Skip to content

Commit 286de40

Browse files
authored
fix: improve environment variable handling in Playwright config (#7605)
2 parents c56f673 + ddfea5a commit 286de40

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

packages/tools/visual-tests/playwright.config.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ import { defineConfig, devices } from '@playwright/test';
22
import * as path from 'path';
33
import * as process from 'process';
44

5-
const PORT = Number(process.env.KOLIBRI_VISUAL_TEST_PORT);
6-
const URL = `http://localhost:${PORT}`;
5+
// Validate and set ENVs
6+
const PORT = parseInt(process.env.KOLIBRI_VISUAL_TEST_PORT || '', 10);
7+
const BASE_URL = `http://localhost:${PORT}`;
78

8-
console.log('Serving React Sample app:', URL);
9+
const CWD = process.env.KOLIBRI_CWD ?? '';
10+
const TIMEOUT = parseInt(process.env.KOLIBRI_VISUAL_TESTS_TIMEOUT || '15000', 10);
11+
const EXPECT_TIMEOUT = parseInt(process.env.KOLIBRI_VISUAL_TESTS_EXPECT_TIMEOUT || '5000', 10);
12+
const BUILD_PATH = process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH ?? '';
13+
const THEME = (process.env.THEME_EXPORT || 'default').toLocaleLowerCase();
914

1015
/**
1116
* See https://playwright.dev/docs/test-configuration.
1217
*/
1318
export default defineConfig({
1419
testDir: './tests',
15-
snapshotDir: path.join(process.env.KOLIBRI_CWD ?? '', 'snapshots'),
20+
snapshotDir: path.join(CWD, 'snapshots'),
1621
// snapshotPathTemplate: '',
17-
outputDir: path.join(process.env.KOLIBRI_CWD ?? '', 'test-results'),
22+
outputDir: path.join(CWD, 'test-results'),
1823
/* Run tests in files in parallel */
1924
fullyParallel: true,
2025
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -24,18 +29,22 @@ export default defineConfig({
2429
/* Opt out of parallel tests on CI. */
2530
workers: process.env.CI ? 1 : undefined,
2631
/* Allow to override the expectation timeout for slow environments */
27-
timeout: process.env.KOLIBRI_VISUAL_TESTS_TIMEOUT ? Number(process.env.KOLIBRI_VISUAL_TESTS_TIMEOUT) : undefined,
32+
timeout: TIMEOUT,
2833
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2934
reporter: 'line',
3035
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3136
use: {
3237
/* Base URL to use in actions like `await page.goto('/')`. */
33-
baseURL: URL,
38+
baseURL: BASE_URL,
3439

3540
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3641
trace: 'on-first-retry',
3742
},
3843

44+
expect: {
45+
timeout: EXPECT_TIMEOUT,
46+
},
47+
3948
/* Configure projects for major browsers */
4049
projects: [
4150
// {
@@ -55,9 +64,9 @@ export default defineConfig({
5564
/* Run your local dev server before starting the tests */
5665
webServer: {
5766
command: `npx serve -p ${PORT}`,
58-
cwd: path.resolve(process.env.KOLIBRI_VISUAL_TESTS_BUILD_PATH),
59-
url: URL,
67+
cwd: path.resolve(BUILD_PATH),
68+
url: BASE_URL,
6069
reuseExistingServer: false,
6170
},
62-
snapshotPathTemplate: `{snapshotDir}/theme-${(process.env.THEME_EXPORT || 'default').toLocaleLowerCase()}/{arg}-{projectName}-{platform}{ext}`,
71+
snapshotPathTemplate: `{snapshotDir}/theme-${THEME}/{arg}-{projectName}-{platform}{ext}`,
6372
});

0 commit comments

Comments
 (0)