From bb7899b6164bdecdebbdd29e1d213b45391514ff Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 14 Jan 2021 13:29:56 +0530 Subject: [PATCH 1/5] chore: add integration tests --- .eslintrc.json | 3 +- package.json | 1 + test/integration/index.test.js | 92 ++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/integration/index.test.js diff --git a/.eslintrc.json b/.eslintrc.json index b642bbc5c14..40029410cce 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,8 @@ "browser": true, "commonjs": true, "node": true, - "es6": true + "es6": true, + "jest": true }, "parserOptions": { "ecmaVersion": 2018 diff --git a/package.json b/package.json index e7eaac5d085..a5c093bf32e 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "screencast": "node ./tasks/screencast.js", "screencast:error": "svg-term --cast jyu19xGl88FQ3poMY8Hbmfw8y --out screencast-error.svg --window --at 12000 --no-cursor", "alex": "alex .", + "test:integration": "jest test/integration", "test": "cd packages/react-scripts && node bin/react-scripts.js test", "format": "prettier --write 'packages/*/*.js' 'packages/*/!(node_modules)/**/*.js'", "compile:lockfile": "node tasks/compile-lockfile.js" diff --git a/test/integration/index.test.js b/test/integration/index.test.js new file mode 100644 index 00000000000..b9bc8206bea --- /dev/null +++ b/test/integration/index.test.js @@ -0,0 +1,92 @@ +'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)); +afterEach(() => 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, + stdio: 'inherit', + }); + + // 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 in the current based on the typescript template', async () => { + await run([projectName, '--template', 'typescript'], { + cwd: __dirname, + stdio: 'inherit', + }); + + // Assert for the generated files + [...generatedFiles, 'tsconfig.json'].forEach(file => + expect(join(genPath, file)).toBeTruthy() + ); + }); +}); From 32e539e26dc9b5f6854d2abb38ccecc9f4a365d4 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 14 Jan 2021 13:38:00 +0530 Subject: [PATCH 2/5] ci: new job for integration tests --- .github/workflows/test.yml | 27 +++++++++++++++++++++++++++ test/integration/index.test.js | 2 -- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000000..5f1b76aa52a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +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: Install packages + run: yarn --no-progress --non-interactive --no-lockfile + - name: Run integration tests + run: yarn test:integration diff --git a/test/integration/index.test.js b/test/integration/index.test.js index b9bc8206bea..5cd123c25b0 100644 --- a/test/integration/index.test.js +++ b/test/integration/index.test.js @@ -64,7 +64,6 @@ describe('create-react-app', () => { it('uses npm as the package manager', async () => { await run([projectName, '--use-npm'], { cwd: __dirname, - stdio: 'inherit', }); // Assert for the generated files @@ -81,7 +80,6 @@ describe('create-react-app', () => { it('creates a project in the current based on the typescript template', async () => { await run([projectName, '--template', 'typescript'], { cwd: __dirname, - stdio: 'inherit', }); // Assert for the generated files From aa69646c7a1236a822709bdaf6236be080383e97 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 15 Jan 2021 23:06:24 +0530 Subject: [PATCH 3/5] ci: cache deps --- .github/workflows/test.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f1b76aa52a..1249f20532f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,16 @@ jobs: 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 - run: yarn --no-progress --non-interactive --no-lockfile + if: steps.cache.outputs.cache-hit != 'true' + run: yarn --frozen-lockfile --prefer-offline - name: Run integration tests run: yarn test:integration From d9d30b294b7871ae3bce7c56c3fa3230fa4cdf83 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 20 Apr 2021 12:29:19 +0530 Subject: [PATCH 4/5] test: improve test suite --- test/integration/{ => create-react-app}/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename test/integration/{ => create-react-app}/index.test.js (95%) diff --git a/test/integration/index.test.js b/test/integration/create-react-app/index.test.js similarity index 95% rename from test/integration/index.test.js rename to test/integration/create-react-app/index.test.js index 5cd123c25b0..875fd8ca348 100644 --- a/test/integration/index.test.js +++ b/test/integration/create-react-app/index.test.js @@ -14,7 +14,7 @@ const genPath = join(__dirname, projectName); const generatedFiles = ['.gitignore', 'package.json', 'src', 'yarn.lock']; beforeEach(() => remove(genPath)); -afterEach(() => remove(genPath)); +afterAll(() => remove(genPath)); const run = (args, options) => execa('node', [cli].concat(args), options); @@ -77,7 +77,7 @@ describe('create-react-app', () => { ); }); - it('creates a project in the current based on the typescript template', async () => { + it('creates a project based on the typescript template', async () => { await run([projectName, '--template', 'typescript'], { cwd: __dirname, }); From 760939014bc748e50496a7dc8219af2836ef3d6f Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 12 May 2021 22:06:56 +0530 Subject: [PATCH 5/5] ci: rename config file --- .github/workflows/{test.yml => integration.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{test.yml => integration.yml} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/integration.yml similarity index 100% rename from .github/workflows/test.yml rename to .github/workflows/integration.yml