From c61e2d6cc9a7d78ee34f4577d02b095972c40f4d Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 23 Jun 2020 16:45:00 -0700 Subject: [PATCH] testrunner: drop nested test environments (#2681) --- utils/testrunner/Test.js | 7 +---- utils/testrunner/TestRunner.js | 33 ++++++++++++------------ utils/testrunner/test/testrunner.spec.js | 4 ++- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/utils/testrunner/Test.js b/utils/testrunner/Test.js index 90753b1e97..ed975a53c7 100644 --- a/utils/testrunner/Test.js +++ b/utils/testrunner/Test.js @@ -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; } diff --git a/utils/testrunner/TestRunner.js b/utils/testrunner/TestRunner.js index 2c70b91810..afe8f575ae 100644 --- a/utils/testrunner/TestRunner.js +++ b/utils/testrunner/TestRunner.js @@ -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 }; diff --git a/utils/testrunner/test/testrunner.spec.js b/utils/testrunner/test/testrunner.spec.js index b8f31af466..8a5926d7c4 100644 --- a/utils/testrunner/test/testrunner.spec.js +++ b/utils/testrunner/test/testrunner.spec.js @@ -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'));