Skip to content

Commit fcfd1bf

Browse files
committed
test: give each dev spec its own fixture copy
1 parent f6ec495 commit fcfd1bf

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ stats.json
1010
playground-bun*
1111
playground-deno*
1212
playground-node*
13+
packages/nuxt-cli/test/fixtures/.tmp-*
1314
packages/nuxi/src/utils/completions-data.ts
1415
packages/nuxt-cli/src/data/nitro-presets.ts
1516
packages/nuxt-cli/src/data/templates.ts

‎packages/nuxt-cli/test/e2e/dev-restart.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import{randomUUID}from'node:crypto'
22
import{rm}from'node:fs/promises'
33
import{join}from'node:path'
4-
import{fileURLToPath}from'node:url'
54
import{getPort}from'get-port-please'
65
import{describe,expect,it,vi}from'vitest'
76
import{initialize}from'../../src/dev'
7+
import{createDevFixture}from'../utils'
88

9-
constfixtureDir=fileURLToPath(newURL('../fixtures/dev',import.meta.url))
9+
constfixtureDir=awaitcreateDevFixture('dev-restart')
1010

1111
describe('dev server reload',()=>{
1212
it('should settle in-flight requests when nuxt reloads',{timeout: 90_000},async()=>{

‎packages/nuxt-cli/test/e2e/dev.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { fileURLToPath } from 'node:url'
44
import{getPort}from'get-port-please'
55
import{afterEach,describe,expect,it,vi}from'vitest'
66
import{runCommand}from'../../src'
7+
import{createDevFixture}from'../utils'
78

89
constNEWLINE_RE=/\r?\n/
910

10-
constfixtureDir=fileURLToPath(newURL('../fixtures/dev',import.meta.url))
11+
constfixtureDir=awaitcreateDevFixture('dev')
1112

1213
constcertsDir=fileURLToPath(newURL('../../../../playground/certs',import.meta.url))
1314
consthttpsCert=join(certsDir,'cert.dummy')

‎packages/nuxt-cli/test/utils/index.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import{cp,rm,symlink}from'node:fs/promises'
2+
import{join,sep}from'node:path'
3+
import{fileURLToPath}from'node:url'
14
import{isCI}from'std-env'
25

36
exportasyncfunctionfetchWithPolling(url: string,options: RequestInit={},maxAttempts=10,interval=100): Promise<Response|null>{
@@ -18,3 +21,24 @@ export async function fetchWithPolling(url: string, options: RequestInit = {}, m
1821
}
1922
returnresponse
2023
}
24+
25+
/**
26+
* Clone the shared `dev` fixture into a project private to a single spec file.
27+
*
28+
* The dev e2e specs each wipe `.nuxt` and take the dev lock inside their
29+
* fixture, so pointing more than one of them at `fixtures/dev` makes them race
30+
* whenever vitest runs the files in parallel.
31+
*/
32+
exportasyncfunctioncreateDevFixture(name: string): Promise<string>{
33+
constsource=fileURLToPath(newURL('../fixtures/dev',import.meta.url))
34+
consttarget=fileURLToPath(newURL(`../fixtures/.tmp-${name}`,import.meta.url))
35+
36+
awaitrm(target,{recursive: true,force: true})
37+
awaitcp(source,target,{
38+
recursive: true,
39+
filter: entry=>!entry.includes('node_modules')&&!entry.includes(`${sep}.nuxt`),
40+
})
41+
awaitsymlink(join(source,'node_modules'),join(target,'node_modules'),'junction')
42+
43+
returntarget
44+
}

0 commit comments

Comments
 (0)