Skip to content

Commit dbbccd9

Browse files
test(create-react-app): assert for exit code
1 parent 93241a0 commit dbbccd9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

test/integration/create-react-app/index.test.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ const run = (args, options) => execa('node', [cli].concat(args), options);
2020

2121
describe('create-react-app', () => {
2222
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);
2427
expect(stderr).toContain('Please specify the project directory');
2528
});
2629

2730
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);
2935

3036
// Assert for the generated files
3137
generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy());
@@ -39,11 +45,14 @@ describe('create-react-app', () => {
3945
const pkgJson = join(genPath, 'package.json');
4046
writeFileSync(pkgJson, '{ "foo": "bar" }');
4147

42-
const { stdout } = await run([projectName], {
48+
const { code, stdout } = await run([projectName], {
4349
cwd: __dirname,
4450
reject: false,
4551
});
4652

53+
// Assert for exit code
54+
expect(code).toBe(1);
55+
4756
// Assert for the expected message
4857
expect(stdout).toContain(
4958
`The directory ${projectName} contains files that could conflict`
@@ -55,17 +64,23 @@ describe('create-react-app', () => {
5564
await mkdirp(genPath);
5665

5766
// 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);
5971

6072
// Assert for the generated files
6173
generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy());
6274
});
6375

6476
it('uses npm as the package manager', async () => {
65-
await run([projectName, '--use-npm'], {
77+
const { code } = await run([projectName, '--use-npm'], {
6678
cwd: __dirname,
6779
});
6880

81+
// Assert for exit code
82+
expect(code).toBe(0);
83+
6984
// Assert for the generated files
7085
const generatedFilesWithNpm = [
7186
...generatedFiles.filter(file => file !== 'yarn.lock'),
@@ -78,10 +93,13 @@ describe('create-react-app', () => {
7893
});
7994

8095
it('creates a project based on the typescript template', async () => {
81-
await run([projectName, '--template', 'typescript'], {
96+
const { code } = await run([projectName, '--template', 'typescript'], {
8297
cwd: __dirname,
8398
});
8499

100+
// Assert for exit code
101+
expect(code).toBe(0);
102+
85103
// Assert for the generated files
86104
[...generatedFiles, 'tsconfig.json'].forEach(file =>
87105
expect(join(genPath, file)).toBeTruthy()

0 commit comments

Comments
 (0)