From a14e990ebf15be6fa3ef46ede6f4ba6411c6aa36 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Tue, 7 Dec 2021 09:20:49 -0700 Subject: [PATCH] chore(test): make all tests install with `npm ci` Previously, individual tests were updating `npm` and running `npm install`, which was redundant with the config in the test runner. This also updates all test runners to `npm@8` and fixes the local Docker test runner, which wasn't working previously. --- .github/workflows/build.yml | 4 ++-- .github/workflows/integration.yml | 4 ++-- .github/workflows/lint.yml | 4 ++-- azure-pipelines-test-job.yml | 4 ++-- tasks/e2e-behavior.sh | 8 -------- tasks/e2e-installs.sh | 8 -------- tasks/e2e-kitchensink-eject.sh | 8 -------- tasks/e2e-kitchensink.sh | 8 -------- tasks/e2e-simple.sh | 22 +++++++--------------- tasks/local-test.sh | 28 +++++++++++++++------------- tasks/publish.sh | 1 + 11 files changed, 31 insertions(+), 68 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e70e13cb520..3ebb67c48e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,8 +11,8 @@ jobs: with: node-version: '14' cache: 'npm' - - name: Install npm@7 - run: npm i -g npm@7 + - name: Install npm@8 + run: npm i -g npm@8 - name: Install run: npm ci --prefer-offline - name: Build diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 66e9dd59dc9..88699dfa278 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -22,8 +22,8 @@ jobs: with: node-version: ${{ matrix.node }} cache: 'npm' - - name: Install npm@7 - run: npm i -g npm@7 + - name: Install npm@8 + run: npm i -g npm@8 - name: Install yarn run: npm i -g yarn - name: Install packages diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ba82da56f35..d9835010a9c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,8 +11,8 @@ jobs: with: node-version: '14' cache: 'npm' - - name: Install npm@7 - run: npm i -g npm@7 + - name: Install npm@8 + run: npm i -g npm@8 - name: Install run: npm ci --prefer-offline - name: Alex diff --git a/azure-pipelines-test-job.yml b/azure-pipelines-test-job.yml index fb3ce4eff9c..cdf3f4dacfd 100644 --- a/azure-pipelines-test-job.yml +++ b/azure-pipelines-test-job.yml @@ -31,8 +31,8 @@ jobs: versionSpec: $(nodeVersion) displayName: 'Install Node.js' - - script: npm i -g npm@7 - displayName: 'Update npm to v7' + - script: npm i -g npm@8 + displayName: 'Update npm to v8' - script: npm ci displayName: 'Run npm ci' diff --git a/tasks/e2e-behavior.sh b/tasks/e2e-behavior.sh index 2619ed5aa08..79059fdf94e 100755 --- a/tasks/e2e-behavior.sh +++ b/tasks/e2e-behavior.sh @@ -61,14 +61,6 @@ set -x cd .. root_path=$PWD -if hash npm 2>/dev/null -then - npm i -g --force npm@latest -fi - -# Bootstrap monorepo -npm install - # ****************************************************************************** # First, publish the monorepo. # ****************************************************************************** diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh index 5736507318d..92407134a65 100755 --- a/tasks/e2e-installs.sh +++ b/tasks/e2e-installs.sh @@ -83,14 +83,6 @@ set -x cd .. root_path=$PWD -if hash npm 2>/dev/null -then - npm i -g npm@latest -fi - -# Bootstrap monorepo -npm install - # ****************************************************************************** # First, publish the monorepo. # ****************************************************************************** diff --git a/tasks/e2e-kitchensink-eject.sh b/tasks/e2e-kitchensink-eject.sh index 622a396d652..fa124f9ec30 100755 --- a/tasks/e2e-kitchensink-eject.sh +++ b/tasks/e2e-kitchensink-eject.sh @@ -69,14 +69,6 @@ if [ "$AGENT_OS" == 'Windows_NT' ]; then root_path=$(cmd //c cd) fi -if hash npm 2>/dev/null -then - npm i -g npm@latest -fi - -# Bootstrap monorepo -npm install - # ****************************************************************************** # First, publish the monorepo. # ****************************************************************************** diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index c29b9840c34..48af65e6031 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -69,14 +69,6 @@ if [ "$AGENT_OS" == 'Windows_NT' ]; then root_path=$(cmd //c cd) fi -if hash npm 2>/dev/null -then - npm i -g npm@latest -fi - -# Bootstrap monorepo -npm install - # ****************************************************************************** # First, publish the monorepo. # ****************************************************************************** diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 3d01fba6f0c..bd2ef39214c 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -76,25 +76,17 @@ if [ "$EXPECTED" != "$ACTUAL" ]; then exit 1 fi -if hash npm 2>/dev/null -then - npm i -g npm@latest -fi - -# Bootstrap monorepo -npm install - # Start the local NPM registry startLocalRegistry "$root_path"/tasks/verdaccio.yaml # Lint own code -./node_modules/.bin/eslint --max-warnings 0 packages/babel-preset-react-app/ -./node_modules/.bin/eslint --max-warnings 0 packages/confusing-browser-globals/ -./node_modules/.bin/eslint --max-warnings 0 packages/create-react-app/ -./node_modules/.bin/eslint --max-warnings 0 packages/eslint-config-react-app/ -./node_modules/.bin/eslint --max-warnings 0 packages/react-dev-utils/ -./node_modules/.bin/eslint --max-warnings 0 packages/react-error-overlay/src/ -./node_modules/.bin/eslint --max-warnings 0 packages/react-scripts/ +npx eslint --max-warnings 0 packages/babel-preset-react-app/ +npx eslint --max-warnings 0 packages/confusing-browser-globals/ +npx eslint --max-warnings 0 packages/create-react-app/ +npx eslint --max-warnings 0 packages/eslint-config-react-app/ +npx eslint --max-warnings 0 packages/react-dev-utils/ +npx eslint --max-warnings 0 packages/react-error-overlay/src/ +npx eslint --max-warnings 0 packages/react-scripts/ npm test -w react-error-overlay if [ "$AGENT_OS" != 'Windows_NT' ]; then diff --git a/tasks/local-test.sh b/tasks/local-test.sh index 0e8af29f0b0..0a9bd35fe39 100755 --- a/tasks/local-test.sh +++ b/tasks/local-test.sh @@ -4,26 +4,26 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +node_version=14 +current_git_branch=`git rev-parse --abbrev-ref HEAD` +git_branch=${current_git_branch} +test_suite=all +interactive=false + function print_help { echo "Usage: ${0} [OPTIONS]" echo "" echo "OPTIONS:" - echo " --node-version the node version to use while testing [12]" - echo " --git-branch the git branch to checkout for testing [the current one]" - echo " --test-suite which test suite to use ('all', 'behavior', installs', 'kitchensink', 'kitchensink-eject', 'simple') ['all']" - echo " --interactive gain a bash shell after the test run" + echo " --node-version the node version to use while testing [${node_version}]" + echo " --git-branch the git branch to checkout for testing [${current_git_branch}]" + echo " --test-suite which test suite to use ('all', 'behavior', installs', 'kitchensink', 'kitchensink-eject', 'simple') ['${test_suite}']" + echo " --interactive gain a bash shell after the test run [${interactive}]" echo " --help print this message and exit" echo "" } cd $(dirname $0) -node_version=14 -current_git_branch=`git rev-parse --abbrev-ref HEAD` -git_branch=${current_git_branch} -test_suite=all -interactive=false - while [ "$1" != "" ]; do case $1 in "--node-version") @@ -84,6 +84,8 @@ cd - mv /var/create-react-app/patch . git apply patch rm patch +git add -A +git commit -m 'Apply local changes' CMD if [ ${git_branch} != ${current_git_branch} ]; then @@ -91,15 +93,15 @@ if [ ${git_branch} != ${current_git_branch} ]; then fi read -r -d '' command <<- CMD -echo "prefix=~/.npm" > ~/.npmrc -mkdir ~/.npm -export PATH=\$PATH:~/.npm/bin +npm install npm@8 -g +export PATH=\$(npm config get prefix -g)/bin:\$PATH set -x git clone /var/create-react-app create-react-app --branch ${git_branch} cd create-react-app ${apply_changes} node --version npm --version +npm ci set +x ${test_command} result_code=\$? diff --git a/tasks/publish.sh b/tasks/publish.sh index 0fed73e0078..f58d670b9a5 100755 --- a/tasks/publish.sh +++ b/tasks/publish.sh @@ -28,6 +28,7 @@ root_path=$PWD if [ -n "$(git status --porcelain)" ]; then echo "Your git status is not clean. Aborting."; + git diff exit 1; fi