Browse Source

tests: Support phantomjs testing

pull/233/head
Tobias Bieniek 10 years ago
parent
commit
8519f07aed
  1. 5
      package.json
  2. 16
      tests/test.js
  3. 11
      tests/tests.html

5
package.json

@ -45,12 +45,15 @@ @@ -45,12 +45,15 @@
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.6.0",
"mocha": "^2.2.5",
"mocha-phantomjs": "^3.5.4",
"open": "0.0.5",
"phantomjs": "1.9.1 - 1.9.7-15",
"serve-static": "^1.7.1"
},
"scripts": {
"test-browser": "node tests/test.js",
"test-phantomjs": "node tests/test.js --phantomjs",
"test-node": "mocha tests/node-tests.js",
"test": "npm run test-node && npm run test-browser"
"test": "npm run test-node && npm run test-phantomjs"
}
}

16
tests/test.js

@ -2,8 +2,18 @@ var connect = require('connect'); @@ -2,8 +2,18 @@ var connect = require('connect');
var serveStatic = require('serve-static');
var open = require('open');
var path = require('path');
var child_process = require('child_process');
connect().use(serveStatic(path.join(__dirname, '/..'))).listen(8071, function() {
open('http://localhost:8071/tests/tests.html');
console.log('Serving tests...');
var server = connect().use(serveStatic(path.join(__dirname, '/..'))).listen(8071, function() {
if (process.argv.indexOf('--phantomjs') !== -1) {
child_process.spawn('node_modules/.bin/mocha-phantomjs', ['http://localhost:8071/tests/tests.html'], {
stdio: 'inherit'
}).on('exit', function () {
server.close();
});
} else {
open('http://localhost:8071/tests/tests.html');
console.log('Serving tests...');
}
});

11
tests/tests.html

@ -17,9 +17,14 @@ @@ -17,9 +17,14 @@
<div id="mocha"></div>
<script>
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
mocha.checkLeaks();
mocha.globals(['jQuery']);
mocha.run();
}
</script>
</body>
</html>

Loading…
Cancel
Save