Mailspring/spec/n1-spec-runner.es6

81 lines
2.5 KiB
Text
Raw Normal View History

2016-10-17 04:11:36 +08:00
/* eslint global-require:0 */
import N1SpecLoader from './n1-spec-loader'
2016-10-17 04:17:34 +08:00
import TimeReporter from './time-reporter'
import N1GuiReporter from './n1-gui-reporter';
2016-10-17 04:11:36 +08:00
import jasmineExports from './jasmine';
2016-10-17 04:17:34 +08:00
import ConsoleReporter from './console-reporter'
2016-10-17 04:11:36 +08:00
class N1SpecRunner {
runSpecs(loadSettings) {
this.loadSettings = loadSettings
2016-10-17 04:11:36 +08:00
this._extendGlobalWindow();
2016-10-17 04:17:34 +08:00
this._setupJasmine();
N1SpecLoader.loadSpecs(loadSettings, this.jasmineEnv);
this.jasmineEnv.execute();
2016-10-17 04:11:36 +08:00
}
/**
* Put jasmine methods on the global scope so they can be used anywhere
* without importing jasmine.
*/
_extendGlobalWindow() {
Object.assign(window, {
jasmine: jasmineExports.jasmine,
it: jasmineExports.it,
xit: jasmineExports.xit,
runs: jasmineExports.runs,
waits: jasmineExports.waits,
spyOn: jasmineExports.spyOn,
expect: jasmineExports.expect,
waitsFor: jasmineExports.waitsFor,
describe: jasmineExports.describe,
xdescribe: jasmineExports.xdescribe,
afterEach: jasmineExports.afterEach,
beforeEach: jasmineExports.beforeEach,
})
// On load, this will require "jasmine-focused" which looks up the
// global `jasmine` object and extends onto it:
2016-10-17 04:17:34 +08:00
// fdescribe, ffdescribe, fffdescribe, fit, ffit, fffit
require('jasmine-tagged');
this.jasmineEnv = jasmineExports.jasmine.getEnv();
}
_setupJasmine() {
this._addReporters()
this._initializeDOM()
}
_addReporters() {
const timeReporter = new TimeReporter();
const consoleReporter = new ConsoleReporter();
// This needs to be `required` at runtime because terminal-reporter
// depends on jasmine-tagged, which depends on jasmine-focused, which
// on require will attempt to extend the `jasmine` object with
// methods. The `jasmine` object has to be attached to the global
// scope before it gets extended. This is done in
// `_extendGlobalWindow`.
const N1TerminalReporter = require('./terminal-reporter').default
const terminalReporter = new N1TerminalReporter();
if (NylasEnv.getLoadSettings().showSpecsInWindow) {
this.jasmineEnv.addReporter(N1GuiReporter);
} else {
this.jasmineEnv.addReporter(terminalReporter);
}
this.jasmineEnv.addReporter(timeReporter);
this.jasmineEnv.addReporter(consoleReporter);
}
_initializeDOM() {
const div = document.createElement('div');
div.id = 'jasmine-content';
document.body.appendChild(div);
}
2016-10-17 04:11:36 +08:00
}
export default new N1SpecRunner()