Skip to content

Commit cb20883

Browse files
authored
fix: display error when project is not found (#34577)
1 parent 50f22f1 commit cb20883

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/playwright/src/worker/workerMain.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export class WorkerMain extends ProcessRunner {
105105
override async gracefullyClose() {
106106
try {
107107
await this._stop();
108+
if (!this._config) {
109+
// We never set anything up and we can crash on attempting cleanup
110+
return;
111+
}
108112
// Ignore top-level errors, they are already inside TestInfo.errors.
109113
const fakeTestInfo = new TestInfoImpl(this._config, this._project, this._params, undefined, 0, () => {}, () => {}, () => {});
110114
const runnable = { type: 'teardown' } as const;
@@ -190,15 +194,19 @@ export class WorkerMain extends ProcessRunner {
190194
if (this._config)
191195
return;
192196

193-
this._config = await deserializeConfig(this._params.config);
194-
this._project = this._config.projects.find(p => p.id === this._params.projectId)!;
197+
const config = await deserializeConfig(this._params.config);
198+
const project = config.projects.find(p => p.id === this._params.projectId);
199+
if (!project)
200+
throw new Error(`Project "${this._params.projectId}" not found in the worker process. Make sure project name does not change.`);
201+
this._config = config;
202+
this._project = project;
195203
this._poolBuilder = PoolBuilder.createForWorker(this._project);
196204
}
197205

198206
async runTestGroup(runPayload: RunPayload) {
199207
this._runFinished = new ManualPromise<void>();
200208
const entries = new Map(runPayload.entries.map(e => [e.testId, e]));
201-
let fatalUnknownTestIds;
209+
let fatalUnknownTestIds: string[] | undefined;
202210
try {
203211
await this._loadIfNeeded();
204212
const fileSuite = await loadTestFile(runPayload.file, this._config.config.rootDir);

tests/playwright-test/config.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,24 @@ test('should print nice error when some of the projects are unknown', async ({ r
392392
expect(output).toContain('Project(s) "suIte3", "SUite4" not found. Available projects: "suite1", "suite2"');
393393
});
394394

395+
test('should print nice error when project name is not stable', async ({ runInlineTest }) => {
396+
const { output, exitCode } = await runInlineTest({
397+
'playwright.config.ts': `
398+
module.exports = { projects: [
399+
{ name: \`calculated \$\{Date.now()\}\` },
400+
] };
401+
`,
402+
'a.test.ts': `
403+
import { test, expect } from '@playwright/test';
404+
test('pass', async ({}, testInfo) => {
405+
console.log(testInfo.project.name);
406+
});
407+
`
408+
});
409+
expect(exitCode).toBe(1);
410+
expect(output).toContain('not found in the worker process. Make sure project name does not change.');
411+
});
412+
395413
test('should work without config file', async ({ runInlineTest }) => {
396414
const { exitCode, passed, failed, skipped } = await runInlineTest({
397415
'playwright.config.ts': `

0 commit comments

Comments
 (0)