testrunner: drop nested test environments (#2681)

This commit is contained in:
Andrey Lushnikov 2020-06-23 16:45:00 -07:00 committed by GitHub
parent fca514d74e
commit c61e2d6cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 23 deletions

View File

@ -28,16 +28,11 @@ function createHook(callback, name) {
}
class Environment {
constructor(name, parentEnvironment = null) {
this._parentEnvironment = parentEnvironment;
constructor(name) {
this._name = name;
this._hooks = [];
}
parentEnvironment() {
return this._parentEnvironment;
}
name() {
return this._name;
}

View File

@ -185,22 +185,7 @@ class TestWorker {
return;
}
const environmentStack = [];
function appendEnvironment(e) {
while (e) {
if (!e.isEmpty())
environmentStack.push(e);
e = e.parentEnvironment();
}
}
for (const environment of test._environments.slice().reverse())
appendEnvironment(environment);
for (let suite = test.suite(); suite; suite = suite.parentSuite()) {
for (const environment of suite._environments.slice().reverse())
appendEnvironment(environment);
}
environmentStack.reverse();
const environmentStack = allTestEnvironments(test);
let common = 0;
while (common < environmentStack.length && this._environmentStack[common] === environmentStack[common])
common++;
@ -499,4 +484,20 @@ class TestRunner {
}
}
function allTestEnvironments(test) {
const environmentStack = [];
for (const environment of test._environments.slice().reverse()) {
if (!environment.isEmpty())
environmentStack.push(environment);
}
for (let suite = test.suite(); suite; suite = suite.parentSuite()) {
for (const environment of suite._environments.slice().reverse()) {
if (!environment.isEmpty())
environmentStack.push(environment);
}
}
environmentStack.reverse();
return environmentStack;
}
module.exports = { TestRunner, TestRun, TestResult, Result };

View File

@ -282,7 +282,7 @@ module.exports.addTests = function({describe, fdescribe, xdescribe, it, xit, fit
e.afterAll(() => log.push('env:afterAll'));
e.beforeEach(() => log.push('env:beforeEach'));
e.afterEach(() => log.push('env:afterEach'));
const e2 = new Environment('env2', e);
const e2 = new Environment('env2');
e2.beforeAll(() => log.push('env2:beforeAll'));
e2.afterAll(() => log.push('env2:afterAll'));
t.beforeAll(() => log.push('root:beforeAll'));
@ -308,6 +308,7 @@ module.exports.addTests = function({describe, fdescribe, xdescribe, it, xit, fit
t.afterAll(() => log.push('suite:afterAll'));
});
t.it('cuatro', () => log.push('test #4'));
t.tests()[t.tests().length - 1].addEnvironment(e);
t.tests()[t.tests().length - 1].addEnvironment(e2);
t.describe('no hooks suite', () => {
t.describe('suite2', () => {
@ -318,6 +319,7 @@ module.exports.addTests = function({describe, fdescribe, xdescribe, it, xit, fit
});
});
});
t.suites()[t.suites().length - 1].addEnvironment(e);
t.suites()[t.suites().length - 1].addEnvironment(e2);
t.afterEach(() => log.push('root:afterEach'));
t.afterAll(() => log.push('root:afterAll1'));