chore(testrunner): remove setup() helper (#1584)
This commit is contained in:
parent
a41836b1f1
commit
c49b856d6d
|
|
@ -52,10 +52,6 @@ const TestResult = {
|
||||||
Crashed: 'crashed', // If testrunner crashed due to this test
|
Crashed: 'crashed', // If testrunner crashed due to this test
|
||||||
};
|
};
|
||||||
|
|
||||||
function isTestFailure(testResult) {
|
|
||||||
return testResult === TestResult.Failed || testResult === TestResult.TimedOut || testResult === TestResult.Crashed;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createHook(callback, name) {
|
function createHook(callback, name) {
|
||||||
const location = getCallerLocation(__filename);
|
const location = getCallerLocation(__filename);
|
||||||
return { name, body: callback, location };
|
return { name, body: callback, location };
|
||||||
|
|
@ -104,6 +100,7 @@ class Test {
|
||||||
|
|
||||||
setSkipped(skipped) {
|
setSkipped(skipped) {
|
||||||
this._skipped = skipped;
|
this._skipped = skipped;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
focused() {
|
focused() {
|
||||||
|
|
@ -112,6 +109,7 @@ class Test {
|
||||||
|
|
||||||
setFocused(focused) {
|
setFocused(focused) {
|
||||||
this._focused = focused;
|
this._focused = focused;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout() {
|
timeout() {
|
||||||
|
|
@ -120,6 +118,7 @@ class Test {
|
||||||
|
|
||||||
setTimeout(timeout) {
|
setTimeout(timeout) {
|
||||||
this._timeout = timeout;
|
this._timeout = timeout;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
expectation() {
|
expectation() {
|
||||||
|
|
@ -128,6 +127,7 @@ class Test {
|
||||||
|
|
||||||
setExpectation(expectation) {
|
setExpectation(expectation) {
|
||||||
this._expectation = expectation;
|
this._expectation = expectation;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
repeat() {
|
repeat() {
|
||||||
|
|
@ -136,14 +136,17 @@ class Test {
|
||||||
|
|
||||||
setRepeat(repeat) {
|
setRepeat(repeat) {
|
||||||
this._repeat = repeat;
|
this._repeat = repeat;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
before(callback) {
|
before(callback) {
|
||||||
this._hooks.push(createHook(callback, 'before'));
|
this._hooks.push(createHook(callback, 'before'));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
after(callback) {
|
after(callback) {
|
||||||
this._hooks.push(createHook(callback, 'after'));
|
this._hooks.push(createHook(callback, 'after'));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
hooks(name) {
|
hooks(name) {
|
||||||
|
|
@ -184,6 +187,7 @@ class Suite {
|
||||||
|
|
||||||
setSkipped(skipped) {
|
setSkipped(skipped) {
|
||||||
this._skipped = skipped;
|
this._skipped = skipped;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
focused() {
|
focused() {
|
||||||
|
|
@ -192,6 +196,7 @@ class Suite {
|
||||||
|
|
||||||
setFocused(focused) {
|
setFocused(focused) {
|
||||||
this._focused = focused;
|
this._focused = focused;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
location() {
|
location() {
|
||||||
|
|
@ -204,6 +209,7 @@ class Suite {
|
||||||
|
|
||||||
setExpectation(expectation) {
|
setExpectation(expectation) {
|
||||||
this._expectation = expectation;
|
this._expectation = expectation;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
repeat() {
|
repeat() {
|
||||||
|
|
@ -212,22 +218,27 @@ class Suite {
|
||||||
|
|
||||||
setRepeat(repeat) {
|
setRepeat(repeat) {
|
||||||
this._repeat = repeat;
|
this._repeat = repeat;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(callback) {
|
beforeEach(callback) {
|
||||||
this._hooks.push(createHook(callback, 'beforeEach'));
|
this._hooks.push(createHook(callback, 'beforeEach'));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEach(callback) {
|
afterEach(callback) {
|
||||||
this._hooks.push(createHook(callback, 'afterEach'));
|
this._hooks.push(createHook(callback, 'afterEach'));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(callback) {
|
beforeAll(callback) {
|
||||||
this._hooks.push(createHook(callback, 'beforeAll'));
|
this._hooks.push(createHook(callback, 'beforeAll'));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
afterAll(callback) {
|
afterAll(callback) {
|
||||||
this._hooks.push(createHook(callback, 'afterAll'));
|
this._hooks.push(createHook(callback, 'afterAll'));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
hooks(name) {
|
hooks(name) {
|
||||||
|
|
@ -647,12 +658,13 @@ class TestRunner extends EventEmitter {
|
||||||
|
|
||||||
this.describe = this._suiteBuilder([]);
|
this.describe = this._suiteBuilder([]);
|
||||||
this.it = this._testBuilder([]);
|
this.it = this._testBuilder([]);
|
||||||
|
this.Expectations = { ...TestExpectation };
|
||||||
|
|
||||||
if (installCommonHelpers) {
|
if (installCommonHelpers) {
|
||||||
this.fdescribe = this.describe.setup(s => s.setFocused(true));
|
this.fdescribe = this._suiteBuilder([{ callback: s => s.setFocused(true), args: [] }]);
|
||||||
this.xdescribe = this.describe.setup(s => s.setSkipped(true));
|
this.xdescribe = this._suiteBuilder([{ callback: s => s.setSkipped(true), args: [] }]);
|
||||||
this.fit = this.it.setup(t => t.setFocused(true));
|
this.fit = this._testBuilder([{ callback: t => t.setFocused(true), args: [] }]);
|
||||||
this.xit = this.it.setup(t => t.setSkipped(true));
|
this.xit = this._testBuilder([{ callback: t => t.setSkipped(true), args: [] }]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -666,10 +678,9 @@ class TestRunner extends EventEmitter {
|
||||||
callback(...suiteArgs);
|
callback(...suiteArgs);
|
||||||
this._suites.push(suite);
|
this._suites.push(suite);
|
||||||
this._currentSuite = suite.parentSuite();
|
this._currentSuite = suite.parentSuite();
|
||||||
|
return suite;
|
||||||
}, {
|
}, {
|
||||||
get: (obj, prop) => {
|
get: (obj, prop) => {
|
||||||
if (prop === 'setup')
|
|
||||||
return callback => this._suiteBuilder([...callbacks, { callback, args: [] }]);
|
|
||||||
if (this._suiteModifiers.has(prop))
|
if (this._suiteModifiers.has(prop))
|
||||||
return (...args) => this._suiteBuilder([...callbacks, { callback: this._suiteModifiers.get(prop), args }]);
|
return (...args) => this._suiteBuilder([...callbacks, { callback: this._suiteModifiers.get(prop), args }]);
|
||||||
if (this._suiteAttributes.has(prop))
|
if (this._suiteAttributes.has(prop))
|
||||||
|
|
@ -687,10 +698,9 @@ class TestRunner extends EventEmitter {
|
||||||
for (const { callback, args } of callbacks)
|
for (const { callback, args } of callbacks)
|
||||||
callback(test, ...args);
|
callback(test, ...args);
|
||||||
this._tests.push(test);
|
this._tests.push(test);
|
||||||
|
return test;
|
||||||
}, {
|
}, {
|
||||||
get: (obj, prop) => {
|
get: (obj, prop) => {
|
||||||
if (prop === 'setup')
|
|
||||||
return callback => this._testBuilder([...callbacks, { callback, args: [] }]);
|
|
||||||
if (this._testModifiers.has(prop))
|
if (this._testModifiers.has(prop))
|
||||||
return (...args) => this._testBuilder([...callbacks, { callback: this._testModifiers.get(prop), args }]);
|
return (...args) => this._testBuilder([...callbacks, { callback: this._testModifiers.get(prop), args }]);
|
||||||
if (this._testAttributes.has(prop))
|
if (this._testAttributes.has(prop))
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,11 @@ module.exports.addTests = function({testRunner, expect}) {
|
||||||
it('should run a failed focused test', async() => {
|
it('should run a failed focused test', async() => {
|
||||||
const t = newTestRunner();
|
const t = newTestRunner();
|
||||||
let run = false;
|
let run = false;
|
||||||
t.fit.setup(t => t.setExpectation(t.Expectations.Fail))('uno', () => {
|
t.it('uno', () => {
|
||||||
run = true; throw new Error('failure');
|
run = true; throw new Error('failure');
|
||||||
});
|
}).setFocused(true).setExpectation(t.Expectations.Fail);
|
||||||
|
expect(t.tests()[0].focused()).toBe(true);
|
||||||
|
expect(t.tests()[0].expectation()).toBe(t.Expectations.Fail);
|
||||||
const result = await t.run();
|
const result = await t.run();
|
||||||
expect(run).toBe(true);
|
expect(run).toBe(true);
|
||||||
expect(result.runs.length).toBe(1);
|
expect(result.runs.length).toBe(1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue