Skip to content

Commit 9c92ece

Browse files
authored
ref(e2e-tests): Make startCommand optional in shared playwright config (#12842)
Not all our e2e tests require a `startCommand` as we sometimes directly invoke an application from within tests. For example in our AWS lambda e2e tests. This PR makes the `startCommand` option optional so that we can avoid a larger override of the entire `webServer` playwright config object.
1 parent f378772 commit 9c92ece

File tree

4 files changed

+31
-119
lines changed

4 files changed

+31
-119
lines changed
Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,3 @@
1-
import type { PlaywrightTestConfig } from '@playwright/test';
2-
import { devices } from '@playwright/test';
1+
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
32

4-
// Fix urls not resolving to localhost on Node v17+
5-
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
6-
import { setDefaultResultOrder } from 'dns';
7-
setDefaultResultOrder('ipv4first');
8-
9-
const eventProxyPort = 3031;
10-
const lambdaPort = 3030;
11-
12-
/**
13-
* See https://playwright.dev/docs/test-configuration.
14-
*/
15-
const config: PlaywrightTestConfig = {
16-
testDir: './tests',
17-
/* Maximum time one test can run for. */
18-
timeout: 150_000,
19-
expect: {
20-
/**
21-
* Maximum time expect() should wait for the condition to be met.
22-
* For example in `await expect(locator).toHaveText();`
23-
*/
24-
timeout: 5000,
25-
},
26-
/* Run tests in files in parallel */
27-
fullyParallel: true,
28-
/* Fail the build on CI if you accidentally left test.only in the source code. */
29-
forbidOnly: !!process.env.CI,
30-
/* Retry on CI only */
31-
retries: 0,
32-
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
33-
reporter: 'list',
34-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
35-
use: {
36-
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
37-
actionTimeout: 0,
38-
39-
/* Base URL to use in actions like `await page.goto('/')`. */
40-
baseURL: `http://localhost:${lambdaPort}`,
41-
42-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
43-
trace: 'on-first-retry',
44-
},
45-
46-
/* Configure projects for major browsers */
47-
projects: [
48-
{
49-
name: 'chromium',
50-
use: {
51-
...devices['Desktop Chrome'],
52-
},
53-
},
54-
// For now we only test Chrome!
55-
// {
56-
// name: 'firefox',
57-
// use: {
58-
// ...devices['Desktop Firefox'],
59-
// },
60-
// },
61-
// {
62-
// name: 'webkit',
63-
// use: {
64-
// ...devices['Desktop Safari'],
65-
// },
66-
// },
67-
],
68-
69-
/* Run your local dev server before starting the tests */
70-
webServer: [
71-
{
72-
command: `node start-event-proxy.mjs && pnpm wait-port ${eventProxyPort}`,
73-
port: eventProxyPort,
74-
stdout: 'pipe',
75-
},
76-
],
77-
};
78-
79-
export default config;
3+
export default getPlaywrightConfig();
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
11
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
22

3-
// Fix urls not resolving to localhost on Node v17+
4-
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575
5-
import { setDefaultResultOrder } from 'dns';
6-
setDefaultResultOrder('ipv4first');
7-
8-
const eventProxyPort = 3031;
9-
10-
/**
11-
* See https://playwright.dev/docs/test-configuration.
12-
*/
13-
const config = getPlaywrightConfig(
14-
{ startCommand: '' },
15-
{
16-
/* Run your local dev server before starting the tests */
17-
webServer: [
18-
{
19-
command: `node start-event-proxy.mjs && pnpm wait-port ${eventProxyPort}`,
20-
port: eventProxyPort,
21-
stdout: 'pipe',
22-
},
23-
],
24-
},
25-
);
26-
27-
export default config;
3+
export default getPlaywrightConfig();

dev-packages/test-utils/.eslintrc.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@ module.exports = {
33
node: true,
44
},
55
extends: ['../../.eslintrc.js'],
6-
overrides: [],
6+
overrides: [
7+
{
8+
files: ['**/*.ts'],
9+
rules: {
10+
'@sentry-internal/sdk/no-optional-chaining': 'off',
11+
},
12+
},
13+
],
714
};

dev-packages/test-utils/src/playwright-config.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ import type { PlaywrightTestConfig } from '@playwright/test';
22

33
/** Get a playwright config to use in an E2E test app. */
44
export function getPlaywrightConfig(
5-
options: {
6-
startCommand: string;
5+
options?: {
6+
startCommand?: string;
77
port?: number;
88
eventProxyPort?: number;
99
eventProxyFile?: string;
1010
},
1111
overwriteConfig?: Partial<PlaywrightTestConfig>,
1212
): PlaywrightTestConfig {
1313
const testEnv = process.env['TEST_ENV'] || 'production';
14-
const appPort = options.port || 3030;
15-
const eventProxyPort = options.eventProxyPort || 3031;
16-
const eventProxyFile = options.eventProxyFile || 'start-event-proxy.mjs';
17-
const { startCommand } = options;
14+
const appPort = options?.port || 3030;
15+
const eventProxyPort = options?.eventProxyPort || 3031;
16+
const eventProxyFile = options?.eventProxyFile || 'start-event-proxy.mjs';
17+
const startCommand = options?.startCommand;
1818

1919
/**
2020
* See https://playwright.dev/docs/test-configuration.
@@ -76,18 +76,23 @@ export function getPlaywrightConfig(
7676
stdout: 'pipe',
7777
stderr: 'pipe',
7878
},
79-
{
80-
command: startCommand,
81-
port: appPort,
82-
stdout: 'pipe',
83-
stderr: 'pipe',
84-
env: {
85-
PORT: appPort.toString(),
86-
},
87-
},
8879
],
8980
};
9081

82+
if (startCommand) {
83+
// @ts-expect-error - we set `config.webserver` to an array above.
84+
// TS just can't infer that and thinks it could also be undefined or an object.
85+
config.webServer.push({
86+
command: startCommand,
87+
port: appPort,
88+
stdout: 'pipe',
89+
stderr: 'pipe',
90+
env: {
91+
PORT: appPort.toString(),
92+
},
93+
});
94+
}
95+
9196
return {
9297
...config,
9398
...overwriteConfig,

0 commit comments

Comments
 (0)