Skip to content

Commit

Permalink
Switch to mocha-phantomjs-core and system PhantomJS
Browse files Browse the repository at this point in the history
mislav committed Apr 14, 2016
1 parent c23c3f9 commit d1ab588
Showing 5 changed files with 45 additions and 32 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@
"chai": "1.10.0",
"jshint": "2.8.0",
"mocha": "2.1.0",
"mocha-phantomjs": "3.5.2",
"phantomjs": "1.9.19",
"mocha-phantomjs-core": "2.0.1",
"url-search-params": "0.5.0"
},
"files": [
12 changes: 8 additions & 4 deletions script/phantomjs
Original file line number Diff line number Diff line change
@@ -14,13 +14,17 @@ trap "kill $server_pid" INT EXIT

STATUS=0

reporter=dot
[ -z "$CI" ] || reporter=spec

run() {
node ./node_modules/.bin/mocha-phantomjs \
-s localToRemoteUrlAccessEnabled=true \
-s webSecurityEnabled=false \
"$@" || STATUS=$?
phantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js \
"$1" $reporter "{\"useColors\":true, \"hooks\":\"$PWD/test/mocha-phantomjs-hooks.js\"}" \
|| STATUS=$?
}

[ -z "$CI" ] || echo "phantomjs $(phantomjs -v)"

run "http://localhost:$port/"
run "http://localhost:$port/test/test-worker.html"

9 changes: 9 additions & 0 deletions test/mocha-phantomjs-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* globals exports */
exports.beforeStart = function(context) {
var originalResourceError = context.page.onResourceError
context.page.onResourceError = function(resErr) {
if (!/\/boom$/.test(resErr.url)) {
originalResourceError(resErr)
}
}
}
11 changes: 6 additions & 5 deletions test/test-worker.html
Original file line number Diff line number Diff line change
@@ -11,7 +11,12 @@
<script src="/node_modules/mocha/mocha.js"></script>

<script>
if (self.initMochaPhantomJS) {
self.initMochaPhantomJS()
}

mocha.setup('tdd')
mocha.suite.suites.unshift(Mocha.Suite.create(mocha.suite, "worker"))

var worker = new Worker('/test/worker.js')

@@ -31,11 +36,7 @@
})
break
case 'end':
if (self.mochaPhantomJS) {
mochaPhantomJS.run()
} else {
mocha.run()
}
mocha.run()
break
}
})
42 changes: 21 additions & 21 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -11,6 +11,10 @@
<script src="/node_modules/chai/chai.js"></script>
<script src="/node_modules/mocha/mocha.js"></script>
<script>
if (self.initMochaPhantomJS) {
self.initMochaPhantomJS()
}

if (self.mocha && mocha.setup) {
mocha.setup('tdd')
self.assert = chai.assert
@@ -24,31 +28,27 @@
<script src="/fetch.js"></script>

<script>
if (self.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
var runner = mocha.run();
var runner = mocha.run();

var failedTests = [];
var failedTests = [];

runner.on('end', function(){
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});
runner.on('end', function(){
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
});

runner.on('fail', function(test, err){
function flattenTitles(test){
var titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};
runner.on('fail', function(test, err){
function flattenTitles(test){
var titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};

failedTests.push({name: test.title, result: false, message: err.message, stack: err.stack, titles: flattenTitles(test) });
});
}
failedTests.push({name: test.title, result: false, message: err.message, stack: err.stack, titles: flattenTitles(test) });
});
</script>
</body>
</html>

0 comments on commit d1ab588

Please sign in to comment.