fix(deps): apply env vars back to the main process for reporters
This commit is contained in:
parent
94348bb3c5
commit
c2366710f5
|
|
@ -63,6 +63,7 @@ if (process.env.PW_TS_ESM_LOADER_ON)
|
|||
let processRunner: ProcessRunner | undefined;
|
||||
let processName: string | undefined;
|
||||
const startingEnv = { ...process.env };
|
||||
const kPredefinedWorkerEnvs = new Set(['TEST_WORKER_INDEX', 'TEST_PARALLEL_INDEX']);
|
||||
|
||||
process.on('message', async (message: any) => {
|
||||
if (message.method === '__init__') {
|
||||
|
|
@ -77,7 +78,7 @@ process.on('message', async (message: any) => {
|
|||
}
|
||||
if (message.method === '__stop__') {
|
||||
const keys = new Set([...Object.keys(process.env), ...Object.keys(startingEnv)]);
|
||||
const producedEnv: EnvProducedPayload = [...keys].filter(key => startingEnv[key] !== process.env[key]).map(key => [key, process.env[key] ?? null]);
|
||||
const producedEnv: EnvProducedPayload = [...keys].filter(key => startingEnv[key] !== process.env[key] && !kPredefinedWorkerEnvs.has(key)).map(key => [key, process.env[key] ?? null]);
|
||||
sendMessageToParent({ method: '__env_produced__', params: producedEnv });
|
||||
await gracefullyCloseAndExit();
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ export class Dispatcher {
|
|||
private _finished = new ManualPromise<void>();
|
||||
private _isStopped = true;
|
||||
|
||||
private _allTests: TestCase[] = [];
|
||||
private _config: FullConfigInternal;
|
||||
private _reporter: ReporterV2;
|
||||
private _failureTracker: FailureTracker;
|
||||
|
|
@ -159,7 +158,6 @@ export class Dispatcher {
|
|||
async run(testGroups: TestGroup[], extraEnvByProjectId: EnvByProjectId) {
|
||||
this._extraEnvByProjectId = extraEnvByProjectId;
|
||||
this._queue = testGroups;
|
||||
this._allTests = testGroups.map(g => g.tests).flat();
|
||||
for (const group of testGroups)
|
||||
this._updateCounterForWorkerHash(group.workerHash, +1);
|
||||
this._isStopped = false;
|
||||
|
|
|
|||
|
|
@ -315,8 +315,12 @@ function createRunTestsTask(): Task<TestRun> {
|
|||
}
|
||||
},
|
||||
teardown: async ({ phases }) => {
|
||||
for (const { dispatcher } of phases.reverse())
|
||||
for (const { dispatcher, projects } of phases.reverse()) {
|
||||
for (const project of projects)
|
||||
process.env = { ...process.env, ...dispatcher.producedEnvByProjectId().get(project.project.id) };
|
||||
dispatcher.producedEnvByProjectId();
|
||||
await dispatcher.stop();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,11 +82,29 @@ test('should inherit env changes from dependencies', async ({ runInlineTest }) =
|
|||
console.log('\\n%%E-' + process.env.SET_IN_A + '-' + process.env.SET_IN_B + '-' + process.env.SET_OUTSIDE);
|
||||
});
|
||||
`,
|
||||
}, {}, { SET_OUTSIDE: 'outside' });
|
||||
'myReporter.ts': `
|
||||
export default class MyReporter {
|
||||
onEnd() {
|
||||
console.log('\\n%%Reporter-onEnd-TEST_WORKER_INDEX=' + process.env.TEST_WORKER_INDEX);
|
||||
console.log('\\n%%Reporter-onEnd-TEST_PARALLEL_INDEX=' + process.env.TEST_PARALLEL_INDEX);
|
||||
console.log('\\n%%Reporter-onEnd-' + process.env.SET_IN_A + '-' + process.env.SET_IN_B + '-' + process.env.SET_OUTSIDE);
|
||||
}
|
||||
}
|
||||
`
|
||||
}, { reporter: './myReporter.ts,list' }, { SET_OUTSIDE: 'outside' });
|
||||
expect(result.passed).toBe(5);
|
||||
expect(result.failed).toBe(0);
|
||||
expect(result.skipped).toBe(0);
|
||||
expect(result.outputLines.sort()).toEqual(['A', 'B', 'C-valuea-undefined-undefined', 'D-undefined-valueb-outside', 'E-undefined-valueb-outside']);
|
||||
expect(result.outputLines.sort()).toEqual([
|
||||
'A',
|
||||
'B',
|
||||
'C-valuea-undefined-undefined',
|
||||
'D-undefined-valueb-outside',
|
||||
'E-undefined-valueb-outside',
|
||||
'Reporter-onEnd-TEST_PARALLEL_INDEX=undefined',
|
||||
'Reporter-onEnd-TEST_WORKER_INDEX=undefined',
|
||||
'Reporter-onEnd-valuea-valueb-undefined',
|
||||
]);
|
||||
});
|
||||
|
||||
test('should not run projects with dependencies when --no-deps is passed', async ({ runInlineTest }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue