Skip to content

Commit

Permalink
Fix tests relying on ESLint 7 API
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Sep 5, 2022
1 parent 2e3da80 commit ec9382c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
33 changes: 18 additions & 15 deletions eslint/babel-eslint-tests/test/integration/config-files.js
@@ -1,4 +1,4 @@
import eslint from "eslint";
import { ESLint } from "eslint";
import path from "path";
import { fileURLToPath } from "url";
import fs from "fs";
Expand All @@ -16,27 +16,30 @@ describe("Babel config files", () => {
const itNode12upNoESM =
USE_ESM || parseInt(process.versions.node) < 12 ? it.skip : it;

itESM("works with babel.config.mjs", () => {
const engine = new eslint.CLIEngine({ ignore: false });
itESM("works with babel.config.mjs", async () => {
const engine = new ESLint({ ignore: false });
expect(
engine.executeOnFiles([
await engine.lintFiles([
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
`../fixtures/mjs-config-file/a.js`,
),
]),
).toMatchObject({ errorCount: 0 });
).toMatchObject([{ errorCount: 0 }]);
});

itNode12upNoESM("experimental worker works with babel.config.mjs", () => {
const engine = new eslint.CLIEngine({ ignore: false });
expect(
engine.executeOnFiles([
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
`../fixtures/mjs-config-file-babel-7/a.js`,
itNode12upNoESM(
"experimental worker works with babel.config.mjs",
async () => {
const engine = new ESLint({ ignore: false });
expect(
await engine.lintFiles(
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
`../fixtures/mjs-config-file-babel-7/a.js`,
),
),
]),
).toMatchObject({ errorCount: 0 });
});
).toMatchObject([{ errorCount: 0 }]);
},
);
});
@@ -1,17 +1,16 @@
import eslint from "eslint";
import { ESLint } from "eslint";
import path from "path";
import { fileURLToPath } from "url";

describe("https://github.com/babel/babel/issues/12985", () => {
it("works with different copies of @babel/parser", () => {
const engine = new eslint.CLIEngine({ ignore: false });
expect(() =>
engine.executeOnFiles([
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
`../fixtures/duplicated-babel-parser/a.js`,
),
]),
).not.toThrow();
it("works with different copies of @babel/parser", async () => {
const engine = new ESLint({ ignore: false });

await engine.lintFiles(
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
`../fixtures/duplicated-babel-parser/a.js`,
),
);
});
});
@@ -1,11 +1,12 @@
import eslint from "eslint";
import { ESLint } from "eslint";
import path from "path";
import { fileURLToPath } from "url";

describe("https://github.com/babel/babel-eslint/issues/558", () => {
it("doesn't crash with eslint-plugin-import", () => {
const engine = new eslint.CLIEngine({ ignore: false });
engine.executeOnFiles(
it("doesn't crash with eslint-plugin-import", async () => {
const engine = new ESLint({ ignore: false });

await engine.lintFiles(
["a.js", "b.js", "c.js"].map(file =>
path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
Expand Down
@@ -1,10 +1,11 @@
import eslint from "eslint";
import { Linter } from "eslint";
import fs from "fs";
import path from "path";
import * as parser from "../../../../../babel-eslint-parser/lib/index.cjs";
import { fileURLToPath } from "url";

eslint.linter.defineParser("@babel/eslint-parser", parser);
const linter = new Linter();
linter.defineParser("@babel/eslint-parser", parser);

const paths = {
fixtures: path.join(
Expand All @@ -28,7 +29,7 @@ const baseEslintOpts = {
};

/**
* Load a fixture and run eslint.linter.verify() on it.
* Load a fixture and run linter.verify() on it.
* Pass the return value to done().
* @param object opts
* @param function done
Expand All @@ -37,7 +38,7 @@ function lint(opts) {
return new Promise((resolve, reject) => {
readFixture(opts.fixture, (err, src) => {
if (err) return reject(err);
resolve(eslint.linter.verify(src, opts.eslint));
resolve(linter.verify(src, opts.eslint));
});
});
}
Expand Down

0 comments on commit ec9382c

Please sign in to comment.