Skip to content

Commit bd19413

Browse files
committed
test: stop the command e2e suite mutating the shared playground
1 parent 013f43f commit bd19413

4 files changed

Lines changed: 27 additions & 17 deletions

File tree

‎packages/nuxt-cli/src/commands/docs.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { logger } from '../utils/logger'
1313
import{resolveRootDir}from'../utils/paths'
1414
import{withSpinner}from'../utils/spinner'
1515
import{isInteractive}from'../utils/stdout'
16-
import{rootDirArgs}from'./_shared'
16+
import{cwdArgs}from'./_shared'
1717

1818
constMAX_RESULTS=8
1919

@@ -28,15 +28,15 @@ export default defineCommand({
2828
description: 'Words to search the documentation for',
2929
required: false,
3030
},
31-
...rootDirArgs,
31+
...cwdArgs,
3232
open: {
3333
type: 'boolean',
3434
description: 'Open the best match in a browser',
3535
default: true,
3636
},
3737
},
3838
asyncrun(ctx){
39-
constquery=ctx.args._.slice(0,!ctx.args._.includes('--') ? undefined : ctx.args._.indexOf('--')).join(' ').trim()
39+
constquery=ctx.args._.join(' ').trim()
4040
if(!query){
4141
returnvisit(DOCS_PATH,ctx.args.open)
4242
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { getPort } from 'get-port-please'
1010
import{isWindows}from'std-env'
1111
import{x}from'tinyexec'
1212
import{describe,expect,it}from'vitest'
13-
import{fetchWithPolling}from'../utils'
13+
import{createPlaygroundFixture,fetchWithPolling}from'../utils'
1414

15-
constfixtureDir=fileURLToPath(newURL('../../../../playground',import.meta.url))
15+
constfixtureDir=awaitcreatePlaygroundFixture('commands')
1616
constnuxi=fileURLToPath(newURL('../../bin/nuxi.mjs',import.meta.url))
1717

1818
describe('commands',()=>{

‎packages/nuxt-cli/test/unit/help.spec.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,17 @@ describe('help', () => {
253253
expect(awaitusage(commands.docs,main)).toMatchInlineSnapshot(`
254254
"Search or open the Nuxt documentation (nuxt docs v0.0.0)
255255
256-
USAGE nuxt docs [OPTIONS] [QUERY] [ROOTDIR]
256+
USAGE nuxt docs [OPTIONS] [QUERY]
257257
258258
ARGUMENTS
259259
260-
QUERY Words to search the documentation for
261-
ROOTDIR The root directory of your Nuxt project (default: .)
260+
QUERY Words to search the documentation for
262261
263262
OPTIONS
264263
265-
--open Open the best match in a browser (Default: true)
266-
--no-open
264+
--cwd=<directory> Specify the root directory of your Nuxt project (Default: .)
265+
--open Open the best match in a browser (Default: true)
266+
--no-open
267267
"
268268
`)
269269
})

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@ export async function fetchWithPolling(url: string, options: RequestInit = {}, t
2828
}
2929

3030
/**
31-
* Clone the shared `dev` fixture into a project private to a single spec file.
31+
* Copy a fixture into a project private to a single spec file.
3232
*
33-
* The dev e2e specs each wipe `.nuxt` and take the dev lock inside their
34-
* fixture, so pointing more than one of them at `fixtures/dev` makes them race
35-
* whenever vitest runs the files in parallel.
33+
* The e2e specs build, clear and take locks inside their fixture, so pointing
34+
* more than one of them at the same directory makes them race whenever vitest
35+
* runs the files in parallel.
3636
*
3737
* Installed packages are linked in one by one rather than by symlinking
3838
* `node_modules` wholesale, so that the caches tooling writes underneath it
3939
* (`node_modules/.cache/vite`) belong to a single spec.
4040
*/
41-
exportasyncfunctioncreateDevFixture(name: string): Promise<string>{
42-
constsource=fileURLToPath(newURL('../fixtures/dev',import.meta.url))
41+
asyncfunctioncreateFixture(source: string,name: string): Promise<string>{
4342
consttarget=fileURLToPath(newURL(`../fixtures/.tmp-${name}`,import.meta.url))
4443

4544
awaitrm(target,{recursive: true,force: true})
4645
awaitcp(source,target,{
4746
recursive: true,
48-
filter: entry=>!entry.includes('node_modules')&&!entry.includes(`${sep}.nuxt`),
47+
filter: entry=>!entry.includes('node_modules')&&!entry.includes(`${sep}.nuxt`)&&!entry.includes(`${sep}.output`),
4948
})
49+
5050
constsourceModules=join(source,'node_modules')
5151
consttargetModules=join(target,'node_modules')
5252
awaitmkdir(targetModules,{recursive: true})
@@ -59,3 +59,13 @@ export async function createDevFixture(name: string): Promise<string> {
5959

6060
returntarget
6161
}
62+
63+
/** Copy of the shared `dev` fixture, private to a single spec file. */
64+
exportfunctioncreateDevFixture(name: string): Promise<string>{
65+
returncreateFixture(fileURLToPath(newURL('../fixtures/dev',import.meta.url)),name)
66+
}
67+
68+
/** Copy of the workspace playground, private to a single spec file. */
69+
exportfunctioncreatePlaygroundFixture(name: string): Promise<string>{
70+
returncreateFixture(fileURLToPath(newURL('../../../../playground',import.meta.url)),name)
71+
}

0 commit comments

Comments
 (0)