Skip to content

Commit

Permalink
use node test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
iamnapo committed May 7, 2023
1 parent 84afc20 commit 0b37879
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
],
"scripts": {
"lint": "eslint . --ext .js,.mjs --cache",
"test": "npm run lint && ava -v"
"test": "npm run lint && node --test"
},
"eslintConfig": {
"extends": ".",
Expand Down Expand Up @@ -64,7 +64,6 @@
"eslint-plugin-unicorn": "^47.0.0"
},
"devDependencies": {
"ava": "^5.2.0",
"eslint": "^8.40.0",
"typescript": "^5.0.4"
},
Expand Down
16 changes: 9 additions & 7 deletions test/default.test.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import test from "ava";
import test from "node:test";
import assert from "node:assert";

import { ESLint } from "eslint";

import config from "../index.js";

const isObject = (value) => value && typeof value === "object" && value.constructor === Object;

test("load config in eslint to validate all rule syntax is correct", async (t) => {
test("load config in eslint to validate all rule syntax is correct", async () => {
const linter = new ESLint();
const code = `
const foo = 1;
const bar = () => {};
bar(foo);
`.replaceAll("\t", "");
const [{ errorCount }] = await linter.lintText(code);
t.is(errorCount, 0);
assert.equal(errorCount, 0);
});

test("test basic properties of config", (t) => {
test("test basic properties of config", () => {
const { env, plugins, rules } = config;

t.true(isObject(env));
t.true(Array.isArray(plugins));
t.true(isObject(rules));
assert.ok(isObject(env));
assert.ok(Array.isArray(plugins));
assert.ok(isObject(rules));
});
14 changes: 8 additions & 6 deletions test/react-typescript.test.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import test from "ava";
import test from "node:test";
import assert from "node:assert";

import { ESLint } from "eslint";

import config from "../react-typescript.js";

const isObject = (value) => value && typeof value === "object" && value.constructor === Object;

test("load config in eslint to validate all rule syntax is correct", async (t) => {
test("load config in eslint to validate all rule syntax is correct", async () => {
const linter = new ESLint({ overrideConfigFile: "react-typescript.js", overrideConfig: { rules: { "import/no-unresolved": "off" } } });
const code = `
import ReactDOM from "react-dom";
Expand All @@ -14,12 +16,12 @@ test("load config in eslint to validate all rule syntax is correct", async (t) =
ReactDOM.render(element, document.querySelector("#root"));
`.replaceAll("\t", "");
const [{ errorCount }] = await linter.lintText(code);
t.is(errorCount, 1);
assert.equal(errorCount, 1);
});

test("test basic properties of config", (t) => {
test("test basic properties of config", () => {
const { plugins, rules } = config;

t.true(Array.isArray(plugins));
t.true(isObject(rules));
assert.ok(Array.isArray(plugins));
assert.ok(isObject(rules));
});
16 changes: 9 additions & 7 deletions test/react.test.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import test from "ava";
import test from "node:test";
import assert from "node:assert";

import { ESLint } from "eslint";

import config from "../react.js";

const isObject = (value) => value && typeof value === "object" && value.constructor === Object;

test("load config in eslint to validate all rule syntax is correct", async (t) => {
test("load config in eslint to validate all rule syntax is correct", async () => {
const linter = new ESLint({ overrideConfigFile: "react.js", overrideConfig: { rules: { "import/no-unresolved": "off" } } });
const code = `
import ReactDOM from "react-dom";
Expand All @@ -14,13 +16,13 @@ test("load config in eslint to validate all rule syntax is correct", async (t) =
ReactDOM.render(element, document.querySelector("#root"));
`.replaceAll("\t", "");
const [{ errorCount }] = await linter.lintText(code);
t.is(errorCount, 0);
assert.equal(errorCount, 0);
});

test("test basic properties of config", (t) => {
test("test basic properties of config", () => {
const { env, plugins, rules } = config;

t.true(isObject(env));
t.true(Array.isArray(plugins));
t.true(isObject(rules));
assert.ok(isObject(env));
assert.ok(Array.isArray(plugins));
assert.ok(isObject(rules));
});
14 changes: 8 additions & 6 deletions test/typescript.test.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import test from "ava";
import test from "node:test";
import assert from "node:assert";

import { ESLint } from "eslint";

import config from "../typescript.js";

const isObject = (value) => value && typeof value === "object" && value.constructor === Object;

test("load config in eslint to validate all rule syntax is correct", async (t) => {
test("load config in eslint to validate all rule syntax is correct", async () => {
const linter = new ESLint({ overrideConfigFile: "typescript.js" });
const code = `
const foo = 1;
const bar = () => {};
bar(foo);
`.replaceAll("\t", "");
const [{ errorCount }] = await linter.lintText(code);
t.is(errorCount, 1);
assert.equal(errorCount, 1);
});

test("test basic properties of config", (t) => {
test("test basic properties of config", () => {
const { plugins, rules } = config;

t.true(Array.isArray(plugins));
t.true(isObject(rules));
assert.ok(Array.isArray(plugins));
assert.ok(isObject(rules));
});

0 comments on commit 0b37879

Please sign in to comment.