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'));