Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
'use strict';
const execa = require('execa');
const { mkdirp, writeFileSync, existsSync, readdirSync } = require('fs-extra');
const { join } = require('path');
const { rmSync } = require('fs');
const cli = require.resolve('create-react-app/index.js');
// Increase the timeout for GitHub macOS runner
jest.setTimeout(1000 * 60 * (process.env.RUNNER_OS === 'macOS' ? 10 : 5));
const projectName = 'test-app';
const genPath = join(__dirname, projectName);
const generatedFiles = [
'.gitignore',
'README.md',
'node_modules',
'package.json',
'public',
'src',
'package-lock.json',
];
const removeGenPath = () => {
rmSync(genPath, {
recursive: true,
force: true,
});
};
beforeEach(removeGenPath);
afterAll(async () => {
removeGenPath();
// Defer jest result output waiting for stdout to flush
await new Promise(resolve => setTimeout(resolve, 100));
});
const run = async (args, options) => {
process.stdout.write(
::group::Test "${ expect.getState().currentTestName }" - "create-react-app ${args.join(' ')}" output:\n
);
const result = execa('node', [cli].concat(args), options);
result.stdout.on('data', chunk =>
process.stdout.write(chunk.toString('utf8'))
);
const childProcessResult = await result;
process.stdout.write(
ExitCode: ${childProcessResult.exitCode}\n
);process.stdout.write('::endgroup::\n');
const files = existsSync(genPath)
? readdirSync(genPath).filter(f => existsSync(join(genPath, f)))
: null;
return {
...childProcessResult,
files,
};
};
const expectAllFiles = (arr1, arr2) =>
expect([...arr1].sort()).toEqual([...arr2].sort());
describe('create-react-app', () => {
it('check yarn installation', async () => {
const { exitCode } = await execa('yarn', ['--version']);
});
it('asks to supply an argument if none supplied', async () => {
const { exitCode, stderr, files } = await run([], { reject: false });
});
it('creates a project on supplying a name as the argument', async () => {
const { exitCode, files } = await run([projectName], { cwd: __dirname });
});
it('warns about conflicting files in path', async () => {
// Create the temporary directory
await mkdirp(genPath);
});
it('creates a project in the current directory', async () => {
// Create temporary directory
await mkdirp(genPath);
});
it('uses yarn as the package manager', async () => {
const { exitCode, files } = await run([projectName], {
cwd: __dirname,
env: { npm_config_user_agent: 'yarn' },
});
});
it('creates a project based on the typescript template', async () => {
const { exitCode, files } = await run(
[projectName, '--template', 'typescript'],
{
cwd: __dirname,
}
);
});
});