-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathroot.test.ts
More file actions
94 lines (86 loc) · 2.9 KB
/
root.test.ts
File metadata and controls
94 lines (86 loc) · 2.9 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
import fs from 'node:fs'
import path from 'node:path'
import { test } from '@playwright/test'
import { setupInlineFixture, useFixture } from './fixture'
import { defineStarterTest } from './starter'
test.describe(() => {
const root = 'examples/e2e/temp/root'
test.beforeAll(async () => {
await setupInlineFixture({
src: 'examples/starter',
dest: root,
files: {
'vite.config.base.ts': { cp: 'vite.config.ts' },
'vite.config.ts': /* js */ `
import baseConfig from './vite.config.base.ts'
import path from "node:path";
baseConfig.root = "./custom-root";
for (const e of Object.values(baseConfig.environments)) {
e.build.rollupOptions.input.index = path.resolve(
'custom-root',
e.build.rollupOptions.input.index,
);
}
export default baseConfig;
`,
},
})
fs.mkdirSync(`${root}/custom-root`, { recursive: true })
fs.renameSync(`${root}/src`, `${root}/custom-root/src`)
fs.renameSync(`${root}/public`, `${root}/custom-root/public`)
})
test.describe('dev-root', () => {
const f = useFixture({ root, mode: 'dev' })
const oldCreateEditor = f.createEditor
f.createEditor = (filePath: string) =>
oldCreateEditor(path.resolve(root, 'custom-root', filePath))
defineStarterTest(f)
})
test.describe('build-root', () => {
const f = useFixture({ root, mode: 'build' })
defineStarterTest(f)
})
})
// Test that the RSC plugin works when `root` is passed as a CLI argument
// e.g. `vite dev ./app` where the app lives in a subdirectory.
// This effectively tests `createServer/createBuilder({ root })`
// and then loading config file from the specified root.
test.describe('root-config', () => {
const root = 'examples/e2e/temp/root-config'
test.beforeAll(async () => {
await setupInlineFixture({
src: 'examples/starter',
dest: `${root}/app`,
files: {
'vite.config.base.ts': { cp: 'vite.config.ts' },
'vite.config.ts': /* js */ `
import baseConfig from './vite.config.base.ts'
import path from "node:path";
for (const e of Object.values(baseConfig.environments)) {
e.build.rollupOptions.input.index = path.resolve(
'app',
e.build.rollupOptions.input.index,
);
}
export default baseConfig;
`,
},
})
})
test.describe('dev', () => {
const f = useFixture({ root, mode: 'dev', command: 'vite dev ./app' })
const oldCreateEditor = f.createEditor
f.createEditor = (filePath: string) =>
oldCreateEditor(path.resolve(root, 'app', filePath))
defineStarterTest(f)
})
test.describe('build', () => {
const f = useFixture({
root,
mode: 'build',
buildCommand: 'vite build ./app',
command: 'vite preview ./app',
})
defineStarterTest(f)
})
})