Skip to content

Commit

Permalink
[Tests] migrate tests to Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 26, 2021
1 parent 035f6d9 commit f422988
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 88 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/node-pretest.yml
@@ -0,0 +1,26 @@
name: 'Tests: pretest/posttest'

on: [pull_request, push]

jobs:
pretest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/install@main
with:
skip-ls-check: true
- run: sh install-relevant-react.sh
- run: npx lerna bootstrap
- run: npm run build
- run: npm run pretest

# posttest:
# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v2
# - uses: ljharb/actions/node/install@main
# - run: npm run build
# - run: npm run posttest
113 changes: 113 additions & 0 deletions .github/workflows/node.yml
@@ -0,0 +1,113 @@
name: 'Tests: node.js'

on: [pull_request, push]

jobs:
build:
name: 'install deps and build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/install@main
with:
skip-ls-check: true
- run: npx lerna bootstrap
- run: npm run build
- uses: actions/cache@v2
with:
path: |
packages/*/build
key: enzyme-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}

tests:
needs: [build]
name: 'run tests'
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version:
- '14'
- '12'
- '4'
react:
- '16.14'
- '16.13'
- '16.12'
- '16.11'
- '16.10'
- '16.9'
- '16.8'
- '16.7'
- '16.6'
- '16.5'
- '16.4'
- '16.3'
- '16.2'
- '16.1'
- '16.0'
- '15.5'
- '15.4'
- '15.3'
- '15.2'
- '15.1'
- '15.0'
- '0.14'
- '0.13'
include:
- node-version: '10'
react: '16'
- node-version: '8'
react: '16'
- node-version: '6'
react: '16'
- react: '16.8.3'
- react: '16.8.5'
env:
RENDERER: '16.8.5'
- react: '16.8.5'
continue-on-error: true
env:
RENDERER: '16.8.3'
- react: '16.3'
env:
ADAPTER: '16'
- react: '16.8'
continue-on-error: true
env:
RENDERER: '16.7'
- react: '16.7'
env:
RENDERER: '16.8'
- react: '16.7'
env:
RENDERER: '16.7'

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/cache@v2
with:
path: |
packages/*/build
key: enzyme-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }}
- run: sudo chmod -R a+w .
- uses: ljharb/actions/node/install@main
with:
node-version: ${{ matrix.node-version || 'lts/* '}}
skip-install: true
before_install: 'npm install --ignore-scripts'
after_install: '(nvm install node && REACT=${{ matrix.react }} TRAVIS=1 sh install-relevant-react.sh)'
skip-ls-check: true
- run: npm run travis
- uses: codecov/codecov-action@v1


node:
name: 'node + react'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'
74 changes: 1 addition & 73 deletions .travis.yml
Expand Up @@ -5,17 +5,14 @@ workspaces:
stages:
- install-build
- test
node_js:
- "12"
- "4"
import:
- ljharb/travis-ci:node/latest-npm.yml
install: 'echo already installed!'
before_script:
- 'nvm exec node sh install-relevant-react.sh'
- 'if [ -n "${KARMA-}" ]; then export CHROME_BIN=chromium-browser; export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; fi'
script:
- 'if [ -n "${LINT-}" ]; then npm run lint; elif [ -n "${KARMA-}" ]; then npm run test:karma -- --single-run; elif [ -n "${REACT-}" ]; then npm run travis; else false ; fi'
- 'if [ -n "${KARMA-}" ]; then npm run test:karma -- --single-run; elif [ -n "${REACT-}" ]; then npm run travis; else false ; fi'
after_script:
- 'if [ -n "${REACT-}" ] && [ "${TRAVIS_ALLOW_FAILURE}" != true ]; then case "${TRAVIS_NODE_VERSION}" in "8" | "6") ;; *) cat ./coverage/lcov.info | ./node_modules/.bin/coveralls ;; esac ; fi'
- 'if [ -n "${REACT-}" ] && [ "${TRAVIS_ALLOW_FAILURE}" != true ]; then bash <(curl -s https://codecov.io/bash) -f coverage/*.json; fi'
Expand All @@ -36,48 +33,6 @@ matrix:
- 'npx lerna bootstrap'
script:
- 'npx lerna run build'
- node_js: "lts/*"
env: LINT=true
stage: test
- node_js: "8"
env: REACT=16
stage: test
- node_js: "6"
env: REACT=16
stage: test
- node_js: "lts/*"
env: REACT=16.8.5 RENDERER=16.8.5
stage: test
- node_js: "lts/*"
env: REACT=16.8.5 RENDERER=16.8.3
stage: test
- node_js: "lts/*"
env: REACT=16.8.3
stage: test
- node_js: "lts/*"
env: REACT=16.8 RENDERER=16.7
stage: test
- node_js: "lts/*"
env: REACT=16.7 RENDERER=16.8
stage: test
- node_js: "lts/*"
env: REACT=16.7 RENDERER=16.7
stage: test
- node_js: "lts/*"
env: REACT=16.3 ADAPTER=16
stage: test
- node_js: "lts/*"
env: REACT=15.3
stage: test
- node_js: "lts/*"
env: REACT=15.2
stage: test
- node_js: "lts/*"
env: REACT=15.1
stage: test
- node_js: "lts/*"
env: REACT=15.0
stage: test
- node_js: "6"
env: KARMA=true REACT=0.13
stage: test
Expand All @@ -104,30 +59,3 @@ matrix:
env: KARMA=true REACT=15
- node_js: "6"
env: KARMA=true REACT=16
- node_js: "lts/*"
env: REACT=16.8.5 RENDERER=16.8.3
- node_js: "lts/*"
env: REACT=16.8 RENDERER=16.7
exclude:
- node_js: "6"
env: REACT=0.13
env:
- REACT=16.14
- REACT=16.13
- REACT=16.12
- REACT=16.11
- REACT=16.10
- REACT=16.9
- REACT=16.8
- REACT=16.7
- REACT=16.6
- REACT=16.5
- REACT=16.4
- REACT=16.3
- REACT=16.2
- REACT=16.1
- REACT=16.0
- REACT=15.5
- REACT=15.4
- REACT=0.14
- REACT=0.13
35 changes: 21 additions & 14 deletions env.js
Expand Up @@ -92,7 +92,8 @@ const reactVersion = version < 15 ? '0.' + version : version;
const adapterVersion = process.env.ADAPTER || getAdapter(reactVersion) || version;
const adapterName = `enzyme-adapter-react-${adapterVersion}`;
const adapterPackageJsonPath = path.join(root, 'packages', adapterName, 'package.json');
const testPackageJsonPath = path.join(root, 'packages', 'enzyme-test-suite', 'package.json');
const testPackagePath = path.join(root, 'packages', 'enzyme-test-suite');
const testPackageJsonPath = path.join(testPackagePath, 'package.json');

if (!fs.statSync(adapterPackageJsonPath)) {
throw new Error('Adapter not found: "' + adapterName + '"');
Expand All @@ -106,13 +107,19 @@ const packagesToRemove = [
'create-react-class',
].map((s) => `./node_modules/${s}`);

const pkgsDir = path.join(root, 'packages');
const projects = fs.readdirSync(pkgsDir);

const additionalDirsToRemove = [
];

const rmrfs = []
.concat(packagesToRemove)
.concat(packagesToRemove.flatMap((x) => projects.map((p) => path.join(pkgsDir, p, x))))
.concat(additionalDirsToRemove);

const originalTestJSON = getJSON(testPackageJsonPath);

Promise.resolve()
.then(() => Promise.all(rmrfs.map((s) => primraf(s))))
.then(() => run('npm', 'i'))
Expand All @@ -133,22 +140,22 @@ Promise.resolve()

// eslint-disable-next-line no-param-reassign
testJson.dependencies[adapterName] = adapterJson.version;
Object.assign(testJson.peerDependencies, adapterJson.peerDependencies);
Object.assign(testJson.devDependencies, adapterJson.peerDependencies);

return writeJSON(adapterPackageJsonPath, adapterJson, true).then(() => Promise.all([
// npm install the peer deps at the root
run('npm', 'i', '--no-save', ...installs),

return Promise.all([
writeJSON(adapterPackageJsonPath, adapterJson, true),
// add the adapter to the dependencies of the test suite
writeJSON(testPackageJsonPath, testJson, true),
]));
]).then(() => run('npm', 'i', '--no-save', ...installs)); // npm install the peer deps at the root
})
.then(() => run('lerna', 'bootstrap', '--hoist=\'react*\''))
.then(() => getJSON(testPackageJsonPath))
.then((testJson) => {
// now that we've lerna bootstrapped, we can remove the adapter from the
// package.json so there is no diff
// eslint-disable-next-line no-param-reassign
delete testJson.dependencies[adapterName];
return writeJSON(testPackageJsonPath, testJson, true);
})
.then(() => Promise.all([
path.join(pkgsDir, '*', 'node_modules', 'react'),
path.join(pkgsDir, '*', 'node_modules', 'react-dom'),
path.join(pkgsDir, '*', 'node_modules', 'react-addons-test-utils'),
].map((x) => primraf(x))))
.then(() => originalTestJSON)
// now that we've lerna bootstrapped, we can revert the test package.json so there is no diff
.then((testJson) => writeJSON(testPackageJsonPath, testJson, true))
.catch((err) => console.error(err));
3 changes: 3 additions & 0 deletions install-relevant-react.sh
Expand Up @@ -5,9 +5,12 @@ REACT="${REACT:-${1:-16}}"
echo "installing React $REACT"

if [ "$REACT" = "0.13" ]; then
echo "*** npm run env: -- 13"
npm run env: -- 13
elif [ "$REACT" = "0.14" ]; then
echo "*** npm run env: -- 14"
npm run env: -- 14
else
echo "*** npm run env: -- "${REACT}""
npm run env: -- "${REACT}"
fi
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -16,7 +16,6 @@
"lint": "lerna exec --parallel 'npm run lint -- --quiet'",
"lint:root": "eslint . --ext=js,md,jsx --ignore-pattern=packages/ --ignore-path .eslintignore",
"check": "lerna run lint && npm run test:all",
"prebuild": "npm run clean",
"build": "lerna run build",
"build:watch": "lerna run --parallel watch",
"pretest": "lerna run lint",
Expand Down Expand Up @@ -96,6 +95,8 @@
"npm": "gist:9cdb687f3806f8e6cb8a365d0b7840eb",
"nyc": "^10.3.2",
"prop-types": "^15.7.2",
"react": "*",
"react-dom": "*",
"rimraf": "^2.7.1",
"safe-publish-latest": "^1.1.4",
"semver": "^6.3.0",
Expand Down

0 comments on commit f422988

Please sign in to comment.