Skip to content

Commit 56f9281

Browse files
committed
E2E: infra refactor + app tests update
1 parent 644636b commit 56f9281

9 files changed

Lines changed: 637 additions & 262 deletions

File tree

packages/e2e/helpers/load-env.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-disable no-restricted-imports */
2+
import * as fs from 'fs'
3+
import * as path from 'path'
4+
import {fileURLToPath} from 'url'
5+
6+
/**
7+
* Load a .env file into process.env (without overwriting existing values).
8+
* Handles quotes and inline comments (e.g. "VALUE # comment" → "VALUE").
9+
*/
10+
export function loadEnv(dirOrUrl: string): void {
11+
const dir = dirOrUrl.startsWith('file://') ? path.dirname(fileURLToPath(dirOrUrl)) : dirOrUrl
12+
const envPath = path.join(dir, '.env')
13+
if (!fs.existsSync(envPath)) return
14+
15+
for (const line of fs.readFileSync(envPath, 'utf-8').split('\n')) {
16+
const trimmed = line.trim()
17+
if (!trimmed || trimmed.startsWith('#')) continue
18+
const eqIdx = trimmed.indexOf('=')
19+
if (eqIdx === -1) continue
20+
const key = trimmed.slice(0, eqIdx).trim()
21+
let value = trimmed.slice(eqIdx + 1).trim()
22+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
23+
value = value.slice(1, -1)
24+
} else {
25+
const commentIdx = value.indexOf(' #')
26+
if (commentIdx !== -1) value = value.slice(0, commentIdx).trim()
27+
}
28+
process.env[key] ??= value
29+
}
30+
}

packages/e2e/playwright.config.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
/* eslint-disable line-comment-position */
2-
/* eslint-disable no-restricted-imports */
2+
import {loadEnv} from './helpers/load-env.js'
33
import {defineConfig} from '@playwright/test'
4-
import * as fs from 'fs'
5-
import * as path from 'path'
6-
import {fileURLToPath} from 'url'
74

8-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
9-
10-
// Load .env file if present (CI provides env vars directly)
11-
const envPath = path.join(__dirname, '.env')
12-
if (fs.existsSync(envPath)) {
13-
for (const line of fs.readFileSync(envPath, 'utf-8').split('\n')) {
14-
const trimmed = line.trim()
15-
if (!trimmed || trimmed.startsWith('#')) continue
16-
const eqIdx = trimmed.indexOf('=')
17-
if (eqIdx === -1) continue
18-
const key = trimmed.slice(0, eqIdx).trim()
19-
const value = trimmed.slice(eqIdx + 1).trim()
20-
process.env[key] ??= value
21-
}
22-
}
5+
loadEnv(import.meta.url)
236

247
const isCI = Boolean(process.env.CI)
258

0 commit comments

Comments
 (0)