Skip to content

Commit 1a05577

Browse files
committed
feat: start using the Node.js test runner and the Chai.js assertions
For a long time I wanted to get rid of the AVA test runner. * AVA does not allow nested tests and test suites. * AVA has a very minimal set of assertion functions. * AVA runs tests concurrently and it causes too many troubles. Now that the Node.js test runner has finally matured in version 22, it's about time to start using it. After me migrated the project to EcmaScript modules, it became possible to import the Chai.js 5.0 assertion library. It has a really nice API and it's a pleasure to work with it. Unlike other libraries, Chai.js does not pollute the global namespace, has no `magic` functionality, feels lightweight.
1 parent bb129b7 commit 1a05577

24 files changed

+542
-504
lines changed

eslint.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import js from "@eslint/js";
44
import keybr from "@keybr/scripts/eslint-plugin-keybr.js";
55
import confusingBrowserGlobals from "confusing-browser-globals";
66
import ava from "eslint-plugin-ava";
7+
import chaiExpect from "eslint-plugin-chai-expect";
78
import formatjs from "eslint-plugin-formatjs";
89
import node from "eslint-plugin-n";
910
import react from "eslint-plugin-react";
@@ -33,6 +34,7 @@ export default [
3334
react.configs.flat["jsx-runtime"],
3435
node.configs["flat/recommended-module"],
3536
ava.configs["flat/recommended"],
37+
chaiExpect.configs["recommended-flat"],
3638
keybr.configs["recommended"],
3739
{
3840
ignores: ["packages/server/**", "packages/server-cli/**"],
@@ -101,6 +103,11 @@ export default [
101103
"n/prefer-node-protocol": "error",
102104
"n/prefer-promises/dns": "error",
103105
"n/prefer-promises/fs": "error",
106+
// configure chai-expect
107+
"chai-expect/no-inner-compare": "error",
108+
"chai-expect/no-inner-literal": "error",
109+
"chai-expect/missing-assertion": "error",
110+
"chai-expect/terminating-properties": "error",
104111
},
105112
languageOptions: {
106113
globals: {

package-lock.json

+93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@
7878
"@testing-library/dom": "^10.4.0",
7979
"@testing-library/react": "^16.0.1",
8080
"@testing-library/user-event": "^14.5.2",
81+
"@types/chai": "^5.0.0",
8182
"@types/node": "^22.7.7",
8283
"@types/react": "^18.3.11",
8384
"@types/react-dom": "^18.3.1",
8485
"ava": "^6.1.3",
86+
"chai": "^5.1.1",
8587
"cheerio": "^1.0.0",
8688
"confusing-browser-globals": "^1.0.11",
8789
"typescript": "^5.6.3"
+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import test from "ava";
1+
import { test } from "node:test";
2+
import { assert } from "chai";
23
import { crc32 } from "./crc32.ts";
34

4-
test("compute checksum", (t) => {
5-
t.is(crc32(Buffer.from("")), 0);
6-
t.is(crc32(Buffer.from("\u0000")), 0xd202ef8d);
7-
t.is(crc32(Buffer.from("hello")), 0x3610a686);
5+
test("compute checksum", () => {
6+
assert.strictEqual(crc32(Buffer.from("")), 0);
7+
assert.strictEqual(crc32(Buffer.from("\u0000")), 0xd202ef8d);
8+
assert.strictEqual(crc32(Buffer.from("hello")), 0x3610a686);
89
});

0 commit comments

Comments
 (0)