Skip to content

Commit 8d56953

Browse files
committed
chore: run tests
1 parent 3f8820f commit 8d56953

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../class-components.spec'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../mdx.spec'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../react.spec'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../react-sourcemap.spec'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../react.spec'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../ssr-react.spec'

playground/vitestGlobalSetup.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,52 @@ export async function setup({ provide }: TestProject): Promise<void> {
4141
}
4242
})
4343

44-
// also setup dedicated copy for plugin-react-oxc tests
45-
const oxcIgnoredDirs = new Set([
46-
'compiler',
47-
'compiler-react-18',
48-
'react-classic',
49-
'react-emotion',
50-
'node_modules',
51-
])
52-
const oxcPlaygrounds = (
44+
const playgrounds = (
5345
await fs.readdir(path.resolve(__dirname, '../playground'), {
5446
withFileTypes: true,
5547
})
56-
).filter((dirent) => !oxcIgnoredDirs.has(dirent.name) && dirent.isDirectory())
57-
for (const { name: playgroundName } of oxcPlaygrounds) {
48+
).filter((dirent) => dirent.name !== 'node_modules' && dirent.isDirectory())
49+
for (const { name: playgroundName } of playgrounds) {
50+
// write vite proxy file to load vite from each playground
51+
await fs.writeFile(
52+
path.resolve(tempDir, `${playgroundName}/_vite-proxy.js`),
53+
"export * from 'vite';",
54+
)
55+
56+
// also setup dedicated copy for plugin-react-oxc tests
57+
const oxcTestDir = path.resolve(
58+
__dirname,
59+
'../playground',
60+
playgroundName,
61+
'__tests__/oxc',
62+
)
63+
if (!(await fs.exists(oxcTestDir))) continue
64+
65+
const variantPlaygroundName = `${playgroundName}__oxc`
5866
await fs.copy(
5967
path.resolve(tempDir, playgroundName),
60-
path.resolve(tempDir, `${playgroundName}-oxc`),
68+
path.resolve(tempDir, variantPlaygroundName),
6169
)
6270
await fs.remove(
6371
path.resolve(
6472
tempDir,
65-
`${playgroundName}-oxc/node_modules/@vitejs/plugin-react`,
73+
`${variantPlaygroundName}/node_modules/@vitejs/plugin-react`,
6674
),
6775
)
6876
await fs.symlink(
6977
path.resolve(__dirname, '../packages/plugin-react-oxc'),
7078
path.resolve(
7179
tempDir,
72-
`${playgroundName}-oxc/node_modules/@vitejs/plugin-react`,
80+
`${variantPlaygroundName}/node_modules/@vitejs/plugin-react`,
7381
),
7482
)
7583
await fs.symlink(
7684
path.resolve(__dirname, '../packages/plugin-react-oxc/node_modules/vite'),
77-
path.resolve(tempDir, `${playgroundName}-oxc/node_modules/vite`),
85+
path.resolve(tempDir, `${variantPlaygroundName}/node_modules/vite`),
7886
)
7987
await fs.copy(
8088
path.resolve(__dirname, '../packages/plugin-react-oxc/node_modules/.bin'),
81-
path.resolve(tempDir, `${playgroundName}-oxc/node_modules/.bin`),
89+
path.resolve(tempDir, `${variantPlaygroundName}/node_modules/.bin`),
8290
)
8391
}
8492
}

playground/vitestSetup.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ import type {
1212
UserConfig,
1313
ViteDevServer,
1414
} from 'vite'
15-
import {
16-
build,
17-
createBuilder,
18-
createServer,
19-
loadConfigFromFile,
20-
mergeConfig,
21-
preview,
22-
} from 'vite'
2315
import type { Browser, Page } from 'playwright-chromium'
2416
import type { RunnerTestFile } from 'vitest'
2517
import { beforeAll, inject } from 'vitest'
@@ -188,6 +180,8 @@ beforeAll(async (s) => {
188180
})
189181

190182
async function loadConfig(configEnv: ConfigEnv) {
183+
const { loadConfigFromFile, mergeConfig } = await importVite()
184+
191185
let config: UserConfig | null = null
192186

193187
// config file named by convention as the *.spec.ts folder
@@ -240,6 +234,9 @@ async function loadConfig(configEnv: ConfigEnv) {
240234
}
241235

242236
export async function startDefaultServe(): Promise<void> {
237+
const { build, createBuilder, createServer, mergeConfig, preview } =
238+
await importVite()
239+
243240
setupConsoleWarnCollector(serverLogs)
244241

245242
if (!isBuild) {
@@ -369,6 +366,11 @@ function stripTrailingSlashIfNeeded(url: string, base: string): string {
369366
return url
370367
}
371368

369+
async function importVite(): Promise<typeof import('vite')> {
370+
const vitePath = path.resolve(testDir, '_vite-proxy.js')
371+
return await import(vitePath)
372+
}
373+
372374
declare module 'vite' {
373375
export interface UserConfig {
374376
/**

0 commit comments

Comments
 (0)