@@ -8,6 +8,7 @@ import { test, expect } from 'vitest';
88const pkg = require ( '../package.json' ) ;
99
1010const SCRIPT_PATH = resolve ( __dirname , '..' , pkg . bin [ 'create-create-app' ] ) ;
11+ const FIXTURE_PATH = join ( __dirname , 'fixtures' ) ;
1112const TMP_PREFIX = join ( tmpdir ( ) , 'create-create-app-' ) ;
1213
1314const DEFAULT_ANSWERS = [
@@ -19,22 +20,31 @@ const DEFAULT_ANSWERS = [
1920 'awesome@example.com' ,
2021] ;
2122
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 [ ] ) {
2824 const tmpDir = mkdtempSync ( TMP_PREFIX ) ;
29- const projectPath = './tests/fixtures/create-test' ;
25+ const projectPath = join ( FIXTURE_PATH , projectName ) ;
3026 const cliPath = resolve ( join ( projectPath , 'src/cli.js' ) ) ;
3127
3228 await execa ( 'yarn' , [ 'install' ] , {
3329 cwd : projectPath ,
3430 } ) ;
3531
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 ( ) => {
3647 const opts = [
37- cliPath ,
3848 'test' ,
3949 ...DEFAULT_ANSWERS ,
4050 '--template' ,
@@ -45,9 +55,7 @@ test('template', async () => {
4555 'macOS' ,
4656 ] ;
4757
48- const { stdout } = await execa ( 'node' , opts , {
49- cwd : tmpDir ,
50- } ) ;
58+ const { stdout, tmpDir } = await useFixture ( 'create-test' , opts ) ;
5159
5260 expect ( readdirSync ( join ( tmpDir , 'test' ) ) ) . toEqual (
5361 expect . arrayContaining ( [
@@ -217,16 +225,7 @@ test('create unlicensed app', async () => {
217225} , 300000 ) ;
218226
219227test ( '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-
228228 const opts = [
229- cliPath ,
230229 'test' ,
231230 ...DEFAULT_ANSWERS ,
232231 '--license' ,
@@ -239,29 +238,15 @@ test('should create project with minimal footprint', async () => {
239238 '--skip-git' ,
240239 ] ;
241240
242- await execa ( 'node' , opts , {
243- cwd : tmpDir ,
244- } ) ;
241+ const { tmpDir } = await useFixture ( 'create-test' , opts ) ;
245242
246243 expect ( existsSync ( `${ tmpDir } /test/LICENSE` ) ) . toBeFalsy ( ) ;
247244 expect ( existsSync ( `${ tmpDir } /test/node_modules` ) ) . toBeFalsy ( ) ;
248245 expect ( existsSync ( `${ tmpDir } /test/.git` ) ) . toBeFalsy ( ) ;
249246} , 300000 ) ;
250247
251248test ( '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' ] ) ;
265250
266251 expect ( existsSync ( `${ tmpDir } /test/.git` ) ) . toBeFalsy ( ) ;
267252 expect ( existsSync ( `${ tmpDir } /test/yarn.lock` ) ) . toBeTruthy ( ) ;
0 commit comments