@@ -20,12 +20,18 @@ const run = (args, options) => execa('node', [cli].concat(args), options);
20
20
21
21
describe ( 'create-react-app' , ( ) => {
22
22
it ( 'asks to supply an argument if none supplied' , async ( ) => {
23
- const { stderr } = await run ( [ ] , { reject : false } ) ;
23
+ const { code, stderr } = await run ( [ ] , { reject : false } ) ;
24
+
25
+ // Assertions
26
+ expect ( code ) . toBe ( 1 ) ;
24
27
expect ( stderr ) . toContain ( 'Please specify the project directory' ) ;
25
28
} ) ;
26
29
27
30
it ( 'creates a project on supplying a name as the argument' , async ( ) => {
28
- await run ( [ projectName ] , { cwd : __dirname } ) ;
31
+ const { code } = await run ( [ projectName ] , { cwd : __dirname } ) ;
32
+
33
+ // Assert for exit code
34
+ expect ( code ) . toBe ( 0 ) ;
29
35
30
36
// Assert for the generated files
31
37
generatedFiles . forEach ( file => expect ( join ( genPath , file ) ) . toBeTruthy ( ) ) ;
@@ -39,11 +45,14 @@ describe('create-react-app', () => {
39
45
const pkgJson = join ( genPath , 'package.json' ) ;
40
46
writeFileSync ( pkgJson , '{ "foo": "bar" }' ) ;
41
47
42
- const { stdout } = await run ( [ projectName ] , {
48
+ const { code , stdout } = await run ( [ projectName ] , {
43
49
cwd : __dirname ,
44
50
reject : false ,
45
51
} ) ;
46
52
53
+ // Assert for exit code
54
+ expect ( code ) . toBe ( 1 ) ;
55
+
47
56
// Assert for the expected message
48
57
expect ( stdout ) . toContain (
49
58
`The directory ${ projectName } contains files that could conflict`
@@ -55,17 +64,23 @@ describe('create-react-app', () => {
55
64
await mkdirp ( genPath ) ;
56
65
57
66
// Create a project in the current directory
58
- await run ( [ '.' ] , { cwd : genPath } ) ;
67
+ const { code } = await run ( [ '.' ] , { cwd : genPath } ) ;
68
+
69
+ // Assert for exit code
70
+ expect ( code ) . toBe ( 0 ) ;
59
71
60
72
// Assert for the generated files
61
73
generatedFiles . forEach ( file => expect ( join ( genPath , file ) ) . toBeTruthy ( ) ) ;
62
74
} ) ;
63
75
64
76
it ( 'uses npm as the package manager' , async ( ) => {
65
- await run ( [ projectName , '--use-npm' ] , {
77
+ const { code } = await run ( [ projectName , '--use-npm' ] , {
66
78
cwd : __dirname ,
67
79
} ) ;
68
80
81
+ // Assert for exit code
82
+ expect ( code ) . toBe ( 0 ) ;
83
+
69
84
// Assert for the generated files
70
85
const generatedFilesWithNpm = [
71
86
...generatedFiles . filter ( file => file !== 'yarn.lock' ) ,
@@ -78,10 +93,13 @@ describe('create-react-app', () => {
78
93
} ) ;
79
94
80
95
it ( 'creates a project based on the typescript template' , async ( ) => {
81
- await run ( [ projectName , '--template' , 'typescript' ] , {
96
+ const { code } = await run ( [ projectName , '--template' , 'typescript' ] , {
82
97
cwd : __dirname ,
83
98
} ) ;
84
99
100
+ // Assert for exit code
101
+ expect ( code ) . toBe ( 0 ) ;
102
+
85
103
// Assert for the generated files
86
104
[ ...generatedFiles , 'tsconfig.json' ] . forEach ( file =>
87
105
expect ( join ( genPath , file ) ) . toBeTruthy ( )
0 commit comments