mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
testrunner: drop nested test environments (#2681)
This commit is contained in:
parent
fca514d74e
commit
c61e2d6cc9
@ -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;
|
||||
}
|
||||
|
@ -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 };
|
||||
|
@ -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'));
|
||||
|
Loading…
Reference in New Issue
Block a user