Zfilipin has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/382183 )
Change subject: WIP Mocha tests for Echo notifications ...................................................................... WIP Mocha tests for Echo notifications Bug: T177412 Change-Id: Ia68c2a26240cc5a07f2122a5f3a6caa0f199a313 --- M Gruntfile.js M package.json A tests/mocha/.eslintrc.json A tests/mocha/README.md A tests/mocha/notifications.js 5 files changed, 94 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo refs/changes/83/382183/1 diff --git a/Gruntfile.js b/Gruntfile.js index c389ce1..8660b07 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -49,4 +49,5 @@ grunt.registerTask( 'lint', [ 'eslint', 'stylelint', 'jsonlint', 'banana' ] ); grunt.registerTask( 'test', 'lint' ); grunt.registerTask( 'default', 'test' ); + // TODO: grunt.registerTask( 'mocha', 'mocha' ); }; diff --git a/package.json b/package.json index bd5d5e9..52f7c80 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "description": "Build tools for Echo.", "scripts": { "test": "grunt test", - "doc": "jsduck" + "doc": "jsduck", + "mocha": "grunt mocha" }, "devDependencies": { "eslint-config-wikimedia": "0.4.0", @@ -15,6 +16,8 @@ "grunt-eslint": "19.0.0", "grunt-jsonlint": "1.0.8", "grunt-stylelint": "0.7.0", + "mocha": "4.0.0", + "nodemw": "0.11.0", "stylelint": "7.8.0", "stylelint-config-wikimedia": "0.4.1" } diff --git a/tests/mocha/.eslintrc.json b/tests/mocha/.eslintrc.json new file mode 100644 index 0000000..db736b7 --- /dev/null +++ b/tests/mocha/.eslintrc.json @@ -0,0 +1,17 @@ +{ + "extends": "../../.eslintrc.json", + "env": { + "es6": true, + "mocha": true, + "node": true + }, + "parserOptions": { + "ecmaVersion": 6 + }, + "globals": { + "browser": false + }, + "rules":{ + "no-console":0 + } +} diff --git a/tests/mocha/README.md b/tests/mocha/README.md new file mode 100644 index 0000000..5ae0cd8 --- /dev/null +++ b/tests/mocha/README.md @@ -0,0 +1,10 @@ +# Usage + + cd mediawiki/vagrant + vagrant up + vagrant roles enable echo flow wikimediaflow + vagrant provision + + cd mediawiki/extensions/Echo + npm install + npm run mocha diff --git a/tests/mocha/notifications.js b/tests/mocha/notifications.js new file mode 100644 index 0000000..e25194e --- /dev/null +++ b/tests/mocha/notifications.js @@ -0,0 +1,62 @@ +'use strict'; +const assert = require( 'assert' ); + +describe( 'Echo', function () { + + it( 'should notify a new user with welcome message', function () { + + function apiCreateAccount( username, password ) { + const url = require( 'url' ), // https://nodejs.org/docs/latest/api/url.html + baseUrl = url.parse( browser.options.baseUrl ), // http://webdriver.io/guide/testrunner/browserobject.html + Bot = require( 'nodemw' ), // https://github.com/macbre/nodemw + client = new Bot( { + protocol: baseUrl.protocol, + server: baseUrl.hostname, + port: baseUrl.port, + path: baseUrl.path, + debug: false + } ); + + return new Promise( ( resolve, reject ) => { + client.api.call( + { + action: 'query', + meta: 'tokens', + type: 'createaccount' + }, + /** + * @param {Error|null} err + * @param {Object} info Processed query result + * @param {Object} next More results? + * @param {Object} data Raw data + */ + function ( err, info, next, data ) { + if ( err ) { + reject( err ); + return; + } + client.api.call( { + action: 'createaccount', + createreturnurl: browser.options.baseUrl, + createtoken: data.query.tokens.createaccounttoken, + username: username, + password: password, + retype: password + }, function ( err ) { + if ( err ) { + reject( err ); + return; + } + resolve(); + }, 'POST' ); + }, + 'POST' + ); + + } ); + + } + + } ); + +} ); -- To view, visit https://gerrit.wikimedia.org/r/382183 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia68c2a26240cc5a07f2122a5f3a6caa0f199a313 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Echo Gerrit-Branch: master Gerrit-Owner: Zfilipin <zfili...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits