From b7bad38dcff024d374ee98f972b55b3de9e61289 Mon Sep 17 00:00:00 2001 From: Jordan Harband <ljharb@gmail.com> Date: Wed, 26 Jan 2022 12:44:40 -0800 Subject: [PATCH] [Tests] build tests first, so CI can build/test in different stages --- .babelrc | 8 ++++++++ .github/workflows/node.yml | 42 +++++++++++++++++++++++++++++++++----- .gitignore | 1 + .npmignore | 1 + .nycrc | 1 - package.json | 15 ++++++++------ test/mocha.opts | 3 +-- 7 files changed, 57 insertions(+), 14 deletions(-) diff --git a/.babelrc b/.babelrc index 4e91c458..cc5885df 100644 --- a/.babelrc +++ b/.babelrc @@ -3,6 +3,14 @@ "test": { "presets": [["airbnb", { looseClasses: true }]], "plugins": [ + ["import-path-replace", { + "rules": [ + { + "match": "../src/", + "replacement": "../lib/" + } + ] + }], ["inline-react-svg", { "svgo": false }], diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 7b9fb66f..1f5467ef 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -14,11 +14,31 @@ jobs: with: type: 'majors' versionsAsRoot: true - preset: '>=6' - # to test in node < 6, we need to run the build in one stage, including the tests, and then run the tests in the desired node version later + preset: '>=4' + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + with: + node-version: 'lts/*' + - uses: actions/cache@v2 + id: cache + with: + path: | + lib + esm + test-build + key: ${{ runner.os }}-${{ hashFiles('package.json', 'src/**', 'test/**', 'scripts/buildCSS.js') }} + - run: npm run build + if: steps.cache.outputs.cache-hit != 'true' + - run: npm run build:test + if: steps.cache.outputs.cache-hit != 'true' + majors: - needs: [matrix] + needs: [build, matrix] name: 'latest minors' runs-on: ubuntu-latest @@ -34,7 +54,7 @@ jobs: - '15' - '15.5' - '15.0' - # - '0.14' # TODO: fix pure-component-fallbacl + - '0.14' steps: - uses: actions/checkout@v2 @@ -42,13 +62,25 @@ jobs: name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} + skip-ls-check: ${{ !startsWith(matrix.node-version, '5.') && !startsWith(matrix.node-version, '4.') && 'true' || 'false' }} + - uses: actions/cache@v2 + id: cache + with: + path: | + lib + esm + test-build + key: ${{ runner.os }}-${{ hashFiles('package.json', 'src/**', 'test/**', 'scripts/buildCSS.js') }} + - run: npm run react + env: + REACT: ${{ matrix.react }} - run: npm run tests-only env: REACT: ${{ matrix.react }} - uses: codecov/codecov-action@v2 node: - name: 'node 6+' + name: 'node.js' needs: [majors] runs-on: ubuntu-latest steps: diff --git a/.gitignore b/.gitignore index 6374bef4..3d7cb404 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ node_modules # build folder lib esm +test-build .idea # gh-pages diff --git a/.npmignore b/.npmignore index f88e53c2..f27011d8 100644 --- a/.npmignore +++ b/.npmignore @@ -44,5 +44,6 @@ public react-dates-demo.gif stories test +test-build css !lib/css diff --git a/.nycrc b/.nycrc index 90d79055..33fbfd6d 100644 --- a/.nycrc +++ b/.nycrc @@ -7,7 +7,6 @@ "src" ], "require": [ - "@babel/register" ], "reporter": [ "text", diff --git a/package.json b/package.json index ad6bfc80..d6c29274 100644 --- a/package.json +++ b/package.json @@ -5,22 +5,23 @@ "main": "index.js", "scripts": { "prebuild": "npm run clean", - "build": "npm run build:cjs && npm run build:esm && npm run build:css -- --optimize ", + "build": "npm run build:cjs && npm run build:esm && npm run build:css -- --optimize", + "postbuild": "npm run build:test", "build:cjs": "BABEL_ENV=cjs babel src/ -d lib/", "build:esm": "BABEL_ENV=esm babel src/ -d esm/", + "build:test": "BABEL_ENV=test babel test/ -d test-build/", "prebuild:css": "rimraf lib/css && mkdirp lib/css", "build:css": "node scripts/buildCSS.js", - "clean": "rimraf lib esm", + "clean": "rimraf lib esm test-build", "lint": "eslint --ext .js,.jsx src test", - "mocha": "mocha ./test/_helpers", + "mocha": "mocha ./test-build/_helpers", "storybook:uninstall": "npm uninstall --no-save @storybook/react && rimraf node_modules/@storybook node_modules/react-modal node_modules/react-dom-factories", "react": "NPM_CONFIG_LEGACY_PEER_DEPS=true enzyme-adapter-react-install 16", "pretest": "npm run --silent lint", - "pretests-only": "npm run react", "tests-only": "cross-env NODE_ENV=test nyc npm run mocha --silent", "pretests-karma": "npm run react", "tests-karma": "karma start", - "test": "npm run build && npm run tests-only", + "test": "npm run react && npm run build && npm run build:test && npm run tests-only", "storybook": "start-storybook -p 6006", "storybook:css": "npm run build:css && start-storybook -p 6006 -c .storybook-css", "tag": "git tag v$npm_package_version", @@ -64,12 +65,14 @@ "airbnb-js-shims": "^2.2.1", "aphrodite": "^2.4.0", "babel-loader": "^8.2.2", + "babel-plugin-import-path-replace": "^0.1.0", "babel-plugin-inline-react-svg": "^1.1.2", "babel-plugin-inline-svg": "^1.2.0", "babel-plugin-istanbul": "^5.2.0", "babel-plugin-transform-replace-object-assign": "^2.0.0", "babel-preset-airbnb": "^4.5.0", "chai": "^4.2.0", + "cheerio": "=1.0.0-rc.3", "clean-css": "^4.2.3", "cross-env": "^5.2.1", "enzyme": "^3.11.0", @@ -104,7 +107,7 @@ "rimraf": "^2.7.1", "safe-publish-latest": "^1.1.4", "sass-loader": "^7.3.1", - "sinon": "^8.1.1", + "sinon": "^7.5.0", "sinon-sandbox": "^2.0.6", "style-loader": "^0.20.3", "typescript": "*", diff --git a/test/mocha.opts b/test/mocha.opts index 6f1ab8e6..22acddc5 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,3 +1,2 @@ ---require @babel/register --require airbnb-js-shims -test/**/*.{js,jsx} +test-build/**/*.js -- GitLab