Created
December 30, 2015 15:07
-
-
Save belen-albeza/11d1dad3a6930345b61a to your computer and use it in GitHub Desktop.
Run tests in console with mocha against a URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var mochaPhantomJS = require('gulp-mocha-phantomjs'); | |
var connect = require('gulp-connect'); | |
gulp.task('connect:test', function () { | |
return connect.server({ | |
root: ['app', 'test', 'node_modules'], // node_modules so the runner can include mocha/chai/sinon assets | |
port: 3001 | |
}); | |
}); | |
gulp.task('test:console', ['connect:test'], function () { | |
let stream = mochaPhantomJS({ | |
reporter: 'spec', | |
phantomjs: { useColors: true } | |
}); | |
stream.on('end', function () { | |
connect.serverClose(); | |
}); | |
stream.write({path: 'http://localhost:3001/runner.html'}); | |
stream.end(); | |
return stream; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Test runner</title> | |
<link rel="stylesheet" href="/mocha/mocha.css"> | |
</head> | |
<body> | |
<div id="mocha"></div> | |
<script src="/mocha/mocha.js"></script> | |
<script src="/chai/chai.js"></script> | |
<script src="/sinon-browser-only/sinon.js"></script> | |
<script>mocha.setup('bdd');</script> | |
<script src="/js/test.js"></script> | |
<script> | |
window.expect = chai.expect; | |
if (window.mochaPhantomJS) { | |
mochaPhantomJS.run(); | |
} else { | |
mocha.run(); | |
} | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment