Files
browser-wakatime/tests/beforeEach.js
Vu Nguyen 9ef655ac3b 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
2021-01-13 21:05:05 -08:00

49 lines
1.2 KiB
JavaScript

var fs = require('fs');
var page;
var beforeLoadFn;
beforeEach(function () {
page = require('webpage').create();
page.onConsoleMessage = function (msg) {
console.log(msg);
};
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;
});