Skip to content

Commit

Permalink
chore: add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Jan 15, 2021
1 parent a504e9d commit 717ed2c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"browser": true,
"commonjs": true,
"node": true,
"es6": true
"es6": true,
"jest": true
},
"parserOptions": {
"ecmaVersion": 2018
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"screencast": "node ./tasks/screencast.js",
"screencast:error": "svg-term --cast jyu19xGl88FQ3poMY8Hbmfw8y --out screencast-error.svg --window --at 12000 --no-cursor",
"alex": "alex .",
"test:integration": "jest test/integration",
"test": "cd packages/react-scripts && node bin/react-scripts.js test",
"format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'",
"compile:lockfile": "node tasks/compile-lockfile.js"
Expand Down
92 changes: 92 additions & 0 deletions test/integration/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict';

const execa = require('execa');
const { mkdirp, remove, writeFileSync } = require('fs-extra');
const { join } = require('path');

const cli = require.resolve('create-react-app/index.js');

jest.setTimeout(1000 * 60 * 5);

const projectName = 'test-app';
const genPath = join(__dirname, projectName);

const generatedFiles = ['.gitignore', 'package.json', 'src', 'yarn.lock'];

beforeEach(() => remove(genPath));
afterEach(() => remove(genPath));

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 });
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 });

// Assert for the generated files
generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy());
});

it('warns about conflicting files in path', async () => {
// Create the temporary directory
await mkdirp(genPath);

// Create a package.json file
const pkgJson = join(genPath, 'package.json');
writeFileSync(pkgJson, '{ "foo": "bar" }');

const { stdout } = await run([projectName], {
cwd: __dirname,
reject: false,
});

// Assert for the expected message
expect(stdout).toContain(
`The directory ${projectName} contains files that could conflict`
);
});

it('creates a project in the current directory', async () => {
// Create temporary directory
await mkdirp(genPath);

// Create a project in the current directory
await run(['.'], { cwd: genPath });

// 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'], {
cwd: __dirname,
stdio: 'inherit',
});

// Assert for the generated files
const generatedFilesWithNpm = [
...generatedFiles.filter(file => file !== 'yarn.lock'),
'package-lock.json',
];

generatedFilesWithNpm.forEach(file =>
expect(join(genPath, file)).toBeTruthy()
);
});

it('creates a project in the current based on the typescript template', async () => {
await run([projectName, '--template', 'typescript'], {
cwd: __dirname,
stdio: 'inherit',
});

// Assert for the generated files
[...generatedFiles, 'tsconfig.json'].forEach(file =>
expect(join(genPath, file)).toBeTruthy()
);
});
});

0 comments on commit 717ed2c

Please sign in to comment.