Skip to content
Snippets Groups Projects
Commit f01b114c authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

get frontend unit tests running under phantomjs - issue #635

parent 76b07770
No related branches found
No related tags found
No related merge requests found
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
language: node_js
before_install:
......@@ -11,7 +15,9 @@ notifications:
irc: "irc.mozilla.org#identity"
env:
- MYSQL_USER=root
- WHAT_TESTS=front MYSQL_USER=root
- WHAT_TESTS=back NODE_ENV=test_mysql MYSQL_USER=root
- WHAT_TESTS=back NODE_ENV=test_json
mysql:
adapter: mysql2
......
......@@ -41,7 +41,7 @@
},
"scripts": {
"postinstall": "./scripts/generate_ephemeral_keys.sh",
"test": "./scripts/run_all_tests.sh",
"test": "./scripts/test",
"start": "./scripts/run_locally.js"
},
"engines": {
......
#!/usr/bin/env node
// a script to RUN TESTS. You can specify WHAT TESTS to run by
// populating an environment variable 'WHAT_TESTS'. Values include:
// * 'front' - frontend unit tests
// * 'back' - backend unit tests
// * 'all' - of it
const
spawn = require('child_process').spawn,
path = require('path');
// WHAT TESTS are we running?
var whatTests = [];
if (process.env['WHAT_TESTS']) {
whatTests.push(process.env['WHAT_TESTS']);
if (whatTests[0] == 'all') whatTests = [ 'front', 'back' ];
} else {
whatTests = [ 'back' ];
}
var ec = 0;
function run() {
if (!whatTests.length) process.exit(ec);
var script = {
front: 'test_frontend',
back: 'test_backend'
}[whatTests.shift()];
console.log(script);
var kid = spawn(path.join(__dirname, script));
kid.stdout.on('data', function(d) { process.stdout.write(d); });
kid.stderr.on('data', function(d) { process.stderr.write(d); });
kid.on('exit', function(code) {
if (code) process.exit(code);
run();
});
}
run();
......@@ -17,19 +17,15 @@ fi
# vows hates absolute paths. sheesh.
cd $BASEDIR
for env in test_mysql test_json ; do
export NODE_ENV=$env
$SCRIPT_DIR/test_db_connectivity.js
if [ $? = 0 ] ; then
echo "Testing with NODE_ENV=$env"
for file in tests/*.js ; do
echo $file
vows $file
if [[ $? != 0 ]] ; then
exit 1
fi
done
else
echo "CANNOT TEST '$env' ENVIRONMENT: can't connect to the database"
fi
done
$SCRIPT_DIR/test_db_connectivity.js
if [ $? = 0 ] ; then
for file in tests/*.js ; do
echo $file
vows $file
if [[ $? != 0 ]] ; then
exit 1
fi
done
else
echo "CANNOT TEST '$env' ENVIRONMENT: can't connect to the database"
fi
#!/usr/bin/env node
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
require('../tests/lib/test_env.js');
const assert =
require('assert'),
vows = require('vows'),
start_stop = require('../tests/lib/start-stop.js'),
spawn = require('child_process').spawn,
path = require('path');
var suite = vows.describe('frontend-tests');
// disable vows (often flakey?) async error behavior
suite.options.error = false;
start_stop.addStartupBatches(suite);
suite.addBatch({
"frontend unit tests": {
topic: function() {
// what phantom.js binary?
var bin = 'phantomjs';
try {
var maybe = '/usr/local/bin/phantomjs';
if (!fs.statSync(maybe).isFile()) throw "meh";
bin = maybe;
} catch(e) {};
var kid = spawn(
bin, [ path.join(__dirname, '..', 'resources', 'static', 'test', 'phantomrunner.js'),
'http://127.0.0.1:10002/test' ]);
kid.stdout.on('data', function(d) { process.stdout.write(d); });
kid.stderr.on('data', function(d) { process.stderr.write(d); });
kid.on('exit', this.callback);
},
"pass!": function(code) {
assert.strictEqual(code, 0);
}
}
});
start_stop.addShutdownBatches(suite);
// run or export the suite.
if (process.argv[1] === __filename) suite.run({}, function(r) { process.exit(r.honored == r.total ? 0 : 1); });
else suite.export(module);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment