Skip to content

Commit

Permalink
test(create-react-app): assert for exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed May 16, 2021
1 parent 7bdeced commit 79cf5b6
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions test/integration/create-react-app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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`
Expand All @@ -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'),
Expand All @@ -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()
Expand Down

0 comments on commit 79cf5b6

Please sign in to comment.