Skip to content

Commit fafd8d6

Browse files
committed
test: skip tests with known error messages
1 parent 60373c1 commit fafd8d6

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

packages/playwright-cloudflare/tests/src/server/testsServer.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { TestRunner, TestEndPayload, isUnderTest } from '@cloudflare/playwright/internal';
1+
import { TestRunner, TestEndPayload, isUnderTest, TestInfoError, TestResult } from '@cloudflare/playwright/internal';
22
import { DurableObject } from 'cloudflare:workers';
33
import '@workerTests/index';
44

5-
import { skipTests } from '../skipTests';
5+
import { skipTests, skipErrorMessages } from '../skipTests';
66
import { BrowserBindingName } from '../utils';
77

88
export type TestRequestPayload = {
@@ -17,6 +17,17 @@ const log = console.log.bind(console);
1717

1818
const skipTestsFullTitles = new Set(skipTests.map(t => t.join(' > ')));
1919

20+
function formatError(error: TestInfoError | Error | string) {
21+
if (typeof error === 'string')
22+
return error;
23+
return `${error.message}${error.stack ? `\n${error.stack}` : ''}`;
24+
}
25+
26+
function shouldSkipTestResult(testResult: TestResult) {
27+
const errorText = testResult.errors.map(e => formatError(e)).join('\n');
28+
return skipErrorMessages.some(msg => typeof msg === 'string' ? errorText.includes(msg) : msg.test(errorText));
29+
}
30+
2031
export class TestsServer extends DurableObject<Env> {
2132
constructor(state: DurableObjectState, env: Env) {
2233
super(state, env);
@@ -61,9 +72,28 @@ export class TestsServer extends DurableObject<Env> {
6172
log(`🧪 Running ${fullTitle}${retry ? ` (retry #${retry})` : ''}`);
6273

6374
const result = await testRunner.runTest(file, testId);
75+
6476
if (!['passed', 'skipped'].includes(result.status)) {
65-
const error = result.errors[0];
66-
log(`❌ ${fullTitle} failed with status ${result.status}${error ? `: ${error.message}` : ''}${error.stack ? `\n${error.stack}` : ''}`);
77+
if (shouldSkipTestResult(result)) {
78+
log(`🚫 Skipping ${fullTitle} because it failed with a known error message`);
79+
return Response.json({
80+
testId,
81+
status: 'skipped',
82+
errors: result.errors,
83+
annotations: [
84+
{
85+
type: 'skip',
86+
description: `Test skipped because it failed with a known error message`,
87+
}
88+
],
89+
duration: 0,
90+
hasNonRetriableError: false,
91+
timeout,
92+
expectedStatus: 'skipped'
93+
} satisfies TestEndPayload);
94+
}
95+
const [error] = result.errors;
96+
log(`❌ ${fullTitle} failed with status ${result.status}${error ? `: ${formatError(error)}` : ''}`);
6797
}
6898
return Response.json(result);
6999
}

packages/playwright-cloudflare/tests/src/server/workerFixtures.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class TestServer {
111111
sendOnWebSocketConnection() {
112112
this._testInfo.skip(true, 'sendOnWebSocketConnection not supported, skipping');
113113
}
114+
115+
setExtraHeaders() {
116+
this._testInfo.skip(true, 'setExtraHeaders not supported, skipping');
117+
}
114118
}
115119

116120
export type ServerFixtures = {

packages/playwright-cloudflare/tests/src/skipTests.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@ export const skipTests: string[][] = [
1111
['page/page-event-popup.spec.ts', 'should work @smoke'],
1212
['page/page-history.spec.ts', 'page.goBack should work @smoke'],
1313
];
14+
15+
export const skipErrorMessages: Array<string | RegExp> = [
16+
'Cloudflare Workers does not support',
17+
'__filename is not defined',
18+
'__dirname is not defined',
19+
'\(\) => {}', // Cloudflare serializes empty arrow function with new lines
20+
'Expected substring: "Mozilla"',
21+
'createHttp2Server is not defined',
22+
/\[unenv\] .* is not implemented yet!/,
23+
];

0 commit comments

Comments
 (0)