fix: display error when project is not found (#34577)

This commit is contained in:
Adam Gastineau 2025-02-05 06:58:02 -08:00 committed by GitHub
parent 50f22f13a4
commit cb208836b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions

View File

@ -105,6 +105,10 @@ export class WorkerMain extends ProcessRunner {
override async gracefullyClose() { override async gracefullyClose() {
try { try {
await this._stop(); await this._stop();
if (!this._config) {
// We never set anything up and we can crash on attempting cleanup
return;
}
// Ignore top-level errors, they are already inside TestInfo.errors. // Ignore top-level errors, they are already inside TestInfo.errors.
const fakeTestInfo = new TestInfoImpl(this._config, this._project, this._params, undefined, 0, () => {}, () => {}, () => {}); const fakeTestInfo = new TestInfoImpl(this._config, this._project, this._params, undefined, 0, () => {}, () => {}, () => {});
const runnable = { type: 'teardown' } as const; const runnable = { type: 'teardown' } as const;
@ -190,15 +194,19 @@ export class WorkerMain extends ProcessRunner {
if (this._config) if (this._config)
return; return;
this._config = await deserializeConfig(this._params.config); const config = await deserializeConfig(this._params.config);
this._project = this._config.projects.find(p => p.id === this._params.projectId)!; const project = config.projects.find(p => p.id === this._params.projectId);
if (!project)
throw new Error(`Project "${this._params.projectId}" not found in the worker process. Make sure project name does not change.`);
this._config = config;
this._project = project;
this._poolBuilder = PoolBuilder.createForWorker(this._project); this._poolBuilder = PoolBuilder.createForWorker(this._project);
} }
async runTestGroup(runPayload: RunPayload) { async runTestGroup(runPayload: RunPayload) {
this._runFinished = new ManualPromise<void>(); this._runFinished = new ManualPromise<void>();
const entries = new Map(runPayload.entries.map(e => [e.testId, e])); const entries = new Map(runPayload.entries.map(e => [e.testId, e]));
let fatalUnknownTestIds; let fatalUnknownTestIds: string[] | undefined;
try { try {
await this._loadIfNeeded(); await this._loadIfNeeded();
const fileSuite = await loadTestFile(runPayload.file, this._config.config.rootDir); const fileSuite = await loadTestFile(runPayload.file, this._config.config.rootDir);

View File

@ -392,6 +392,24 @@ test('should print nice error when some of the projects are unknown', async ({ r
expect(output).toContain('Project(s) "suIte3", "SUite4" not found. Available projects: "suite1", "suite2"'); expect(output).toContain('Project(s) "suIte3", "SUite4" not found. Available projects: "suite1", "suite2"');
}); });
test('should print nice error when project name is not stable', async ({ runInlineTest }) => {
const { output, exitCode } = await runInlineTest({
'playwright.config.ts': `
module.exports = { projects: [
{ name: \`calculated \$\{Date.now()\}\` },
] };
`,
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('pass', async ({}, testInfo) => {
console.log(testInfo.project.name);
});
`
});
expect(exitCode).toBe(1);
expect(output).toContain('not found in the worker process. Make sure project name does not change.');
});
test('should work without config file', async ({ runInlineTest }) => { test('should work without config file', async ({ runInlineTest }) => {
const { exitCode, passed, failed, skipped } = await runInlineTest({ const { exitCode, passed, failed, skipped } = await runInlineTest({
'playwright.config.ts': ` 'playwright.config.ts': `