mirror of
https://github.com/microsoft/playwright.git
synced 2024-11-28 09:23:42 +03:00
feat(test-runner): filter out syntax error stack traces (#12095)
Filter out long stack traces from babel when it fails compilation due to syntax error in test.
This commit is contained in:
parent
6ff23fc446
commit
ef21ce3f56
@ -189,6 +189,7 @@ export function transformHook(code: string, filename: string, isModule = false):
|
||||
if (hasPreprocessor)
|
||||
plugins.push([scriptPreprocessor]);
|
||||
|
||||
try {
|
||||
const result = babel.transformFileSync(filename, {
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
@ -210,6 +211,11 @@ export function transformHook(code: string, filename: string, isModule = false):
|
||||
fs.writeFileSync(codePath, result.code, 'utf8');
|
||||
}
|
||||
return result.code || '';
|
||||
} catch (e) {
|
||||
// Re-throw error with a playwright-test stack
|
||||
// that could be filtered out.
|
||||
throw new Error(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
export function installTransform(): () => void {
|
||||
|
@ -47,7 +47,10 @@ function filterStackTrace(e: Error) {
|
||||
const functionName = callSite.getFunctionName() || undefined;
|
||||
if (!fileName)
|
||||
return true;
|
||||
return !fileName.startsWith(PLAYWRIGHT_TEST_PATH) && !fileName.startsWith(PLAYWRIGHT_CORE_PATH) && !fileName.startsWith(EXPECT_PATH) && !isInternalFileName(fileName, functionName);
|
||||
return !fileName.startsWith(PLAYWRIGHT_TEST_PATH) &&
|
||||
!fileName.startsWith(PLAYWRIGHT_CORE_PATH) &&
|
||||
!fileName.startsWith(EXPECT_PATH) &&
|
||||
!isInternalFileName(fileName, functionName);
|
||||
}));
|
||||
};
|
||||
// eslint-disable-next-line
|
||||
|
@ -314,6 +314,21 @@ test('should filter out event emitter from stack traces', async ({ runInlineTest
|
||||
expect(outputWithoutGoodStackFrames).not.toContain('EventEmitter.emit');
|
||||
});
|
||||
|
||||
test('should filter out syntax error stack traces', async ({ runInlineTest }, testInfo) => {
|
||||
const result = await runInlineTest({
|
||||
'expect-test.spec.ts': `
|
||||
const { test } = pwt;
|
||||
test('should work', ({}) => {
|
||||
// syntax error: cannot have await in non-async function
|
||||
await Proimse.resolve();
|
||||
});
|
||||
`
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(stripAnsi(result.output)).not.toContain('babel');
|
||||
expect(stripAnsi(result.output)).not.toContain(' at ');
|
||||
});
|
||||
|
||||
test('should filter stack trace for raw errors', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'expect-test.spec.ts': `
|
||||
|
Loading…
Reference in New Issue
Block a user