Skip to content

Commit

Permalink
Showing 5 changed files with 766 additions and 528 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@ jobs:
cache: 'npm'
- name: Install npm@7
run: npm i -g npm@7
- name: Install yarn
run: npm i -g yarn
- name: Install packages
run: npm ci --prefer-offline
- name: Run integration tests
1,175 changes: 687 additions & 488 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
"@testing-library/user-event": "^12.1.10",
"alex": "^8.2.0",
"eslint": "^7.30.0",
"execa": "^1.0.0",
"execa": "^5.1.1",
"fs-extra": "^9.0.1",
"get-port": "^5.1.1",
"globby": "^11.0.1",
12 changes: 6 additions & 6 deletions tasks/screencast-start.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env node

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';
@@ -20,7 +20,7 @@ function main(cli) {

const start = Date.now();
const duration = parseInt(cli.flags.timeout, 10) * 1000;
const cp = execa.shell(cli.flags.command);
const cp = execa(cli.flags.command, { shell: true });

const target = parseInt(cli.flags.patternCount || '1', 10);

@@ -52,7 +52,7 @@ function main(cli) {
}

setTimeout(() => {
process.exit(e.code);
process.exit(e.exitCode);
}, duration - elapsed);
});
}
103 changes: 70 additions & 33 deletions test/integration/create-react-app/index.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const execa = require('execa');
const { mkdirp, remove, writeFileSync, existsSync } = require('fs-extra');
const { mkdirp, writeFileSync, existsSync } = require('fs-extra');
const { join } = require('path');
const { rmSync } = require('fs');

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

@@ -18,27 +19,59 @@ const generatedFiles = [
'package-lock.json',
];

beforeEach(() => remove(genPath));
afterAll(() => remove(genPath));
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 = (args, options) => execa('node', [cli].concat(args), options);
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');
return childProcessResult;
};

const genFileExists = f => existsSync(join(genPath, f));

describe('create-react-app', () => {
it('check yarn installation', async () => {
const { exitCode } = await execa('yarn', ['--version']);

// Assert for exit code
expect(exitCode).toBe(0);
});

it('asks to supply an argument if none supplied', async () => {
const { code, stderr } = await run([], { reject: false });
const { exitCode, stderr } = await run([], { reject: false });

// Assertions
expect(code).toBe(1);
expect(exitCode).toBe(1);
expect(stderr).toContain('Please specify the project directory');
});

it('creates a project on supplying a name as the argument', async () => {
const { code } = await run([projectName], { cwd: __dirname });
const { exitCode } = await run([projectName], { cwd: __dirname });

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

// Assert for the generated files
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
@@ -52,13 +85,13 @@ describe('create-react-app', () => {
const pkgJson = join(genPath, 'package.json');
writeFileSync(pkgJson, '{ "foo": "bar" }');

const { code, stdout } = await run([projectName], {
const { exitCode, stdout } = await run([projectName], {
cwd: __dirname,
reject: false,
});

// Assert for exit code
expect(code).toBe(1);
expect(exitCode).toBe(1);

// Assert for the expected message
expect(stdout).toContain(
@@ -71,42 +104,46 @@ describe('create-react-app', () => {
await mkdirp(genPath);

// Create a project in the current directory
const { code } = await run(['.'], { cwd: genPath });
const { exitCode } = await run(['.'], { cwd: genPath });

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

// Assert for the generated files
generatedFiles.forEach(file => expect(genFileExists(file)).toBeTruthy());
});

it('uses yarn as the package manager', async () => {
const { code } = await run([projectName], {
cwd: __dirname,
env: { npm_config_user_agent: 'yarn' },
});

// Assert for exit code
expect(code).toBe(0);

// Assert for the generated files
const generatedFilesWithYarn = [
...generatedFiles.filter(file => file !== 'package-lock.json'),
'yarn.lock',
];

generatedFilesWithYarn.forEach(file =>
expect(genFileExists(file)).toBeTruthy()
);
});
it(
'uses yarn as the package manager',
async () => {
const { exitCode } = await run([projectName], {
cwd: __dirname,
env: { npm_config_user_agent: 'yarn' },
});

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

// Assert for the generated files
const generatedFilesWithYarn = [
...generatedFiles.filter(file => file !== 'package-lock.json'),
'yarn.lock',
];

generatedFilesWithYarn.forEach(file =>
expect(genFileExists(file)).toBeTruthy()
);
},
1000 * 60 * 10
);

it('creates a project based on the typescript template', async () => {
const { code } = await run([projectName, '--template', 'typescript'], {
const { exitCode } = await run([projectName, '--template', 'typescript'], {
cwd: __dirname,
});

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

// Assert for the generated files
[...generatedFiles, 'tsconfig.json'].forEach(file =>

0 comments on commit e8319da

Please sign in to comment.