mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-24 01:06:07 +08:00
82e7a276a3
Summary: Move the base Jasmine spec runner into isomorphic-core to prevent code duplication. Jasmine will look for the config file relative to the directory it's being run in though, so we need to symlink the config file into each package that will need it. Test Plan: Run tests once the suites are integrated Reviewers: evan, spang, juan Reviewed By: spang, juan Differential Revision: https://phab.nylas.com/D4056
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
export default class JasmineExtensions {
|
|
extend({beforeEach, afterEach} = {}) {
|
|
global.it = this._makeItAsync(global.it)
|
|
global.fit = this._makeItAsync(global.fit)
|
|
global.beforeAll = this._makeEachOrAllFnAsync(global.beforeAll)
|
|
global.afterAll = this._makeEachOrAllFnAsync(global.afterAll)
|
|
global.beforeEach = this._makeEachOrAllFnAsync(global.beforeEach)
|
|
global.afterEach = this._makeEachOrAllFnAsync(global.afterEach)
|
|
if (beforeEach) {
|
|
global.beforeEach(beforeEach)
|
|
}
|
|
if (afterEach) {
|
|
global.afterEach(afterEach)
|
|
}
|
|
}
|
|
|
|
_runAsync(userFn, done) {
|
|
if (!userFn) {
|
|
done()
|
|
return true
|
|
}
|
|
const resp = userFn.apply(this);
|
|
if (resp && resp.then) {
|
|
return resp.then(done).catch((error) => {
|
|
// Throwing an error doesn't register as stopping the test. Instead, run an
|
|
// expect() that will fail and show us the error. We still need to call done()
|
|
// afterwards, or it will take the full timeout to fail.
|
|
expect(error).toBeUndefined()
|
|
done()
|
|
})
|
|
}
|
|
done()
|
|
return resp
|
|
}
|
|
|
|
_makeEachOrAllFnAsync(jasmineEachFn) {
|
|
const self = this;
|
|
return (userFn) => {
|
|
return jasmineEachFn(function asyncEachFn(done) {
|
|
self._runAsync.call(this, userFn, done)
|
|
})
|
|
}
|
|
}
|
|
|
|
_makeItAsync(jasmineIt) {
|
|
const self = this;
|
|
return (desc, userFn) => {
|
|
return jasmineIt(desc, function asyncIt(done) {
|
|
self._runAsync.call(this, userFn, done)
|
|
})
|
|
}
|
|
}
|
|
}
|