Skip to content

Commit 7c319a3

Browse files
chore: add integration tests
1 parent 9722ef1 commit 7c319a3

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"browser": true,
55
"commonjs": true,
66
"node": true,
7-
"es6": true
7+
"es6": true,
8+
"jest": true
89
},
910
"parserOptions": {
1011
"ecmaVersion": 2018

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"screencast": "node ./tasks/screencast.js",
1616
"screencast:error": "svg-term --cast jyu19xGl88FQ3poMY8Hbmfw8y --out screencast-error.svg --window --at 12000 --no-cursor",
1717
"alex": "alex .",
18+
"test:integration": "jest test/integration",
1819
"test": "cd packages/react-scripts && node bin/react-scripts.js test",
1920
"format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'",
2021
"compile:lockfile": "node tasks/compile-lockfile.js"

test/integration/index.test.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'use strict';
2+
3+
const execa = require('execa');
4+
const { mkdirp, remove, writeFileSync } = require('fs-extra');
5+
const { join } = require('path');
6+
7+
const cli = require.resolve('create-react-app/index.js');
8+
9+
jest.setTimeout(1000 * 60 * 5);
10+
11+
const projectName = 'test-app';
12+
const genPath = join(__dirname, projectName);
13+
14+
const generatedFiles = ['.gitignore', 'package.json', 'src', 'yarn.lock'];
15+
16+
beforeEach(() => remove(genPath));
17+
afterEach(() => remove(genPath));
18+
19+
const run = (args, options) => execa('node', [cli].concat(args), options);
20+
21+
describe('create-react-app', () => {
22+
it('asks to supply an argument if none supplied', async () => {
23+
const { stderr } = await run([], { reject: false });
24+
expect(stderr).toContain('Please specify the project directory');
25+
});
26+
27+
it('creates a project on supplying a name as the argument', async () => {
28+
await run([projectName], { cwd: __dirname });
29+
30+
// Assert for the generated files
31+
generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy());
32+
});
33+
34+
it('warns about conflicting files in path', async () => {
35+
// Create the temporary directory
36+
await mkdirp(genPath);
37+
38+
// Create a package.json file
39+
const pkgJson = join(genPath, 'package.json');
40+
writeFileSync(pkgJson, '{ "foo": "bar" }');
41+
42+
const { stdout } = await run([projectName], {
43+
cwd: __dirname,
44+
reject: false,
45+
});
46+
47+
// Assert for the expected message
48+
expect(stdout).toContain(
49+
`The directory ${projectName} contains files that could conflict`
50+
);
51+
});
52+
53+
it('creates a project in the current directory', async () => {
54+
// Create temporary directory
55+
await mkdirp(genPath);
56+
57+
// Create a project in the current directory
58+
await run(['.'], { cwd: genPath });
59+
60+
// Assert for the generated files
61+
generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy());
62+
});
63+
64+
it('uses npm as the package manager', async () => {
65+
await run([projectName, '--use-npm'], {
66+
cwd: __dirname,
67+
stdio: 'inherit',
68+
});
69+
70+
// Assert for the generated files
71+
const generatedFilesWithNpm = [
72+
...generatedFiles.filter(file => file !== 'yarn.lock'),
73+
'package-lock.json',
74+
];
75+
76+
generatedFilesWithNpm.forEach(file =>
77+
expect(join(genPath, file)).toBeTruthy()
78+
);
79+
});
80+
81+
it('creates a project in the current based on the typescript template', async () => {
82+
await run([projectName, '--template', 'typescript'], {
83+
cwd: __dirname,
84+
stdio: 'inherit',
85+
});
86+
87+
// Assert for the generated files
88+
[...generatedFiles, 'tsconfig.json'].forEach(file =>
89+
expect(join(genPath, file)).toBeTruthy()
90+
);
91+
});
92+
});

0 commit comments

Comments
 (0)