diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b1a215fb..ee3c8571 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,5 +39,10 @@ jobs: run: npm install env: CI: true + - name: Install examples/react Packages + working-directory: ./examples/react + run: npm install + env: + CI: true - name: Test run: npm run test-cov diff --git a/package.json b/package.json index e45e70bd..4b3d5836 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "scripts": { "lint": "eslint --ext js,md .", "test": "npm run lint && npm run test-cov", - "test-cov": "nyc _mocha -- -c tests/lib/**/*.js", + "test-cov": "nyc _mocha -- -c tests/{examples,lib}/**/*.js", "generate-release": "eslint-generate-release", "generate-alpharelease": "eslint-generate-prerelease alpha", "generate-betarelease": "eslint-generate-prerelease beta", diff --git a/tests/examples/all.js b/tests/examples/all.js new file mode 100644 index 00000000..199c8d9d --- /dev/null +++ b/tests/examples/all.js @@ -0,0 +1,41 @@ +"use strict"; + +const assert = require("chai").assert; +const execSync = require("child_process").execSync; +const fs = require("fs"); +const path = require("path"); +const semver = require("semver"); + +const examples = path.resolve(__dirname, "../../examples/"); +for (const example of fs.readdirSync(examples)) { + const cwd = path.join(examples, example); + + // The plugin officially supports ESLint as early as v6, but the examples + // use ESLint v7, which has a higher minimum Node.js version than does v6. + // Only exercise the example if the running Node.js version satisfies the + // minimum version constraint. In CI, this will skip these tests in Node.js + // v8 and run them on all other Node.js versions. + const eslintPackageJsonPath = require.resolve("eslint/package.json", { + paths: [cwd] + }); + const eslintPackageJson = require(eslintPackageJsonPath); + if (semver.satisfies(process.version, eslintPackageJson.engines.node)) { + describe("examples", () => { + describe(example, () => { + it("reports errors on code blocks in .md files", () => { + try { + execSync("npx eslint . --format json", { cwd }); + assert.fail("ESLint should have found issues."); + } catch (error) { + const results = JSON.parse(error.stdout.toString()); + const readme = results.find(result => + path.basename(result.filePath) == "README.md" + ); + assert.isNotNull(readme); + assert.isAbove(readme.messages.length, 0); + } + }); + }); + }); + } +}