Jhernandez has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/337838 )
Change subject: Set up qunit running in node to migrate tests
......................................................................
Set up qunit running in node to migrate tests
In order to run qunit tests on sources that use common.js modules, set
up infra to run qunit tests in the node cli when running `npm run
test:node`.
Changes:
* Add npm script test:node that runs the tests
* Run node tests on CI (npm test)
* Add a qunit node test runner in scripts/qunit-node-runner.js
* Bring in QUnit, the tap logger and reporter, and sinon as npm
dependencies
Todo:
* Migrate one of the tests to QUnit
Change-Id: I55d76b7db168f3745e0ac69852c152322ab385c3
---
M README.md
M package.json
A scripts/qunit-node-runner.js
A tests/node-qunit/nested/t2.js
A tests/node-qunit/t1.js
5 files changed, 52 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups
refs/changes/38/337838/1
diff --git a/README.md b/README.md
index f0a9e91..0fb732a 100644
--- a/README.md
+++ b/README.md
@@ -14,9 +14,20 @@
After an `npm install`:
-* `npm start` Will run the bundler in watch mode, re-assembling the files on
- file change.
-* `npm run build` Will compile the assets just once, ready for deployment. You
- *must* run this step before sending the patch or CI will fail (so that
- sources and built assets are in sync).
-* `npm test` To run the linting tools and the tests.
+* On one terminal, kickstart the bundler process:
+ * `npm start` Will run the bundler in watch mode, re-assembling the files on
+ file change.
+ * `npm run build` Will compile the assets just once, ready for deployment.
You
+ *must* run this step before sending the patch or CI will fail (so that
+ sources and built assets are in sync).
+* On another terminal, run tests and linting tools:
+ * `npm test` To run the linting tools and the tests.
+ * You can find the QUnit tests that depend on running MediaWiki under
+ `tests/qunit/`
+ * You can find the isolated QUnit tests under `tests/node-qunit/`, which
you
+ can run with `npm run test:node`
+ * We recommend you install a file watcher like `nodemon` to watch sources and
+ auto run linting and tests.
+ * `npm install -g nodemon`
+ * Example running linting and node unit tests:
+ * `nodemon -w src/ --exec "grunt lint:all && npm run test:node"`
diff --git a/package.json b/package.json
index aee413f..b4945ed 100644
--- a/package.json
+++ b/package.json
@@ -3,9 +3,10 @@
"scripts": {
"start": "webpack -w",
"build": "webpack",
- "test": "grunt lint && npm run check-built-assets",
+ "test": "grunt lint && npm run check-built-assets && npm run test:node",
"doc": "jsduck",
- "check-built-assets": "echo 'CHECKING BUILD SOURCES ARE COMMITED' && rm
-rf test-build && mv resources/dist test-build && npm run build && diff -x
'*.map' -qr test-build resources/dist && rm -rf test-build"
+ "check-built-assets": "echo 'CHECKING BUILD SOURCES ARE COMMITED' && rm
-rf test-build && mv resources/dist test-build && npm run build && diff -x
'*.map' -qr test-build resources/dist && rm -rf test-build",
+ "test:node": "node scripts/qunit-node-runner.js
tests/node-qunit/{*,**/*}.js | tap-spec"
},
"devDependencies": {
"eslint-config-wikimedia": "0.3.0",
@@ -17,9 +18,13 @@
"grunt-eslint": "19.0.0",
"grunt-jsonlint": "1.1.0",
"grunt-stylelint": "^0.6.0",
+ "qunit-tap": "^1.5.1",
+ "qunitjs": "^2.1.1",
"redux": "3.6.0",
"redux-thunk": "2.2.0",
+ "sinon": "^1.17.7",
"stylelint-config-wikimedia": "0.3.0",
+ "tap-spec": "^4.1.1",
"webpack": "^1.14.0"
}
}
diff --git a/scripts/qunit-node-runner.js b/scripts/qunit-node-runner.js
new file mode 100644
index 0000000..6eefacd
--- /dev/null
+++ b/scripts/qunit-node-runner.js
@@ -0,0 +1,11 @@
+var path = require( 'path' );
+var Q = require( 'qunitjs' );
+var reporter = require( 'qunit-tap' );
+
+reporter( Q, function() { console.log.apply( console, arguments ); } );
+
+process.argv.slice( 2 ).forEach( function ( file ) {
+ require( path.resolve( file ) );
+} );
+
+Q.start();
diff --git a/tests/node-qunit/nested/t2.js b/tests/node-qunit/nested/t2.js
new file mode 100644
index 0000000..c243916
--- /dev/null
+++ b/tests/node-qunit/nested/t2.js
@@ -0,0 +1,7 @@
+var Q = require( 'qunitjs' );
+
+Q.module( 'nested module' );
+
+Q.test( 'tests on nested modules run', function ( assert ) {
+ assert.ok( true, 'test ran' );
+} );
diff --git a/tests/node-qunit/t1.js b/tests/node-qunit/t1.js
new file mode 100644
index 0000000..7826163
--- /dev/null
+++ b/tests/node-qunit/t1.js
@@ -0,0 +1,10 @@
+var Q = require( 'qunitjs' );
+var sinon = require( 'sinon' );
+
+Q.module( 'Basic qunit and sinon running in node' );
+
+Q.test( 'Qunit and sinon work in node', function ( assert ) {
+ var s = sinon.spy();
+ s();
+ assert.ok( s.called );
+} );
--
To view, visit https://gerrit.wikimedia.org/r/337838
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I55d76b7db168f3745e0ac69852c152322ab385c3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits