Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(create-react-app): assert for exit code #10973

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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