2023-10-23 23:00:22 +02:00
|
|
|
const test = require("node:test")
|
|
|
|
const assert = require("node:assert/strict")
|
2023-07-02 15:46:14 +02:00
|
|
|
|
2023-10-23 23:00:22 +02:00
|
|
|
const { ESLint } = require("eslint")
|
2022-02-19 16:05:21 +01:00
|
|
|
|
2022-02-20 12:36:37 +01:00
|
|
|
const eslint = new ESLint({
|
|
|
|
ignore: false,
|
|
|
|
useEslintrc: false,
|
2023-10-23 23:00:22 +02:00
|
|
|
overrideConfigFile: "eslintrc.json",
|
2022-02-20 12:36:37 +01:00
|
|
|
})
|
|
|
|
|
2023-10-23 23:00:22 +02:00
|
|
|
test("ensure we validate correctly JavaScript files", async () => {
|
2022-02-19 16:05:21 +01:00
|
|
|
const [noErrors] = await eslint.lintFiles(
|
2023-10-23 23:00:22 +02:00
|
|
|
"test/fixtures/javascript-no-errors.js",
|
2022-02-19 16:05:21 +01:00
|
|
|
)
|
|
|
|
const [withErrors] = await eslint.lintFiles(
|
2023-10-23 23:00:22 +02:00
|
|
|
"test/fixtures/javascript-with-errors.js",
|
2022-02-19 16:05:21 +01:00
|
|
|
)
|
2023-07-02 15:46:14 +02:00
|
|
|
assert.strictEqual(noErrors?.errorCount, 0)
|
|
|
|
assert.strictEqual(withErrors?.errorCount, 3)
|
2022-02-19 16:05:21 +01:00
|
|
|
})
|
|
|
|
|
2023-10-23 23:00:22 +02:00
|
|
|
test("ensure we validate correctly TypeScript files", async () => {
|
2022-02-19 16:05:21 +01:00
|
|
|
const [noErrors] = await eslint.lintFiles(
|
2023-10-23 23:00:22 +02:00
|
|
|
"test/fixtures/typescript-no-errors.ts",
|
2022-02-19 16:05:21 +01:00
|
|
|
)
|
|
|
|
const [withErrors] = await eslint.lintFiles(
|
2023-10-23 23:00:22 +02:00
|
|
|
"test/fixtures/javascript-with-errors.js",
|
2022-02-19 16:05:21 +01:00
|
|
|
)
|
2023-07-02 15:46:14 +02:00
|
|
|
assert.strictEqual(noErrors?.errorCount, 0)
|
|
|
|
assert.strictEqual(withErrors?.errorCount, 3)
|
2022-02-19 16:05:21 +01:00
|
|
|
})
|
|
|
|
|
2023-10-23 23:00:22 +02:00
|
|
|
test("ensure we allow top-level await", async () => {
|
2022-02-19 16:05:21 +01:00
|
|
|
const [lintResult] = await eslint.lintFiles(
|
2023-10-23 23:00:22 +02:00
|
|
|
"test/fixtures/top-level-await.mjs",
|
2022-02-19 16:05:21 +01:00
|
|
|
)
|
2023-07-02 15:46:14 +02:00
|
|
|
assert.strictEqual(lintResult?.errorCount, 0)
|
2022-02-19 16:05:21 +01:00
|
|
|
})
|