Skip to content

Commit

Permalink
♻️ Migrate core tests to native node test runner
Browse files Browse the repository at this point in the history
Mocha is not maintained, monkey patches `require()`, and mucks with
the module loader. Meanwhile, Node has a native test runner that is
fast, reliable, and actively maintained as part of the Node JS
project.

This gets rid of `ts-node` and `mocha` in favor of `tsx` and the
native runner. Most of the time this involves just importing from
`node:test` instead of `mocha`.

In cases where `mocha` was mushing its hooks onto the global
scope (`beforeEach()`, `afterEach()`, et al.) the function has been
explicitly imported from `node:test`.
  • Loading branch information
cowboyd committed Mar 7, 2024
1 parent d22f08f commit 32537e3
Show file tree
Hide file tree
Showing 19 changed files with 377 additions and 24 deletions.
10 changes: 4 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"clean": "rm -rf dist *.tsbuildinfo",
"lint": "eslint \"{src,test}/**/*.ts\"",
"check:types": "tsc --noEmit",
"test:unit": "mocha \"test/**/*.test.ts\"",
"test:unit": "tsx --test --no-deprecation",
"test:types": "dtslint types --localTs ../../node_modules/typescript/lib --expectOnly",
"test": "yarn test:unit && yarn test:types",
"docs": "rm -rf docs && yarn typedoc --options typedoc.json",
Expand All @@ -47,14 +47,12 @@
"@types/express": "^4.17.6",
"@types/jsdom": "^16.2.3",
"@types/lodash.isequal": "^4.5.5",
"@types/mocha": "^7.0.1",
"@types/node": "^14.17.5",
"@types/node": "^20.11.25",
"dtslint": "^4.0.5",
"expect": "^24.9.0",
"express": "^4.17.1",
"jsdom": "^16.2.2",
"mocha": "^6.2.2",
"ts-node": "^10.4.0",
"jsdom": "^24.0.0",
"tsx": "^4.7.1",
"typedoc": "^0.22.7",
"typescript": "~4.4.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/create-interactor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';
import { Datepicker, Details, Div, Header, Link, MainNav, TextField } from './fixtures';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/extend.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/filter-delegate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach } from "mocha";
import { afterEach, beforeEach } from "node:test";
import { DOMWindow, JSDOM } from "jsdom";
import { addInteractionWrapper, globals, setDocumentResolver, setInteractorTimeout } from "@interactors/globals";

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/inspector.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/interactor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';
import { Header, Link, MainNav } from './fixtures';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/locator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matchers/and.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from '../helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matchers/every.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from '../helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matchers/including.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from '../helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matchers/matching.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { beforeEach, describe, it } from 'node:test';
import expect from 'expect';
import { dom } from '../helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matchers/not.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from '../helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matchers/or.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from '../helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/matchers/some.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from '../helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/selector.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from 'mocha';
import { describe, it } from 'node:test';
import expect from 'expect';
import { dom } from './helpers';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/serialize.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it } from "mocha";
import { describe, it } from "node:test";
import expect from "expect";
import { HTML, TextField } from "./fixtures";
import { including, or } from "../src";
Expand Down
Loading

0 comments on commit 32537e3

Please sign in to comment.