Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/75268


Change subject: Add Makefile to core
......................................................................

Add Makefile to core

To a newbie it's not clear at all how to run all the tests
and ensure any code I commit is up to some basic standards

This adds a makefile which allows us to run qunit and phpunit
tests. We've been using it in MobileFrontend extension for some
time and finding it extremely useful

Change-Id: Ib7e46e8df66f73a0522dc7b8f6ab0da896957b70
---
A Makefile
A package.json
A scripts/nodecheck.sh
A scripts/qunit.sh
A tests/externals/phantomjs-qunit-runner.js
5 files changed, 177 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/68/75268/1

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d8e8763
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,16 @@
+nodecheck:
+       @scripts/nodecheck.sh
+
+jshint: nodecheck
+       @node_modules/.bin/jshint resources/* --config .jshintrc
+
+phpunit:
+       cd tests/phpunit && php phpunit.php
+
+qunit:
+       @scripts/qunit.sh
+
+qunitdebug:
+       @scripts/qunit.sh 'MobileFrontend&debug=true'
+
+tests: jshint phpunit qunit
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..dfbb018
--- /dev/null
+++ b/package.json
@@ -0,0 +1,8 @@
+{
+       "name": "MediaWiki-dependencies",
+       "description": "Node.js dependencies used in MediaWiki",
+       "version": "0.0.1",
+       "dependencies": {
+               "jshint": ">=1.1.0"
+       }
+}
diff --git a/scripts/nodecheck.sh b/scripts/nodecheck.sh
new file mode 100755
index 0000000..3ee0f83
--- /dev/null
+++ b/scripts/nodecheck.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+if command -v npm > /dev/null ; then
+  npm install
+else
+  echo "You need to install Node.JS!"
+  echo "See http://nodejs.org/";
+  exit 1
+fi
diff --git a/scripts/qunit.sh b/scripts/qunit.sh
new file mode 100755
index 0000000..bcbb26c
--- /dev/null
+++ b/scripts/qunit.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+echo "Running QUnit tests..."
+if command -v phantomjs > /dev/null ; then
+  URL=${MEDIAWIKI_URL:-"http://127.0.0.1:80"}
+  if [ -z "$1" ]; then
+    FILTER=""
+  else
+    FILTER="&filter=$1"
+  fi
+  echo "Using $URL as a development environment host."
+  echo "To specify a different host set MEDIAWIKI_URL environment variable"
+  echo '(e.g. by running "export MEDIAWIKI_URL=http://localhost:8080/w";)'
+  phantomjs tests/externals/phantomjs-qunit-runner.js 
"$URL/index.php/Special:JavaScriptTest/qunit?$FILTER"
+else
+  echo "You need to install PhantomJS to run QUnit tests in terminal!"
+  echo "See http://phantomjs.org/";
+  exit 1
+fi
diff --git a/tests/externals/phantomjs-qunit-runner.js 
b/tests/externals/phantomjs-qunit-runner.js
new file mode 100644
index 0000000..4b1d38b
--- /dev/null
+++ b/tests/externals/phantomjs-qunit-runner.js
@@ -0,0 +1,127 @@
+/*
+ * QtWebKit-powered headless test runner using PhantomJS
+ *
+ * PhantomJS binaries: http://phantomjs.org/download.html
+ * Requires PhantomJS 1.6+ (1.7+ recommended)
+ *
+ * Run with:
+ *   phantomjs runner.js [url-of-your-qunit-testsuite]
+ *
+ * e.g.
+ *   phantomjs runner.js http://localhost/qunit/test/index.html
+ */
+
+/*jshint latedef:false */
+/*global phantom:false, require:false, console:false, window:false, 
QUnit:false */
+
+(function() {
+       'use strict';
+
+       var args = require('system').args;
+
+       // arg[0]: scriptName, args[1...]: arguments
+       if (args.length !== 2) {
+               console.error('Usage:\n  phantomjs runner.js 
[url-of-your-qunit-testsuite]');
+               phantom.exit(1);
+       }
+
+       var url = args[1],
+               page = require('webpage').create();
+
+       // Route `console.log()` calls from within the Page context to the main 
Phantom context (i.e. current `this`)
+       page.onConsoleMessage = function(msg) {
+               console.log(msg);
+       };
+
+       page.onInitialized = function() {
+               page.evaluate(addLogging);
+       };
+
+       page.onCallback = function(message) {
+               var result,
+                       failed;
+
+               if (message) {
+                       if (message.name === 'QUnit.done') {
+                               result = message.data;
+                               failed = !result || result.failed;
+
+                               phantom.exit(failed ? 1 : 0);
+                       }
+               }
+       };
+
+       page.open(url, function(status) {
+               if (status !== 'success') {
+                       console.error('Unable to access network: ' + status);
+                       phantom.exit(1);
+               } else {
+                       // Cannot do this verification with the 
'DOMContentLoaded' handler because it
+                       // will be too late to attach it if a page does not 
have any script tags.
+                       var qunitMissing = page.evaluate(function() { return 
(typeof QUnit === 'undefined' || !QUnit); });
+                       if (qunitMissing) {
+                               console.error('The `QUnit` object is not 
present on this page.');
+                               phantom.exit(1);
+                       }
+
+                       // Do nothing... the callback mechanism will handle 
everything!
+               }
+       });
+
+       function addLogging() {
+               window.document.addEventListener('DOMContentLoaded', function() 
{
+                       var current_test_assertions = [];
+
+                       QUnit.log(function(details) {
+                               var response;
+
+                               // Ignore passing assertions
+                               if (details.result) {
+                                       return;
+                               }
+
+                               response = details.message || '';
+
+                               if (typeof details.expected !== 'undefined') {
+                                       if (response) {
+                                               response += ', ';
+                                       }
+
+                                       response += 'expected: ' + 
details.expected + ', but was: ' + details.actual;
+                                       if (details.source) {
+                                               response += "\n" + 
details.source;
+                                       }
+                               }
+
+                               current_test_assertions.push('Failed assertion: 
' + response);
+                       });
+
+                       QUnit.testDone(function(result) {
+                               var i,
+                                       len,
+                                       name = result.module + ': ' + 
result.name;
+
+                               if (result.failed) {
+                                       console.log('Test failed: ' + name);
+
+                                       for (i = 0, len = 
current_test_assertions.length; i < len; i++) {
+                                               console.log('    ' + 
current_test_assertions[i]);
+                                       }
+                               }
+
+                               current_test_assertions.length = 0;
+                       });
+
+                       QUnit.done(function(result) {
+                               console.log('Took ' + result.runtime +  'ms to 
run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed 
+ ' failed.');
+
+                               if (typeof window.callPhantom === 'function') {
+                                       window.callPhantom({
+                                               'name': 'QUnit.done',
+                                               'data': result
+                                       });
+                               }
+                       });
+               }, false);
+       }
+})();

-- 
To view, visit https://gerrit.wikimedia.org/r/75268
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7e46e8df66f73a0522dc7b8f6ab0da896957b70
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to