Skip to content

Commit 183f0e5

Browse files
committed
re-iterate
1 parent 2776191 commit 183f0e5

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

packages/playwright/src/runner/testServer.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { Watcher } from '../fsWatcher';
2929
import { baseFullConfig } from '../isomorphic/teleReceiver';
3030
import { addGitCommitInfoPlugin } from '../plugins/gitCommitInfoPlugin';
3131
import { webServerPluginsForConfig } from '../plugins/webServerPlugin';
32-
import { internalScreen } from '../reporters/base';
32+
import { internalScreen, prepareErrorStack } from '../reporters/base';
3333
import { InternalReporter } from '../reporters/internalReporter';
3434
import ListReporter from '../reporters/list';
3535
import { affectedTestFiles, collectAffectedTestFiles, dependenciesForTestFile } from '../transform/compilationCache';
@@ -43,7 +43,6 @@ import type { TestRunnerPluginRegistration } from '../plugins';
4343
import type { ReporterV2 } from '../reporters/reporterV2';
4444
import type { TraceViewerRedirectOptions, TraceViewerServerOptions } from 'playwright-core/lib/server/trace/viewer/traceViewer';
4545
import type { HttpServer, Transport } from 'playwright-core/lib/utils';
46-
import { serializeLoadError } from '../common/testLoader';
4746

4847
const originalStdoutWrite = process.stdout.write;
4948
const originalStderrWrite = process.stderr.write;
@@ -419,7 +418,17 @@ export class TestServerDispatcher implements TestServerInterface {
419418
}
420419
return { config };
421420
} catch (e) {
422-
return { config: null, error: this._configLocation.resolvedConfigFile ? serializeLoadError(this._configLocation.resolvedConfigFile, e) : serializeError(e) };
421+
const error: reporterTypes.TestError = serializeError(e);
422+
if (e.name === 'SyntaxError' && e.code === 'BABEL_PARSE_ERROR' && this._configLocation.resolvedConfigFile) {
423+
error.location = {
424+
file: this._configLocation.resolvedConfigFile,
425+
line: e.loc?.line,
426+
column: e.loc?.column,
427+
};
428+
} else {
429+
error.location = prepareErrorStack(e.stack).location;
430+
}
431+
return { config: null, error };
423432
}
424433
}
425434

tests/playwright-test/test-server.spec.ts

+45
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,51 @@ test('should list tests with testIdAttribute', async ({ startTestServer, writeFi
145145
expect(onProject.use.testIdAttribute).toBe('testId');
146146
});
147147

148+
test('should serialize exception if config throws error', async ({ startTestServer, writeFiles }) => {
149+
await writeFiles({
150+
'playwright.config.ts': `
151+
throw new Error('Config error');
152+
`,
153+
});
154+
155+
const testServerConnection = await startTestServer();
156+
const events = await testServerConnection.listFiles({});
157+
const error = events.report.find(e => e.method === 'onError').params.error;
158+
expect(error).toEqual({
159+
message: expect.stringContaining('Config error'),
160+
location: {
161+
file: expect.stringContaining('playwright.config.ts'),
162+
line: 2,
163+
column: 13,
164+
},
165+
snippet: expect.anything(),
166+
stack: expect.stringContaining('Error: Config error'),
167+
});
168+
});
169+
170+
171+
test('should serialize exception if config has SyntaxError', async ({ startTestServer, writeFiles }) => {
172+
await writeFiles({
173+
'playwright.config.ts': `
174+
Invalid syntax
175+
`,
176+
});
177+
178+
const testServerConnection = await startTestServer();
179+
const events = await testServerConnection.listFiles({});
180+
const error = events.report.find(e => e.method === 'onError').params.error;
181+
expect(error).toEqual({
182+
message: expect.stringMatching(/SyntaxError: .*playwright\.config\.ts: Missing semicolon/),
183+
location: {
184+
file: expect.stringContaining('playwright.config.ts'),
185+
line: 2,
186+
column: 13,
187+
},
188+
snippet: expect.anything(),
189+
stack: expect.stringMatching(/SyntaxError: .*playwright\.config\.ts: Missing semicolon/),
190+
});
191+
});
192+
148193
test('stdio interception', async ({ startTestServer, writeFiles }) => {
149194
const testServerConnection = await startTestServer();
150195
await testServerConnection.initialize({ interceptStdio: true });

0 commit comments

Comments
 (0)