Skip to content

Commit

Permalink
Docs: Test examples report errors
Browse files Browse the repository at this point in the history
  • Loading branch information
btmills committed Aug 1, 2020
1 parent e51daaf commit ff6ffe1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions tests/examples/all.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
});
});
}
}

0 comments on commit ff6ffe1

Please sign in to comment.