mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
test: refactor hmr-ssr tests (#18075)
This commit is contained in:
parent
41180d0273
commit
e7d51a361f
File diff suppressed because it is too large
Load Diff
@ -8,4 +8,12 @@ if (import.meta.hot) {
|
||||
|
||||
rerender({ child: newMod.value })
|
||||
})
|
||||
|
||||
import.meta.hot.dispose(() => {
|
||||
log('file-delete-restore/child.js is disposed')
|
||||
})
|
||||
|
||||
import.meta.hot.prune(() => {
|
||||
log('file-delete-restore/child.js is pruned')
|
||||
})
|
||||
}
|
||||
|
@ -142,7 +142,9 @@ export function editFile(
|
||||
}
|
||||
|
||||
export function addFile(filename: string, content: string): void {
|
||||
fs.writeFileSync(path.resolve(testDir, filename), content)
|
||||
const resolvedFilename = path.resolve(testDir, filename)
|
||||
fs.mkdirSync(path.dirname(resolvedFilename), { recursive: true })
|
||||
fs.writeFileSync(resolvedFilename, content)
|
||||
}
|
||||
|
||||
export function removeFile(filename: string): void {
|
||||
|
@ -82,6 +82,14 @@ export function setViteUrl(url: string): void {
|
||||
|
||||
beforeAll(async (s) => {
|
||||
const suite = s as File
|
||||
|
||||
testPath = suite.filepath!
|
||||
testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1]
|
||||
testDir = path.dirname(testPath)
|
||||
if (testName) {
|
||||
testDir = path.resolve(workspaceRoot, 'playground-temp', testName)
|
||||
}
|
||||
|
||||
// skip browser setup for non-playground tests
|
||||
// TODO: ssr playground?
|
||||
if (
|
||||
@ -124,15 +132,9 @@ beforeAll(async (s) => {
|
||||
browserErrors.push(error)
|
||||
})
|
||||
|
||||
testPath = suite.filepath!
|
||||
testName = slash(testPath).match(/playground\/([\w-]+)\//)?.[1]
|
||||
testDir = path.dirname(testPath)
|
||||
|
||||
// if this is a test placed under playground/xxx/__tests__
|
||||
// start a vite server in that directory.
|
||||
if (testName) {
|
||||
testDir = path.resolve(workspaceRoot, 'playground-temp', testName)
|
||||
|
||||
// when `root` dir is present, use it as vite's root
|
||||
const testCustomRoot = path.resolve(testDir, 'root')
|
||||
rootDir = fs.existsSync(testCustomRoot) ? testCustomRoot : testDir
|
||||
|
Loading…
Reference in New Issue
Block a user