@@ -8,6 +8,7 @@ import { test, expect } from 'vitest';
8
8
const pkg = require ( '../package.json' ) ;
9
9
10
10
const SCRIPT_PATH = resolve ( __dirname , '..' , pkg . bin [ 'create-create-app' ] ) ;
11
+ const FIXTURE_PATH = join ( __dirname , 'fixtures' ) ;
11
12
const TMP_PREFIX = join ( tmpdir ( ) , 'create-create-app-' ) ;
12
13
13
14
const DEFAULT_ANSWERS = [
@@ -19,22 +20,31 @@ const DEFAULT_ANSWERS = [
19
20
20
21
] ;
21
22
22
- test ( 'show usage' , async ( ) => {
23
- const { stdout } = await execa ( SCRIPT_PATH , [ ] ) ;
24
- expect ( stdout ) . toBe ( 'create-create-app <name>' ) ;
25
- } , 300000 ) ;
26
-
27
- test ( 'template' , async ( ) => {
23
+ async function useFixture ( projectName : string , opts : readonly string [ ] ) {
28
24
const tmpDir = mkdtempSync ( TMP_PREFIX ) ;
29
- const projectPath = './tests/fixtures/create-test' ;
25
+ const projectPath = join ( FIXTURE_PATH , projectName ) ;
30
26
const cliPath = resolve ( join ( projectPath , 'src/cli.js' ) ) ;
31
27
32
28
await execa ( 'yarn' , [ 'install' ] , {
33
29
cwd : projectPath ,
34
30
} ) ;
35
31
32
+ const { stdout } = await execa ( 'node' , [ cliPath , ...opts ] , {
33
+ cwd : tmpDir ,
34
+ } ) ;
35
+
36
+ return { stdout, tmpDir } ;
37
+ }
38
+
39
+ // Tests
40
+
41
+ test ( 'show usage' , async ( ) => {
42
+ const { stdout } = await execa ( SCRIPT_PATH , [ ] ) ;
43
+ expect ( stdout ) . toBe ( 'create-create-app <name>' ) ;
44
+ } , 300000 ) ;
45
+
46
+ test ( 'template' , async ( ) => {
36
47
const opts = [
37
- cliPath ,
38
48
'test' ,
39
49
...DEFAULT_ANSWERS ,
40
50
'--template' ,
@@ -45,9 +55,7 @@ test('template', async () => {
45
55
'macOS' ,
46
56
] ;
47
57
48
- const { stdout } = await execa ( 'node' , opts , {
49
- cwd : tmpDir ,
50
- } ) ;
58
+ const { stdout, tmpDir } = await useFixture ( 'create-test' , opts ) ;
51
59
52
60
expect ( readdirSync ( join ( tmpDir , 'test' ) ) ) . toEqual (
53
61
expect . arrayContaining ( [
@@ -217,16 +225,7 @@ test('create unlicensed app', async () => {
217
225
} , 300000 ) ;
218
226
219
227
test ( 'should create project with minimal footprint' , async ( ) => {
220
- const tmpDir = mkdtempSync ( TMP_PREFIX ) ;
221
- const projectPath = './tests/fixtures/create-test' ;
222
- const cliPath = resolve ( join ( projectPath , 'src/cli.js' ) ) ;
223
-
224
- await execa ( 'yarn' , [ 'install' ] , {
225
- cwd : projectPath ,
226
- } ) ;
227
-
228
228
const opts = [
229
- cliPath ,
230
229
'test' ,
231
230
...DEFAULT_ANSWERS ,
232
231
'--license' ,
@@ -239,29 +238,15 @@ test('should create project with minimal footprint', async () => {
239
238
'--skip-git' ,
240
239
] ;
241
240
242
- await execa ( 'node' , opts , {
243
- cwd : tmpDir ,
244
- } ) ;
241
+ const { tmpDir } = await useFixture ( 'create-test' , opts ) ;
245
242
246
243
expect ( existsSync ( `${ tmpDir } /test/LICENSE` ) ) . toBeFalsy ( ) ;
247
244
expect ( existsSync ( `${ tmpDir } /test/node_modules` ) ) . toBeFalsy ( ) ;
248
245
expect ( existsSync ( `${ tmpDir } /test/.git` ) ) . toBeFalsy ( ) ;
249
246
} , 300000 ) ;
250
247
251
248
test ( 'should create project with minimal questions' , async ( ) => {
252
- const tmpDir = mkdtempSync ( TMP_PREFIX ) ;
253
- const projectPath = './tests/fixtures/minimal' ;
254
- const cliPath = resolve ( join ( projectPath , 'src/cli.js' ) ) ;
255
-
256
- await execa ( 'yarn' , [ 'install' ] , {
257
- cwd : projectPath ,
258
- } ) ;
259
-
260
- const opts = [ cliPath , 'test' ] ;
261
-
262
- await execa ( 'node' , opts , {
263
- cwd : tmpDir ,
264
- } ) ;
249
+ const { tmpDir } = await useFixture ( 'minimal' , [ 'test' ] ) ;
265
250
266
251
expect ( existsSync ( `${ tmpDir } /test/.git` ) ) . toBeFalsy ( ) ;
267
252
expect ( existsSync ( `${ tmpDir } /test/yarn.lock` ) ) . toBeTruthy ( ) ;
0 commit comments