Skip to content

Instantly share code, notes, and snippets.

@xiankai
Last active April 12, 2017 18:19
Show Gist options
  • Save xiankai/e2c8a6eca092afcae7aeff73d3af68b0 to your computer and use it in GitHub Desktop.
Save xiankai/e2c8a6eca092afcae7aeff73d3af68b0 to your computer and use it in GitHub Desktop.
jspm mocha-phantomjs config
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link href="jspm_packages/npm/mocha@2.4.5/mocha.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="jspm_packages/system.js"></script>
<script src="jspm_packages/config-test.js"></script>
<script>
Promise.all([
System.import('mocha'),
System.import('chai'),
System.import('lodash/lodash'),
System.import('jquery')
]).then(function(modules) {
// mocha-phantomJS hook
if (window.initMochaPhantomJS) {
window.initMochaPhantomJS();
}
// mocha globals
var mocha = modules[0];
mocha.setup('bdd');
// chai globals
var chai = modules[1];
window.Assertion = chai.Assertion;
window.expect = chai.expect;
// fetch file list
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("get", "test-file-list.json", true);
oReq.send();
// callback, run tests after loaded
function reqListener(e) {
var files = JSON.parse(this.responseText);
Promise.all(files.map(function(file) {
return System.import(file);
})).then(function() {
mocha.run();
});
}
});
</script>
</body>
</html>
{
"jspm": {
"devDependencies": {
"chai": "npm:chai@^3.5.0",
"mocha": "npm:mocha@^2.4.5"
}
},
"scripts": {
"copy-config": "cp webroot/jspm_packages/config.js webroot/jspm_packages/config-test.js && sed -i -e 's/\"\\/\"/\"\"/' webroot/jspm_packages/config-test.js",
"generate-test-file-list": "node test-file-list.js > webroot/test-file-list.json",
"test": "npm run copy-config && npm run generate-test-file-list && ./node_modules/mocha-phantomjs/bin/mocha-phantomjs webroot/mocha.html -t 10000",
}
}
var glob = require('glob');
process.chdir('webroot');
glob('components/**/tests/**/*.js', function(er, files) {
console.log(JSON.stringify(files));
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment