forked from facebook/create-react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(create-react-app): add integration tests (facebook#10381)
- Loading branch information
1 parent
f1f46c9
commit 4db38c9
Showing
4 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Integration Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
job: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] | ||
node: ['10', '12', '14'] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: Cache dependencies | ||
id: cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
node_modules | ||
*/*/node_modules | ||
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', './yarn.lock') }} | ||
- name: Install packages | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: yarn --frozen-lockfile --prefer-offline | ||
- name: Run integration tests | ||
run: yarn test:integration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
'use strict'; | ||
|
||
const execa = require('execa'); | ||
const { mkdirp, remove, writeFileSync } = require('fs-extra'); | ||
const { join } = require('path'); | ||
|
||
const cli = require.resolve('create-react-app/index.js'); | ||
|
||
jest.setTimeout(1000 * 60 * 5); | ||
|
||
const projectName = 'test-app'; | ||
const genPath = join(__dirname, projectName); | ||
|
||
const generatedFiles = ['.gitignore', 'package.json', 'src', 'yarn.lock']; | ||
|
||
beforeEach(() => remove(genPath)); | ||
afterAll(() => remove(genPath)); | ||
|
||
const run = (args, options) => execa('node', [cli].concat(args), options); | ||
|
||
describe('create-react-app', () => { | ||
it('asks to supply an argument if none supplied', async () => { | ||
const { stderr } = await run([], { reject: false }); | ||
expect(stderr).toContain('Please specify the project directory'); | ||
}); | ||
|
||
it('creates a project on supplying a name as the argument', async () => { | ||
await run([projectName], { cwd: __dirname }); | ||
|
||
// Assert for the generated files | ||
generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy()); | ||
}); | ||
|
||
it('warns about conflicting files in path', async () => { | ||
// Create the temporary directory | ||
await mkdirp(genPath); | ||
|
||
// Create a package.json file | ||
const pkgJson = join(genPath, 'package.json'); | ||
writeFileSync(pkgJson, '{ "foo": "bar" }'); | ||
|
||
const { stdout } = await run([projectName], { | ||
cwd: __dirname, | ||
reject: false, | ||
}); | ||
|
||
// Assert for the expected message | ||
expect(stdout).toContain( | ||
`The directory ${projectName} contains files that could conflict` | ||
); | ||
}); | ||
|
||
it('creates a project in the current directory', async () => { | ||
// Create temporary directory | ||
await mkdirp(genPath); | ||
|
||
// Create a project in the current directory | ||
await run(['.'], { cwd: genPath }); | ||
|
||
// Assert for the generated files | ||
generatedFiles.forEach(file => expect(join(genPath, file)).toBeTruthy()); | ||
}); | ||
|
||
it('uses npm as the package manager', async () => { | ||
await run([projectName, '--use-npm'], { | ||
cwd: __dirname, | ||
}); | ||
|
||
// Assert for the generated files | ||
const generatedFilesWithNpm = [ | ||
...generatedFiles.filter(file => file !== 'yarn.lock'), | ||
'package-lock.json', | ||
]; | ||
|
||
generatedFilesWithNpm.forEach(file => | ||
expect(join(genPath, file)).toBeTruthy() | ||
); | ||
}); | ||
|
||
it('creates a project based on the typescript template', async () => { | ||
await run([projectName, '--template', 'typescript'], { | ||
cwd: __dirname, | ||
}); | ||
|
||
// Assert for the generated files | ||
[...generatedFiles, 'tsconfig.json'].forEach(file => | ||
expect(join(genPath, file)).toBeTruthy() | ||
); | ||
}); | ||
}); |