mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00: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 {
|
class Environment {
|
||||||
constructor(name, parentEnvironment = null) {
|
constructor(name) {
|
||||||
this._parentEnvironment = parentEnvironment;
|
|
||||||
this._name = name;
|
this._name = name;
|
||||||
this._hooks = [];
|
this._hooks = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
parentEnvironment() {
|
|
||||||
return this._parentEnvironment;
|
|
||||||
}
|
|
||||||
|
|
||||||
name() {
|
name() {
|
||||||
return this._name;
|
return this._name;
|
||||||
}
|
}
|
||||||
|
@ -185,22 +185,7 @@ class TestWorker {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const environmentStack = [];
|
const environmentStack = allTestEnvironments(test);
|
||||||
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();
|
|
||||||
|
|
||||||
let common = 0;
|
let common = 0;
|
||||||
while (common < environmentStack.length && this._environmentStack[common] === environmentStack[common])
|
while (common < environmentStack.length && this._environmentStack[common] === environmentStack[common])
|
||||||
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 };
|
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.afterAll(() => log.push('env:afterAll'));
|
||||||
e.beforeEach(() => log.push('env:beforeEach'));
|
e.beforeEach(() => log.push('env:beforeEach'));
|
||||||
e.afterEach(() => log.push('env:afterEach'));
|
e.afterEach(() => log.push('env:afterEach'));
|
||||||
const e2 = new Environment('env2', e);
|
const e2 = new Environment('env2');
|
||||||
e2.beforeAll(() => log.push('env2:beforeAll'));
|
e2.beforeAll(() => log.push('env2:beforeAll'));
|
||||||
e2.afterAll(() => log.push('env2:afterAll'));
|
e2.afterAll(() => log.push('env2:afterAll'));
|
||||||
t.beforeAll(() => log.push('root:beforeAll'));
|
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.afterAll(() => log.push('suite:afterAll'));
|
||||||
});
|
});
|
||||||
t.it('cuatro', () => log.push('test #4'));
|
t.it('cuatro', () => log.push('test #4'));
|
||||||
|
t.tests()[t.tests().length - 1].addEnvironment(e);
|
||||||
t.tests()[t.tests().length - 1].addEnvironment(e2);
|
t.tests()[t.tests().length - 1].addEnvironment(e2);
|
||||||
t.describe('no hooks suite', () => {
|
t.describe('no hooks suite', () => {
|
||||||
t.describe('suite2', () => {
|
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.suites()[t.suites().length - 1].addEnvironment(e2);
|
||||||
t.afterEach(() => log.push('root:afterEach'));
|
t.afterEach(() => log.push('root:afterEach'));
|
||||||
t.afterAll(() => log.push('root:afterAll1'));
|
t.afterAll(() => log.push('root:afterAll1'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user