From 1a2b411ef422c6417dd81145b282033b5b129aaf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 21 Jan 2022 15:03:35 -0800 Subject: [PATCH] [Tests] migrate tests to Github Actions per https://github.com/ljharb/object.assign/pull/81 See also: https://github.com/inspect-js/is-arguments/pull/38 --- .eslintrc | 5 +- .github/workflows/node-pretest.yml | 7 ++ .github/workflows/node.yml | 105 ++++++++++++++++++++++ .github/workflows/rebase.yml | 15 ++++ .github/workflows/require-allow-edits.yml | 12 +++ .travis.yml | 26 ------ package.json | 9 +- tests/lib/rules/no-unused-styles.js | 17 ++-- 8 files changed, 158 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/node-pretest.yml create mode 100644 .github/workflows/node.yml create mode 100644 .github/workflows/rebase.yml create mode 100644 .github/workflows/require-allow-edits.yml delete mode 100644 .travis.yml diff --git a/.eslintrc b/.eslintrc index a290457..5680399 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,7 @@ { "extends": "airbnb-base", "env": { - "node": true + "node": true, }, "rules": { "strict": 0, @@ -13,5 +13,6 @@ "exports": "always-multiline", "functions": "ignore", }], - } + "prefer-object-spread": "off", + }, } diff --git a/.github/workflows/node-pretest.yml b/.github/workflows/node-pretest.yml new file mode 100644 index 0000000..765edf7 --- /dev/null +++ b/.github/workflows/node-pretest.yml @@ -0,0 +1,7 @@ +name: 'Tests: pretest/posttest' + +on: [pull_request, push] + +jobs: + tests: + uses: ljharb/actions/.github/workflows/pretest.yml@main diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml new file mode 100644 index 0000000..7876517 --- /dev/null +++ b/.github/workflows/node.yml @@ -0,0 +1,105 @@ +name: 'Tests: node.js' + +on: [pull_request, push] + +jobs: + matrix: + runs-on: ubuntu-latest + outputs: + latest: ${{ steps.set-matrix.outputs.requireds }} + minors: ${{ steps.set-matrix.outputs.optionals }} + steps: + - uses: ljharb/actions/node/matrix@main + id: set-matrix + with: + versionsAsRoot: true + type: majors + preset: '>=4' # mocha 5 requires node 4 + + latest: + needs: [matrix] + name: 'latest majors' + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + node-version: ${{ fromJson(needs.matrix.outputs.latest) }} + eslint: + - 7 + - 6 + - 5 + - 4 + - 4.14 # last version without messageId + - 3 + exclude: + - node-version: 5 + - node-version: 4 + - node-version: 15 + eslint: 8 + - node-version: 13 + eslint: 8 + - node-version: 11 + eslint: 8 + - node-version: 11 + eslint: 7 + - node-version: 10 + eslint: 8 + - node-version: 9 + eslint: 8 + - node-version: 9 + eslint: 7 + - node-version: 8 + eslint: 8 + - node-version: 8 + eslint: 7 + - node-version: 7 + eslint: 8 + - node-version: 7 + eslint: 7 + - node-version: 7 + eslint: 6 + - node-version: 6 + eslint: 8 + - node-version: 6 + eslint: 7 + - node-version: 6 + eslint: 6 + - node-version: 5 + eslint: 8 + - node-version: 5 + eslint: 7 + - node-version: 5 + eslint: 6 + - node-version: 5 + eslint: 5 + - node-version: 4 + eslint: 8 + - node-version: 4 + eslint: 7 + - node-version: 4 + eslint: 6 + - node-version: 4 + eslint: 5 + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@main + name: 'nvm install ${{ matrix.node-version }} && npm install' + with: + node-version: ${{ matrix.node-version }} + after_install: npm install --no-save "eslint@${{ matrix.eslint }}" + skip-ls-check: ${{ matrix.node-version < 10 && true || false }} + env: + NPM_CONFIG_LEGACY_PEER_DEPS: true + - run: npx ls-engines + if: ${{ matrix.node-version >= 12 }} + - run: npm run tests-only + - uses: codecov/codecov-action@v1 + + node: + name: 'node.js' + needs: [latest] + runs-on: ubuntu-latest + steps: + - run: 'echo tests completed' diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 0000000..5b6d04b --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,15 @@ +name: Automatic Rebase + +on: [pull_request_target] + +jobs: + _: + name: "Automatic Rebase" + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/rebase@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/require-allow-edits.yml b/.github/workflows/require-allow-edits.yml new file mode 100644 index 0000000..7b842f8 --- /dev/null +++ b/.github/workflows/require-allow-edits.yml @@ -0,0 +1,12 @@ +name: Require “Allow Edits” + +on: [pull_request_target] + +jobs: + _: + name: "Require “Allow Edits”" + + runs-on: ubuntu-latest + + steps: + - uses: ljharb/require-allow-edits@main diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c6697e1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: node_js -os: - - linux -node_js: - - "12" - - "10" - - "8" - - "6" - -before_install: - - 'nvm install-latest-npm' -install: - - 'npm install' - - 'if [ "${TRAVIS_NODE_VERSION}" = "6" ]; then npm install --no-save eslint@5 ; fi' - - 'npm ls > /dev/null' -script: - - 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi' - - 'if [ -n "${TEST-}" ]; then npm run tests-only; fi' -sudo: false -env: - - TEST=true -matrix: - fast_finish: true - include: - - node_js: "lts/*" - env: PRETEST=true diff --git a/package.json b/package.json index d26ac1e..90e0673 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,14 @@ "lint": "eslint .", "mocha": "mocha --recursive", "postversion": "git commit package.json CHANGELOG.md -m \"Version $npm_package_version\" && npm run tag && git push && git push --tags && npm publish", - "prepublish": "in-publish && safe-publish-latest || not-in-publish", + "prepublishOnly": "safe-publish-latest", + "prepublish": "not-in-publish || safe-publish-latest", "pretest": "npm run --silent lint", "preversion": "npm run test && npm run check-changelog && npm run check-only-changelog-changed", "tag": "git tag v$npm_package_version", "test": "npm run tests-only", "tests-only": "npm run mocha --silent tests", + "posttest": "aud --production", "version:major": "npm --no-git-tag-version version major", "version:minor": "npm --no-git-tag-version version minor", "version:patch": "npm --no-git-tag-version version patch" @@ -44,13 +46,16 @@ "eslint": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0" }, "devDependencies": { + "aud": "^2.0.0", "chai": "^4.2.0", "eslint": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0", "eslint-config-airbnb-base": "^14.0.0", "eslint-plugin-import": "^2.18.2", "in-publish": "^2.0.0", + "ls-engines": "^0.6.4", "mocha": "^5.2.0", - "safe-publish-latest": "^1.1.3" + "safe-publish-latest": "^1.1.3", + "semver": "^6.3.0" }, "dependencies": { "has": "^1.0.3" diff --git a/tests/lib/rules/no-unused-styles.js b/tests/lib/rules/no-unused-styles.js index 00375ae..006875d 100644 --- a/tests/lib/rules/no-unused-styles.js +++ b/tests/lib/rules/no-unused-styles.js @@ -6,11 +6,13 @@ 'use strict'; const RuleTester = require('eslint').RuleTester; +const semver = require('semver'); +const eslintVersion = require('eslint/package.json').version; const rule = require('../../../lib/rules/no-unused-styles'); const parserOptions = { - ecmaVersion: 2019, + ecmaVersion: 6, ecmaFeatures: { jsx: true, }, @@ -19,8 +21,7 @@ const parserOptions = { const ruleTester = new RuleTester(); ruleTester.run('no-unused-styles', rule, { - - valid: [ + valid: [].concat( { parserOptions, code: ` @@ -411,8 +412,8 @@ ruleTester.run('no-unused-styles', rule, { `.trim(), }, - { // TODO handle object spread better? - parserOptions, + semver.satisfies('>= 5', eslintVersion) ? { // TODO handle object spread better? + parserOptions: Object.assign({}, parserOptions, { ecmaVersion: 2019 }), code: ` import { css } from 'withStyles'; @@ -426,7 +427,7 @@ ruleTester.run('no-unused-styles', rule, { ...foo, }))(Foo); `.trim(), - }, + } : [], { parserOptions, @@ -498,8 +499,8 @@ ruleTester.run('no-unused-styles', rule, { foo: {}, }))(Foo); `.trim(), - }, - ], + } + ), invalid: [ {