Browse Source

tests: Support phantomjs testing

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

5
package.json

@ -45,12 +45,15 @@
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.6.0", "grunt-contrib-uglify": "^0.6.0",
"mocha": "^2.2.5", "mocha": "^2.2.5",
"mocha-phantomjs": "^3.5.4",
"open": "0.0.5", "open": "0.0.5",
"phantomjs": "1.9.1 - 1.9.7-15",
"serve-static": "^1.7.1" "serve-static": "^1.7.1"
}, },
"scripts": { "scripts": {
"test-browser": "node tests/test.js", "test-browser": "node tests/test.js",
"test-phantomjs": "node tests/test.js --phantomjs",
"test-node": "mocha tests/node-tests.js", "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"
} }
} }

12
tests/test.js

@ -2,8 +2,18 @@ var connect = require('connect');
var serveStatic = require('serve-static'); var serveStatic = require('serve-static');
var open = require('open'); var open = require('open');
var path = require('path'); var path = require('path');
var child_process = require('child_process');
connect().use(serveStatic(path.join(__dirname, '/..'))).listen(8071, function() { 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'); open('http://localhost:8071/tests/tests.html');
console.log('Serving tests...'); console.log('Serving tests...');
}
}); });

5
tests/tests.html

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

Loading…
Cancel
Save