Skip to content

Commit 7e865fe

Browse files
jamesgeorge007abhiisheek
authored andcommitted
test(create-react-app): add integration tests (facebook#10381)
1 parent 20a630b commit 7e865fe

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed

.eslintrc.json

+2-1
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

.github/workflows/integration.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
job:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
17+
node: ['10', '12', '14']
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Setup node
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node }}
24+
- name: Cache dependencies
25+
id: cache
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
node_modules
30+
*/*/node_modules
31+
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', './yarn.lock') }}
32+
- name: Install packages
33+
if: steps.cache.outputs.cache-hit != 'true'
34+
run: yarn --frozen-lockfile --prefer-offline
35+
- name: Run integration tests
36+
run: yarn test:integration

package.json

+1
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"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
afterAll(() => 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+
});
68+
69+
// Assert for the generated files
70+
const generatedFilesWithNpm = [
71+
...generatedFiles.filter(file => file !== 'yarn.lock'),
72+
'package-lock.json',
73+
];
74+
75+
generatedFilesWithNpm.forEach(file =>
76+
expect(join(genPath, file)).toBeTruthy()
77+
);
78+
});
79+
80+
it('creates a project based on the typescript template', async () => {
81+
await run([projectName, '--template', 'typescript'], {
82+
cwd: __dirname,
83+
});
84+
85+
// Assert for the generated files
86+
[...generatedFiles, 'tsconfig.json'].forEach(file =>
87+
expect(join(genPath, file)).toBeTruthy()
88+
);
89+
});
90+
});

0 commit comments

Comments
 (0)