Skip to content

Commit 2c35868

Browse files
chore: add integration tests
1 parent a504e9d commit 2c35868

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-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: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 tempDirPath = join(__dirname, projectName);
13+
14+
const generatedFiles = ['.gitignore', 'package.json', 'src', 'yarn.lock'];
15+
16+
beforeEach(() => remove(tempDirPath));
17+
afterEach(() => remove(tempDirPath));
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 =>
32+
expect(join(tempDirPath, file)).toBeTruthy()
33+
);
34+
});
35+
36+
it('warns about conflicting files in path', async () => {
37+
// Create the temporary directory
38+
await mkdirp(tempDirPath);
39+
40+
// Create a package.json file
41+
const pkgJson = join(tempDirPath, 'package.json');
42+
writeFileSync(pkgJson, '{ "foo": "bar" }');
43+
44+
const { stdout } = await run([projectName], {
45+
cwd: __dirname,
46+
reject: false,
47+
});
48+
49+
// Assert for the expected message
50+
expect(stdout).toContain(
51+
`The directory ${projectName} contains files that could conflict`
52+
);
53+
});
54+
55+
it('creates a project in the current directory', async () => {
56+
// Create temporary directory
57+
await mkdirp(tempDirPath);
58+
59+
// Create a project in the current directory
60+
await run(['.'], { cwd: tempDirPath });
61+
62+
// Assert for the generated files
63+
generatedFiles.forEach(file =>
64+
expect(join(tempDirPath, file)).toBeTruthy()
65+
);
66+
});
67+
68+
it('uses npm as the package manager', async () => {
69+
await run([projectName, '--use-npm'], {
70+
cwd: __dirname,
71+
stdio: 'inherit',
72+
});
73+
74+
// Assert for the generated files
75+
const filteredFiles = [
76+
...generatedFiles.filter(file => file !== 'yarn.lock'),
77+
'package-lock.json',
78+
];
79+
80+
filteredFiles.forEach(file => expect(join(tempDirPath, file)).toBeTruthy());
81+
});
82+
83+
it('creates a project in the current based on the typescript template', async () => {
84+
await run([projectName, '--template', 'typescript'], {
85+
cwd: __dirname,
86+
stdio: 'inherit',
87+
});
88+
89+
// Assert for the generated files
90+
[...generatedFiles, 'tsconfig.json'].forEach(file =>
91+
expect(join(tempDirPath, file)).toBeTruthy()
92+
);
93+
});
94+
});

0 commit comments

Comments
 (0)