Skip to content

Commit ca80708

Browse files
committed
chore(test): increase timeout and check all files in intergration test
1 parent f559dd0 commit ca80708

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
'use strict';
22

33
const execa = require('execa');
4-
const { mkdirp, writeFileSync, existsSync } = require('fs-extra');
4+
const { mkdirp, writeFileSync, existsSync, readdirSync } = require('fs-extra');
55
const { join } = require('path');
66
const { rmSync } = require('fs');
77

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

10-
jest.setTimeout(1000 * 60 * 5);
10+
jest.setTimeout(1000 * 60 * 10);
1111

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

1515
const generatedFiles = [
1616
'.gitignore',
17+
'README.md',
18+
'node_modules',
1719
'package.json',
20+
'public',
1821
'src',
1922
'package-lock.json',
2023
];
@@ -46,10 +49,17 @@ const run = async (args, options) => {
4649
const childProcessResult = await result;
4750
process.stdout.write(`ExitCode: ${childProcessResult.exitCode}\n`);
4851
process.stdout.write('::endgroup::\n');
49-
return childProcessResult;
52+
const files = existsSync(genPath)
53+
? readdirSync(genPath).filter(f => existsSync(join(genPath, f)))
54+
: null;
55+
return {
56+
...childProcessResult,
57+
files,
58+
};
5059
};
5160

52-
const genFileExists = f => existsSync(join(genPath, f));
61+
const expectAllFiles = (arr1, arr2) =>
62+
expect([...arr1].sort()).toEqual([...arr2].sort());
5363

5464
describe('create-react-app', () => {
5565
it('check yarn installation', async () => {
@@ -60,21 +70,22 @@ describe('create-react-app', () => {
6070
});
6171

6272
it('asks to supply an argument if none supplied', async () => {
63-
const { exitCode, stderr } = await run([], { reject: false });
73+
const { exitCode, stderr, files } = await run([], { reject: false });
6474

6575
// Assertions
6676
expect(exitCode).toBe(1);
6777
expect(stderr).toContain('Please specify the project directory');
78+
expect(files).toBe(null);
6879
});
6980

7081
it('creates a project on supplying a name as the argument', async () => {
71-
const { exitCode } = await run([projectName], { cwd: __dirname });
82+
const { exitCode, files } = await run([projectName], { cwd: __dirname });
7283

7384
// Assert for exit code
7485
expect(exitCode).toBe(0);
7586

7687
// Assert for the generated files
77-
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
88+
expectAllFiles(files, generatedFiles);
7889
});
7990

8091
it('warns about conflicting files in path', async () => {
@@ -85,7 +96,7 @@ describe('create-react-app', () => {
8596
const pkgJson = join(genPath, 'package.json');
8697
writeFileSync(pkgJson, '{ "foo": "bar" }');
8798

88-
const { exitCode, stdout } = await run([projectName], {
99+
const { exitCode, stdout, files } = await run([projectName], {
89100
cwd: __dirname,
90101
reject: false,
91102
});
@@ -97,57 +108,54 @@ describe('create-react-app', () => {
97108
expect(stdout).toContain(
98109
`The directory ${projectName} contains files that could conflict`
99110
);
111+
112+
// Existing file is still there
113+
expectAllFiles(files, ['package.json']);
100114
});
101115

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

106120
// Create a project in the current directory
107-
const { exitCode } = await run(['.'], { cwd: genPath });
121+
const { exitCode, files } = await run(['.'], { cwd: genPath });
108122

109123
// Assert for exit code
110124
expect(exitCode).toBe(0);
111125

112126
// Assert for the generated files
113-
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
127+
expectAllFiles(files, generatedFiles);
114128
});
115129

116-
it(
117-
'uses yarn as the package manager',
118-
async () => {
119-
const { exitCode } = await run([projectName], {
120-
cwd: __dirname,
121-
env: { npm_config_user_agent: 'yarn' },
122-
});
123-
124-
// Assert for exit code
125-
expect(exitCode).toBe(0);
126-
127-
// Assert for the generated files
128-
const generatedFilesWithYarn = [
129-
...generatedFiles.filter(file => file !== 'package-lock.json'),
130-
'yarn.lock',
131-
];
132-
133-
generatedFilesWithYarn.forEach(file =>
134-
expect(genFileExists(file)).toBeTruthy()
135-
);
136-
},
137-
1000 * 60 * 10
138-
);
139-
140-
it('creates a project based on the typescript template', async () => {
141-
const { exitCode } = await run([projectName, '--template', 'typescript'], {
130+
it('uses yarn as the package manager', async () => {
131+
const { exitCode, files } = await run([projectName], {
142132
cwd: __dirname,
133+
env: { npm_config_user_agent: 'yarn' },
143134
});
144135

145136
// Assert for exit code
146137
expect(exitCode).toBe(0);
147138

148139
// Assert for the generated files
149-
[...generatedFiles, 'tsconfig.json'].forEach(file =>
150-
expect(genFileExists(file)).toBeTruthy()
140+
const generatedFilesWithYarn = generatedFiles.map(file =>
141+
file === 'package-lock.json' ? 'yarn.lock' : file
142+
);
143+
144+
expectAllFiles(files, generatedFilesWithYarn);
145+
});
146+
147+
it('creates a project based on the typescript template', async () => {
148+
const { exitCode, files } = await run(
149+
[projectName, '--template', 'typescript'],
150+
{
151+
cwd: __dirname,
152+
}
151153
);
154+
155+
// Assert for exit code
156+
expect(exitCode).toBe(0);
157+
158+
// Assert for the generated files
159+
expectAllFiles(files, [...generatedFiles, 'tsconfig.json']);
152160
});
153161
});

0 commit comments

Comments
 (0)