From 14a583500f9e6f268328df24d423af229afba70b Mon Sep 17 00:00:00 2001 From: James George Date: Tue, 12 Oct 2021 13:59:58 +0530 Subject: [PATCH] test(create-react-app): assert for exit code (#10973) --- .../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 f18d791ee3e..f819e9b95bb 100644 --- a/test/integration/create-react-app/index.test.js +++ b/test/integration/create-react-app/index.test.js @@ -27,12 +27,18 @@ const genFileExists = f => existsSync(join(genPath, f)); 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(genFileExists(file)).toBeTruthy()); @@ -46,11 +52,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` @@ -62,18 +71,24 @@ 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(genFileExists(file)).toBeTruthy()); }); it('uses yarn as the package manager', async () => { - await run([projectName], { + const { code } = await run([projectName], { cwd: __dirname, env: { npm_config_user_agent: 'yarn' }, }); + // Assert for exit code + expect(code).toBe(0); + // Assert for the generated files const generatedFilesWithYarn = [ ...generatedFiles.filter(file => file !== 'package-lock.json'), @@ -86,10 +101,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(genFileExists(file)).toBeTruthy()