Skip to content

Commit

Permalink
test(create-react-app): assert for exit code (facebook#10973)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 authored and abhiisheek committed May 24, 2023
1 parent d44e4bf commit 14a5835
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 @@ -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());
Expand All @@ -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`
Expand All @@ -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'),
Expand All @@ -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()
Expand Down

0 comments on commit 14a5835

Please sign in to comment.