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,27 +189,33 @@ export function transformHook(code: string, filename: string, isModule = false):
|
||||
if (hasPreprocessor)
|
||||
plugins.push([scriptPreprocessor]);
|
||||
|
||||
const result = babel.transformFileSync(filename, {
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
assumptions: {
|
||||
// Without this, babel defines a top level function that
|
||||
// breaks playwright evaluates.
|
||||
setPublicClassFields: true,
|
||||
},
|
||||
presets: [
|
||||
[require.resolve('@babel/preset-typescript'), { onlyRemoveTypeImports: true }],
|
||||
],
|
||||
plugins,
|
||||
sourceMaps: 'both',
|
||||
} as babel.TransformOptions)!;
|
||||
if (result.code) {
|
||||
fs.mkdirSync(path.dirname(cachePath), { recursive: true });
|
||||
if (result.map)
|
||||
fs.writeFileSync(sourceMapPath, JSON.stringify(result.map), 'utf8');
|
||||
fs.writeFileSync(codePath, result.code, 'utf8');
|
||||
try {
|
||||
const result = babel.transformFileSync(filename, {
|
||||
babelrc: false,
|
||||
configFile: false,
|
||||
assumptions: {
|
||||
// Without this, babel defines a top level function that
|
||||
// breaks playwright evaluates.
|
||||
setPublicClassFields: true,
|
||||
},
|
||||
presets: [
|
||||
[require.resolve('@babel/preset-typescript'), { onlyRemoveTypeImports: true }],
|
||||
],
|
||||
plugins,
|
||||
sourceMaps: 'both',
|
||||
} as babel.TransformOptions)!;
|
||||
if (result.code) {
|
||||
fs.mkdirSync(path.dirname(cachePath), { recursive: true });
|
||||
if (result.map)
|
||||
fs.writeFileSync(sourceMapPath, JSON.stringify(result.map), 'utf8');
|
||||
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);
|
||||
}
|
||||
return result.code || '';
|
||||
}
|
||||
|
||||
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