From 1dd70890b92827a5fbd3a86a62c3f2bc30389340 Mon Sep 17 00:00:00 2001 From: Brandon Mills Date: Sun, 20 Dec 2020 15:37:46 -0500 Subject: [PATCH] Fix: npm prepare script on Windows (refs #166) (#168) * Chore: Test on Windows and macOS * Fix: npm prepare script on Windows (refs #166) The previous script worked on macOS and Linux, but I neglected to consider Windows. This wouldn't affect users thankfully, only developers, so the blast radius would have been small had it not been caught. Now that we're testing on Windows, future bugs like this should be caught. I'm out of ideas for doing this entirely inside npm scripts, so I broke down and did it in JS. * Chore: Increase test timeout for Windows and macOS runners They occasionally exhibit extremely slow filesystem performance. * Add npm-prepare script JSDoc header --- .github/workflows/ci.yml | 8 +++++++- npm-prepare.js | 20 ++++++++++++++++++++ package.json | 2 +- tests/lib/plugin.js | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 npm-prepare.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65c5720..f23e890 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,16 @@ jobs: test: name: Test - runs-on: ubuntu-latest strategy: matrix: + os: [ubuntu-latest] node-version: ["8.10.0", 8.x, 10.x, 12.x, 13.x, 14.x] + include: + - os: windows-latest + node: "12.x" + - os: macOS-latest + node: "12.x" + runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v1 diff --git a/npm-prepare.js b/npm-prepare.js new file mode 100644 index 0000000..243ada0 --- /dev/null +++ b/npm-prepare.js @@ -0,0 +1,20 @@ +/** + * @fileoverview Install examples' dependencies as part of local npm install for + * development and CI. + * @author btmills + */ + +"use strict"; + +const childProcess = require("child_process"); +const fs = require("fs"); +const path = require("path"); + +const examplesDir = path.resolve(__dirname, "examples"); +const examples = fs.readdirSync(examplesDir); + +for (const example of examples) { + childProcess.execSync("npm install", { + cwd: path.resolve(examplesDir, example) + }); +} diff --git a/package.json b/package.json index d65086c..9bae0fc 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ ], "scripts": { "lint": "eslint --ext js,md .", - "prepare": "for example in examples/*; do (cd \"$example\" && npm install); done", + "prepare": "node ./npm-prepare.js", "test": "npm run lint && npm run test-cov", "test-cov": "nyc _mocha -- -c tests/{examples,lib}/**/*.js", "generate-release": "eslint-generate-release", diff --git a/tests/lib/plugin.js b/tests/lib/plugin.js index f51cbe3..cd12763 100644 --- a/tests/lib/plugin.js +++ b/tests/lib/plugin.js @@ -55,7 +55,7 @@ describe("recommended config", () => { // hook-level timeouts uses `this`, so disable the rule. // https://mochajs.org/#hook-level // eslint-disable-next-line no-invalid-this - this.timeout(9999); + this.timeout(30000); execSync("npm link && npm link eslint-plugin-markdown"); } else {