-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathrstest.config.ts
More file actions
106 lines (100 loc) · 4.12 KB
/
Copy pathrstest.config.ts
File metadata and controls
106 lines (100 loc) · 4.12 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import {defineConfig} from '@rstest/core'
import {fileURLToPath} from 'node:url'
const isBrowserMode = process.argv.some(arg => arg === '--browser' || arg.startsWith('--browser.'))
const isListCommand = process.argv.includes('list')
const isWatchCommand = process.argv.includes('watch')
const skipNextBrowserRebuildKey = 'APPS_BROWSER_SKIP_NEXT_REBUILD'
const browserScope = process.env.EMP_BROWSER_SCOPE === 'apps' ? 'apps' : 'all'
const appsBrowserTestFiles = ['apps/*/test/browser/**/*.browser.ts']
const empShareBrowserTestFiles = ['packages/emp-share/test/browser/**/*.browser.ts']
const browserTestFiles = browserScope === 'apps' ? appsBrowserTestFiles : [...appsBrowserTestFiles, ...empShareBrowserTestFiles]
const appsBrowserForceRerunTriggers = [
'apps/*/emp*.js',
'apps/*/emp*.ts',
'apps/adapter-host/src/**',
'apps/demo/src/**',
'apps/dual-role/src/**',
'apps/esm-federation/src/**',
'apps/mf-app/src/**',
'apps/mf-host/src/**',
'apps/react-19-tanstack/src/**',
'apps/rspack2-optimization/src/**',
'apps/tailwind-4/src/**',
'apps/vue-2-base/src/**',
'apps/vue-2-project/src/**',
'apps/vue-3-base/src/**',
'apps/vue-3-project/src/**',
'packages/cli/src/**',
'packages/emp-chain/src/**',
'packages/emp-share/src/**',
'scripts/apps-browser-harness.mjs',
'scripts/rstest-browser-mf-container.mjs',
'apps/*/test/browser/**/*.browser.ts',
'apps/test-support/browser/**/*.ts',
]
const empShareBrowserForceRerunTriggers = ['packages/emp-share/test/browser/**/*.browser.ts', 'packages/emp-share/output/**']
const browserForceRerunTriggers =
browserScope === 'apps' ? appsBrowserForceRerunTriggers : [...appsBrowserForceRerunTriggers, ...empShareBrowserForceRerunTriggers]
const testSupportAlias = fileURLToPath(new URL('./apps/test-support', import.meta.url))
if (isBrowserMode) {
process.env.RSTEST_CONTAINER_DEV_SERVER ??= 'http://localhost:51203/'
}
let cleanupAppsBrowserServicesOnce: (() => Promise<void>) | undefined
let cleanupAppsBrowserServicesNow: (() => void) | undefined
if (isBrowserMode && !isListCommand) {
const appsBrowserHarness = await import('./scripts/apps-browser-harness.mjs')
await appsBrowserHarness.startAppsBrowserServices()
cleanupAppsBrowserServicesNow = appsBrowserHarness.cleanupAppsBrowserServicesNow
process.env[skipNextBrowserRebuildKey] = 'true'
let cleanupStarted = false
cleanupAppsBrowserServicesOnce = async () => {
if (cleanupStarted) return
cleanupStarted = true
await appsBrowserHarness.cleanupAppsBrowserServices()
}
process.once('SIGINT', () => cleanupAppsBrowserServicesOnce?.().finally(() => process.exit(130)))
process.once('SIGTERM', () => cleanupAppsBrowserServicesOnce?.().finally(() => process.exit(143)))
process.once('beforeExit', () => {
void cleanupAppsBrowserServicesOnce?.()
})
process.once('exit', () => {
cleanupAppsBrowserServicesNow?.()
})
}
const browserRebuildReporter = {
onTestRunStart: async () => {
if (!isBrowserMode || isListCommand) return
if (process.env[skipNextBrowserRebuildKey] === 'true') {
delete process.env[skipNextBrowserRebuildKey]
return
}
const {buildAppsBrowserTargets} = await import('./scripts/apps-browser-harness.mjs')
await buildAppsBrowserTargets()
},
onTestRunEnd: async () => {
if (!isBrowserMode || isListCommand || isWatchCommand) return
await cleanupAppsBrowserServicesOnce?.()
},
}
export default defineConfig({
testEnvironment: 'node',
include: isBrowserMode ? browserTestFiles : ['test/**/*.test.ts', 'apps/test/**/*.test.ts'],
exclude: isBrowserMode ? [] : ['test/**/*.browser.ts', 'test/**/*.browser.test.ts', 'apps/**/*.browser.ts'],
forceRerunTriggers: isBrowserMode ? browserForceRerunTriggers : undefined,
resolve: {
alias: {
'@empjs/test-support': testSupportAlias,
},
},
reporters: isBrowserMode ? ['default', browserRebuildReporter] : undefined,
browser: isBrowserMode
? {
enabled: true,
provider: 'playwright',
browser: 'chromium',
viewport: {width: 1440, height: 1000},
}
: undefined,
hookTimeout: isBrowserMode ? 600000 : 5000,
testTimeout: isBrowserMode ? 600000 : 5000,
})