Repository navigation
Expand file tree
/
Copy pathdesktop-e2e.test.ts
More file actions
60 lines (59 loc) · 2.46 KB
/
Copy pathdesktop-e2e.test.ts
File metadata and controls
60 lines (59 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { spawnSync } from 'node:child_process'
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
import { expect, it } from 'vitest'
it.each([
{ index: 1, title: 'brand-new.test.ts' },
{ index: 2, title: 'factory' },
{ index: 3, title: 'ordinary.spec.ts' },
])('executes only $title on desktop shard $index/3', ({ index, title }) => {
const root = resolve(import.meta.dirname, '..')
const fixture = mkdtempSync(join(tmpdir(), 'desktop-shard-'))
try {
symlinkSync(join(root, 'node_modules'), join(fixture, 'node_modules'), 'dir')
writeFileSync(join(fixture, 'package.json'), '{"type":"module"}')
writeFileSync(
join(fixture, 'playwright.config.ts'),
"export default { testDir: './tests', workers: 1, retries: 0 }"
)
mkdirSync(join(fixture, 'tests/nested'), { recursive: true })
mkdirSync(join(fixture, 'tests/support'), { recursive: true })
writeFileSync(
join(fixture, 'tests/support/factory.ts'),
"import { test } from '@playwright/test'; export function register() { test('factory', () => {}); }"
)
writeFileSync(
join(fixture, 'tests/nested/a[1].spec.ts'),
"import { register } from '../support/factory'; register();"
)
for (const file of ['brand-new.test.ts', 'ordinary.spec.ts']) {
writeFileSync(
join(fixture, 'tests', file),
`import { test } from '@playwright/test'; test('${file}', () => {});`
)
}
const cases: { title: string; status: string }[] = []
const reportPath = join(fixture, `${index}.json`)
const result = spawnSync('bun', ['run', join(root, 'scripts/desktop-e2e.ts'), `${index}/3`], {
cwd: fixture,
env: { ...process.env, PLAYWRIGHT_JSON_OUTPUT_FILE: reportPath },
encoding: 'utf8',
timeout: 10_000,
})
expect(result.status, result.stdout + result.stderr).toBe(0)
const report = JSON.parse(readFileSync(reportPath, 'utf8')) as {
suites: { specs: { title: string; tests: { results: { status: string }[] }[] }[] }[]
}
for (const suite of report.suites) {
for (const spec of suite.specs) {
for (const test of spec.tests) {
for (const run of test.results) cases.push({ title: spec.title, status: run.status })
}
}
}
expect(cases).toEqual([{ title, status: 'passed' }])
} finally {
rmSync(fixture, { recursive: true, force: true })
}
})