Skip to content

Commit

Permalink
test: use ESLint class instead of CLIEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed May 12, 2020
1 parent ad0edef commit ac16d75
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 82 deletions.
4 changes: 2 additions & 2 deletions test/base-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("base", () => {
it("should get expected errors and warninigs with base config", () => {
const result = runLintWithFixtures("base");
it("should get expected errors and warninigs with base config", async () => {
const result = await runLintWithFixtures("base");
assert.deepStrictEqual(result, {
"error.js": {
errors: [
Expand Down
4 changes: 2 additions & 2 deletions test/es5-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("es5", () => {
it("should get expected errors and warninigs with es5 config", () => {
const result = runLintWithFixtures("es5");
it("should get expected errors and warninigs with es5 config", async () => {
const result = await runLintWithFixtures("es5");
assert.deepStrictEqual(result, {
"error.js": {
errors: ["no-unused-vars", "no-redeclare"]
Expand Down
4 changes: 2 additions & 2 deletions test/flowtype-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("flowtype", () => {
it("should get expected errors and warninigs with react config with flowtype config", () => {
it("should get expected errors and warninigs with react config with flowtype config", async () => {
// We use react presets in order to support ES2017 syntax
const result = runLintWithFixtures("flowtype");
const result = await runLintWithFixtures("flowtype");
assert.deepStrictEqual(result, {
"ok.js": {},
"error.js": {
Expand Down
7 changes: 5 additions & 2 deletions test/globals-kintone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("kintone", () => {
it("should get expected errors and warninigs with kintone config", () => {
const result = runLintWithFixtures("globals-kintone", "globals/kintone.js");
it("should get expected errors and warninigs with kintone config", async () => {
const result = await runLintWithFixtures(
"globals-kintone",
"globals/kintone.js"
);
assert.deepStrictEqual(result, {
"error.js": {
errors: ["no-undef"]
Expand Down
4 changes: 2 additions & 2 deletions test/kintone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("kintone", () => {
it("should get expected errors and warninigs with kintone config", () => {
const result = runLintWithFixtures("kintone");
it("should get expected errors and warninigs with kintone config", async () => {
const result = await runLintWithFixtures("kintone");
assert.deepStrictEqual(result, {
"error.js": {
errors: ["strict", "strict"]
Expand Down
12 changes: 6 additions & 6 deletions test/lib/runLintWithFixtures.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"use strict";

const CLIEngine = require("eslint").CLIEngine;
const { ESLint } = require("eslint");
const path = require("path");

/**
* Run ESlint and return the result per files
* @param type lint type, which is in lib directory
* @returns {Object} lint results {[fileName]: {errors: [ruleNames], warnings: [ruleNames]}}
*/
const runLintWithFixtures = (type, configFile = `lib/${type}.js`) => {
const cli = new CLIEngine({
configFile: path.resolve(process.cwd(), configFile),
const runLintWithFixtures = async (type, configFile = `lib/${type}.js`) => {
const eslint = new ESLint({
overrideConfigFile: path.resolve(process.cwd(), configFile),
ignore: false,
useEslintrc: false,
extensions: [".js", ".jsx", ".ts", ".tsx"]
});
const targetDir = path.resolve(__dirname, "..", "fixtures", type);
const lintResult = cli.executeOnFiles([targetDir]);
const lintResult = await eslint.lintFiles([targetDir]);
// console.log(JSON.stringify(lintResult, null, 2));
return lintResult.results.reduce((results, { filePath, messages }) => {
return lintResult.reduce((results, { filePath, messages }) => {
// strip path
const fileName = filePath.replace(`${targetDir}/`, "");
return Object.assign(results, {
Expand Down
4 changes: 2 additions & 2 deletions test/node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("node", () => {
it("should get expected errors and warninigs with node config", () => {
const result = runLintWithFixtures("node");
it("should get expected errors and warninigs with node config", async () => {
const result = await runLintWithFixtures("node");
assert.deepStrictEqual(result, {
"error.js": {
errors: [
Expand Down
4 changes: 2 additions & 2 deletions test/node-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("node-typescript", () => {
it("should get expected errors and warninigs", () => {
const result = runLintWithFixtures(
it("should get expected errors and warninigs", async () => {
const result = await runLintWithFixtures(
"node-typescript",
"presets/node-typescript-prettier.js"
);
Expand Down
123 changes: 69 additions & 54 deletions test/presets-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,72 @@ const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("presets", () => {
describe("index", () => {
it("should be able to use index as well as lib/base", () => {
it("should be able to use index as well as lib/base", async () => {
assert.deepStrictEqual(
runLintWithFixtures("base"),
runLintWithFixtures("base", "index.js")
await runLintWithFixtures("base"),
await runLintWithFixtures("base", "index.js")
);
});
});
describe("react", () => {
it("should be able to use react as well as lib/base and lib/react", () => {
assert.deepStrictEqual(runLintWithFixtures("react", "presets/react.js"), {
"ok.jsx": {}
});
it("should be able to use react as well as lib/base and lib/react", async () => {
assert.deepStrictEqual(
runLintWithFixtures("base"),
runLintWithFixtures("base", "presets/react.js")
await runLintWithFixtures("react", "presets/react.js"),
{
"ok.jsx": {}
}
);
assert.deepStrictEqual(
await runLintWithFixtures("base"),
await runLintWithFixtures("base", "presets/react.js")
);
});
});
describe("flowtype", () => {
it("should be able to use flowtype as well as lib/base and lib/flowtype", () => {
it("should be able to use flowtype as well as lib/base and lib/flowtype", async () => {
assert.deepStrictEqual(
runLintWithFixtures("flowtype"),
runLintWithFixtures("flowtype", "presets/flowtype.js")
await runLintWithFixtures("flowtype"),
await runLintWithFixtures("flowtype", "presets/flowtype.js")
);
assert.deepStrictEqual(
runLintWithFixtures("base"),
runLintWithFixtures("base", "presets/flowtype.js")
await runLintWithFixtures("base"),
await runLintWithFixtures("base", "presets/flowtype.js")
);
});
});
describe("react-flowtype", () => {
it("should be able to use react-flowtype as well as lib/react and lib/flowtype", () => {
it("should be able to use react-flowtype as well as lib/react and lib/flowtype", async () => {
assert.deepStrictEqual(
runLintWithFixtures("react", "presets/react.js"),
runLintWithFixtures("react", "presets/react-flowtype.js")
await runLintWithFixtures("react", "presets/react.js"),
await runLintWithFixtures("react", "presets/react-flowtype.js")
);
assert.deepStrictEqual(
runLintWithFixtures("flowtype"),
runLintWithFixtures("flowtype", "presets/react-flowtype.js")
await runLintWithFixtures("flowtype"),
await runLintWithFixtures("flowtype", "presets/react-flowtype.js")
);
});
});
describe("node", () => {
it("should be able to use node as well as lib/node", () => {
it("should be able to use node as well as lib/node", async () => {
assert.deepStrictEqual(
runLintWithFixtures("node"),
runLintWithFixtures("node", "presets/node.js")
await runLintWithFixtures("node"),
await runLintWithFixtures("node", "presets/node.js")
);
});
});
describe("kintone-customize-es5", () => {
it("should be able to use kintone-customize-es5 as well as lib/es5 and lib/kintone", () => {
it("should be able to use kintone-customize-es5 as well as lib/es5 and lib/kintone", async () => {
assert.deepStrictEqual(
runLintWithFixtures("es5"),
runLintWithFixtures("es5", "presets/kintone-customize-es5.js")
await runLintWithFixtures("es5"),
await runLintWithFixtures("es5", "presets/kintone-customize-es5.js")
);
});
it("should be able to use kintone-customize-es5 as well as lib/kintone", () => {
it("should be able to use kintone-customize-es5 as well as lib/kintone", async () => {
assert.deepStrictEqual(
runLintWithFixtures("kintone", "presets/kintone-customize-es5.js"),
await runLintWithFixtures(
"kintone",
"presets/kintone-customize-es5.js"
),
{
"ok.js": {},
"error.js": { errors: ["strict", "strict"] }
Expand All @@ -71,74 +77,83 @@ describe("presets", () => {
});
});
describe("prettier", () => {
it("should be able to use prettier as well as lib/prettier", () => {
it("should be able to use prettier as well as lib/prettier", async () => {
assert.deepStrictEqual(
runLintWithFixtures("prettier"),
runLintWithFixtures("prettier", "presets/prettier.js")
await runLintWithFixtures("prettier"),
await runLintWithFixtures("prettier", "presets/prettier.js")
);
});
});
describe("react-prettier", () => {
it("should be able to use react-prettier as well as lib/prettier", () => {
it("should be able to use react-prettier as well as lib/prettier", async () => {
assert.deepStrictEqual(
runLintWithFixtures("prettier"),
runLintWithFixtures("prettier", "presets/react-prettier.js")
await runLintWithFixtures("prettier"),
await runLintWithFixtures("prettier", "presets/react-prettier.js")
);
});
});
describe("react-flowtype-prettier", () => {
it("should be able to use react-flowtype-prettier as well as lib/prettier", () => {
it("should be able to use react-flowtype-prettier as well as lib/prettier", async () => {
assert.deepStrictEqual(
runLintWithFixtures("prettier"),
runLintWithFixtures("prettier", "presets/react-flowtype-prettier.js")
await runLintWithFixtures("prettier"),
await runLintWithFixtures(
"prettier",
"presets/react-flowtype-prettier.js"
)
);
});
});
describe("node-prettier", () => {
it("should be able to use node-prettier as well as lib/prettier", () => {
it("should be able to use node-prettier as well as lib/prettier", async () => {
assert.deepStrictEqual(
runLintWithFixtures("prettier"),
runLintWithFixtures("prettier", "presets/node-prettier.js")
await runLintWithFixtures("prettier"),
await runLintWithFixtures("prettier", "presets/node-prettier.js")
);
});
});
describe("node-typescript-prettier", () => {
it("should be able to use node-typescript-prettier as well as lib/prettier", () => {
it("should be able to use node-typescript-prettier as well as lib/prettier", async () => {
assert.deepStrictEqual(
runLintWithFixtures("prettier"),
runLintWithFixtures("prettier", "presets/node-typescript-prettier.js")
await runLintWithFixtures("prettier"),
await runLintWithFixtures(
"prettier",
"presets/node-typescript-prettier.js"
)
);
});
});
describe("react-typescript-prettier", () => {
it("should be able to use react-typescript-prettier as well as lib/prettier", () => {
it("should be able to use react-typescript-prettier as well as lib/prettier", async () => {
assert.deepStrictEqual(
runLintWithFixtures("prettier"),
runLintWithFixtures("prettier", "presets/react-typescript-prettier.js")
await runLintWithFixtures("prettier"),
await runLintWithFixtures(
"prettier",
"presets/react-typescript-prettier.js"
)
);
});
});
describe("react-typescript", () => {
it("should be able to use react-typescript as well as presets/typescript", () => {
it("should be able to use react-typescript as well as presets/typescript", async () => {
assert.deepStrictEqual(
runLintWithFixtures("typescript", "presets/typescript.js"),
runLintWithFixtures("typescript", "presets/react-typescript.js")
await runLintWithFixtures("typescript", "presets/typescript.js"),
await runLintWithFixtures("typescript", "presets/react-typescript.js")
);
});
});
describe("typescript-prettier", () => {
it("should be able to use typescript-prettier as well as lib/prettier", () => {
it("should be able to use typescript-prettier as well as lib/prettier", async () => {
assert.deepStrictEqual(
runLintWithFixtures("prettier"),
runLintWithFixtures("prettier", "presets/typescript-prettier.js")
await runLintWithFixtures("prettier"),
await runLintWithFixtures("prettier", "presets/typescript-prettier.js")
);
});
});
describe("typescript", () => {
it("should be able to use typescript as well as lib/typescript", () => {
it("should be able to use typescript as well as lib/typescript", async () => {
assert.deepStrictEqual(
runLintWithFixtures("typescript"),
runLintWithFixtures("typescript", "presets/typescript.js")
await runLintWithFixtures("typescript"),
await runLintWithFixtures("typescript", "presets/typescript.js")
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/prettier-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("prettier", () => {
it("should get expected errors and warninigs", () => {
const result = runLintWithFixtures("prettier", "presets/prettier.js");
it("should get expected errors and warninigs", async () => {
const result = await runLintWithFixtures("prettier", "presets/prettier.js");
assert.deepStrictEqual(result, {
"ok.js": {},
"error.js": {
Expand Down
4 changes: 2 additions & 2 deletions test/react-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("react", () => {
it("should get expected errors and warninigs", () => {
it("should get expected errors and warninigs", async () => {
// We use react presets in order to support ES2017 syntax
const result = runLintWithFixtures("react", "presets/react.js");
const result = await runLintWithFixtures("react", "presets/react.js");
assert.deepStrictEqual(result, {
"ok.jsx": {}
});
Expand Down
4 changes: 2 additions & 2 deletions test/react-typescript-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("react-typescript", () => {
it("should get expected errors and warninigs", () => {
it("should get expected errors and warninigs", async () => {
// We use react presets in order to support ES2017 syntax
const result = runLintWithFixtures(
const result = await runLintWithFixtures(
"react-typescript",
"presets/react-typescript.js"
);
Expand Down
4 changes: 2 additions & 2 deletions test/typescript-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("typescript", () => {
it("should get expected errors and warninigs", () => {
it("should get expected errors and warninigs", async () => {
// We use react presets in order to support ES2017 syntax
const result = runLintWithFixtures("typescript");
const result = await runLintWithFixtures("typescript");
assert.deepStrictEqual(result, {
"ok.ts": {},
"error.ts": {
Expand Down

0 comments on commit ac16d75

Please sign in to comment.