Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Run qunit tests via phantom in 'npm test' rather than .travis.yml.

We also throw a helpful error if phantom isn't found.
  • Loading branch information...
commit fac471eda19113e58ccb3ed485f98e408b7db3a7 1 parent ecff01e
@toolness toolness authored
View
3  .travis.yml
@@ -13,8 +13,5 @@ before_script:
- mysql -e 'create database test_openbadges;'
- mysql -uroot -e "grant all on openbadges.* to 'badgemaker'@'localhost' identified by 'secret'"
- mysql -uroot -e "grant all on test_openbadges.* to 'badgemaker'@'localhost' identified by 'secret'"
- - node app.js &
script:
- npm test
- - phantomjs static/test/phantom-qunit.js http://localhost:8888/test/
- - phantomjs static/test/phantom-qunit.js http://localhost:8888/test/badge-accept/
View
8 test/qunit.test.js
@@ -0,0 +1,8 @@
+var test = require('tap').test;
+var qunitTap = require('./utils/qunit-tap');
+
+test('root qunit tests', qunitTap.testRunner('/test/'));
+
+test('badge-accept qunit tests', qunitTap.testRunner('/test/badge-accept/'));
+
+test('backpack qunit tests', qunitTap.testRunner('/test/backpack/'));
View
0  static/test/phantom-qunit.js → test/utils/phantom-qunit.js
File renamed without changes
View
60 test/utils/qunit-tap.js
@@ -0,0 +1,60 @@
+var app = require('../../app'),
+ test = require('tap').test;
+ spawn = require('child_process').spawn;
+
+const PHANTOMJS = 'phantomjs' || process.env['PHANTOMJS'];
+const PORT = 8889;
+const PHANTOMJS_NOT_FOUND_ERR =
+ 'phantomjs not found. please install it from ' +
+ 'http://phantomjs.org/, or set the ' +
+ 'PHANTOMJS environment variable to its absolute path.';
+
+function log(msg) {
+ process.stderr.write(msg);
+}
+
+function loggedSpawn(command, args, options) {
+ var process = spawn(command, args, options);
+ process.stdout.setEncoding('utf8');
+ process.stderr.setEncoding('utf8');
+ process.stdout.on('data', log);
+ process.stderr.on('data', log);
+ return process;
+}
+
+function start(path, cb) {
+ app.listen(PORT, function() {
+ var url = 'http://localhost:' + PORT + path;
+ var args = [__dirname + '/phantom-qunit.js', url];
+ var cmdline = PHANTOMJS + ' ' + args.join(' ');
+ var phantom = loggedSpawn(PHANTOMJS, args);
+
+ log('running browser-based tests at ' + url + ' using phantomjs.');
+ phantom.on('exit', function(status) {
+ app.close();
+ if (status != 0)
+ throw new Error('process "' + cmdline + '" exited with status ' +
+ status);
+ if (cb) cb();
+ });
+ });
+}
+
+exports.runQunitTests = function(path, cb) {
+ if ('PHANTOMJS' in process.env)
+ start(path, cb);
+ else
+ spawn('which', [PHANTOMJS]).on('exit', function(status) {
+ if (status) throw new Error(PHANTOMJS_NOT_FOUND_ERR);
+ start(path, cb);
+ });
+};
+
+exports.testRunner = function(path) {
+ return function(t) {
+ exports.runQunitTests(path, function() {
+ t.ok(true, 'all qunit tests in ' + path + ' pass');
+ t.end();
+ });
+ };
+};
Please sign in to comment.
Something went wrong with that request. Please try again.