Skip to content

Commit

Permalink
Add unit tests for "staying on the same page when switching versions"…
Browse files Browse the repository at this point in the history
… functionality

This is meant to simplify checking correctness of code like #7227 and fixing bugs like #7226. In fact, I'm hoping to eventually make this code general enough that it runs locally with `mike serve`.

I picked `mocha` as the testing library because its Typescript support
relies on ts-node, which this project already relies on. I have little experience with `mocha` vs `jest` vs something else beyond this commit.

See also https://github.com/mochajs/mocha-examples/tree/main/packages/typescript

Instead of using `chai`, I'm using Node's assert package.
Its TS types are in `@types/node`. It should be trivial, and might be good, to switch to `chai` or something else.

This setup is not perfect, in particular I can't get tests to import the whole `index.ts` file. This is why the function being tested gets its own file. Importing `index.ts` would seem to require writing some DOM shims and be a general headache.

For the record, using `tsx` and `jsdom-global` instead of `ts-node` to run `mocha` seemed like the most promising approach, but it still failed since some files imported from this `index.ts` rely on the DOM having some particular structure in their top-level definitions.
  • Loading branch information
ilyagr committed Jul 8, 2024
1 parent dea244c commit 2d9d7cb
Show file tree
Hide file tree
Showing 4 changed files with 801 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extension": ["ts"],
"spec": "src/**/**.test.ts",
"require": "ts-node/register"
}
Loading

0 comments on commit 2d9d7cb

Please sign in to comment.