From 79cf5b61c217c9ef24e10b2387baf20bb2fbccb7 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Mon, 17 May 2021 00:42:18 +0530 Subject: [PATCH] test(create-react-app): assert for exit code --- .../create-react-app/index.test.js | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/test/integration/create-react-app/index.test.js b/test/integration/create-react-app/index.test.js index 875fd8ca348..8753c01c8aa 100644 --- a/test/integration/create-react-app/index.test.js +++ b/test/integration/create-react-app/index.test.js @@ -20,12 +20,18 @@ const run = (args, options) => execa('node', [cli].concat(args), options); describe('create-react-app', () => { it('asks to supply an argument if none supplied', async () => { - const { stderr } = await run([], { reject: false }); + const { code, stderr } = await run([], { reject: false }); + + // Assertions + expect(code).toBe(1); expect(stderr).toContain('Please specify the project directory'); }); it('creates a project on supplying a name as the argument', async () => { - await run([projectName], { cwd: __dirname }); + const { code } = await run([projectName], { cwd: __dirname }); + + // Assert for exit code + expect(code).toBe(0); // Assert for the generated files generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy()); @@ -39,11 +45,14 @@ describe('create-react-app', () => { const pkgJson = join(genPath, 'package.json'); writeFileSync(pkgJson, '{ "foo": "bar" }'); - const { stdout } = await run([projectName], { + const { code, stdout } = await run([projectName], { cwd: __dirname, reject: false, }); + // Assert for exit code + expect(code).toBe(1); + // Assert for the expected message expect(stdout).toContain( `The directory ${projectName} contains files that could conflict` @@ -55,17 +64,23 @@ describe('create-react-app', () => { await mkdirp(genPath); // Create a project in the current directory - await run(['.'], { cwd: genPath }); + const { code } = await run(['.'], { cwd: genPath }); + + // Assert for exit code + expect(code).toBe(0); // Assert for the generated files generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy()); }); it('uses npm as the package manager', async () => { - await run([projectName, '--use-npm'], { + const { code } = await run([projectName, '--use-npm'], { cwd: __dirname, }); + // Assert for exit code + expect(code).toBe(0); + // Assert for the generated files const generatedFilesWithNpm = [ ...generatedFiles.filter(file => file !== 'yarn.lock'), @@ -78,10 +93,13 @@ describe('create-react-app', () => { }); it('creates a project based on the typescript template', async () => { - await run([projectName, '--template', 'typescript'], { + const { code } = await run([projectName, '--template', 'typescript'], { cwd: __dirname, }); + // Assert for exit code + expect(code).toBe(0); + // Assert for the generated files [...generatedFiles, 'tsconfig.json'].forEach(file => expect(join(genPath, file)).toBeTruthy()