Setup CI tests (#100)
* use @xarc/xrun to streamline tasks in an imperative manner * add lint-staged/husky for git hook tasks * run prettier across all files * fixing tests * add ci test workflow * add a ci workflow * remove precommit in favor of husky * add .prettierrc.js * reformat with prettier
This commit is contained in:
@@ -2,39 +2,47 @@ var fs = require('fs');
|
||||
var page;
|
||||
var beforeLoadFn;
|
||||
|
||||
beforeEach(function() {
|
||||
page = require('webpage').create();
|
||||
|
||||
page.onConsoleMessage = function(msg) { console.log(msg); };
|
||||
beforeEach(function () {
|
||||
page = require('webpage').create();
|
||||
|
||||
page.onError = function(msg, trace) {
|
||||
var msgStack = [msg];
|
||||
if (trace && trace.length) {
|
||||
msgStack.push('TRACE:');
|
||||
trace.forEach(function(t) {
|
||||
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
|
||||
});
|
||||
}
|
||||
// we need try..catch here as mocha throws error that catched by phantom.onError
|
||||
try {
|
||||
mocha.throwError(msgStack.join('\n'));
|
||||
} catch(e) { }
|
||||
};
|
||||
page.onConsoleMessage = function (msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
page.onInitialized = function() {
|
||||
page.injectJs(node_modules + 'chai/chai.js');
|
||||
page.injectJs(node_modules + 'sinon/pkg/sinon.js');
|
||||
page.injectJs(node_modules + 'sinon-chrome/chrome.js');
|
||||
page.injectJs(node_modules + 'sinon-chrome/src/phantom-tweaks.js');
|
||||
page.injectJs(node_modules + 'require-stub/index.js');
|
||||
// call additional function defined in tests
|
||||
if (beforeLoadFn) {
|
||||
beforeLoadFn();
|
||||
}
|
||||
};
|
||||
page.onError = function (msg, trace) {
|
||||
var msgStack = [msg];
|
||||
if (trace && trace.length) {
|
||||
msgStack.push('TRACE:');
|
||||
trace.forEach(function (t) {
|
||||
msgStack.push(
|
||||
' -> ' +
|
||||
t.file +
|
||||
': ' +
|
||||
t.line +
|
||||
(t.function ? ' (in function "' + t.function + '")' : ''),
|
||||
);
|
||||
});
|
||||
}
|
||||
// we need try..catch here as mocha throws error that catched by phantom.onError
|
||||
try {
|
||||
mocha.throwError(msgStack.join('\n'));
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
page.onInitialized = function () {
|
||||
page.injectJs(node_modules + 'chai/chai.js');
|
||||
page.injectJs(node_modules + 'sinon/pkg/sinon.js');
|
||||
page.injectJs(node_modules + 'sinon-chrome/chrome.js');
|
||||
page.injectJs(node_modules + 'sinon-chrome/src/phantom-tweaks.js');
|
||||
page.injectJs(node_modules + 'require-stub/index.js');
|
||||
// call additional function defined in tests
|
||||
if (beforeLoadFn) {
|
||||
beforeLoadFn();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
page.close();
|
||||
beforeLoadFn = null;
|
||||
});
|
||||
afterEach(function () {
|
||||
page.close();
|
||||
beforeLoadFn = null;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user