Skip to content

Commit ef3256f

Browse files
authored
test: run the docs examples in CI (#149)
Co-authored-by: botandbang <337765928+botandbang@users.noreply.github.com>
1 parent d528a2a commit ef3256f

15 files changed

Lines changed: 552 additions & 25 deletions

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ nodevu is composed of a set of modules, each supporting Node.js 24 and later:
2323
Installing needs npm 11.17 or newer, which ships with Node.js 24 and later. `.npmrc` skips packages published in the last 3 days and blocks git and URL dependencies. npm only runs the dependency install scripts that `allowScripts` in `package.json` approves, and `npm approve-scripts <pkg>` adds one pinned to its installed version.
2424

2525
- `npm test` and `npm run coverage` run every module's tests. The tests share the release data snapshot and its helpers through `fixtures/`, a private workspace that isn't published. `npm run test:update -w fixtures` refreshes the snapshot.
26-
- `npm run lint` checks the whole repo with oxlint (warnings fail it too) and oxfmt, and checks with [docov](https://github.com/cutenode/docov) that everything the modules export has JSDoc. `docov.jsonc` sets what it scans. `npm run lint:harden` tests `tools/harden/` and runs [@lavamoat/harden](https://github.com/LavaMoat/LavaMoat/tree/main/packages/harden) to check that `.npmrc` and `package.json` keep every hardening setting, except the ones `tools/harden/decisions.json` turns off. `tools/oxlint/nodevu/` holds the repo's own oxlint rule, which stops code from reaching into another package's folder by relative path, and `npm run lint:rules` tests it. `npm run lint:pack` packs every module and checks the tarball with [publint](https://publint.dev) and [Are the Types Wrong?](https://arethetypeswrong.github.io). `npm run lint:workspaces` checks that every config naming the modules (tsconfig, CI, release, Dependabot, the docs sidebar) matches `workspaces` in `package.json`. `npm run knip` runs [knip](https://knip.dev) to find unused files, exports and dependencies. `knip.jsonc` lists what it skips and why. `npm run lint` runs all of them.
26+
- `npm run lint` checks the whole repo with oxlint (warnings fail it too) and oxfmt, and checks with [docov](https://github.com/cutenode/docov) that everything the modules export has JSDoc. `docov.jsonc` sets what it scans. `npm run lint:harden` tests `tools/harden/` and runs [@lavamoat/harden](https://github.com/LavaMoat/LavaMoat/tree/main/packages/harden) to check that `.npmrc` and `package.json` keep every hardening setting, except the ones `tools/harden/decisions.json` turns off. `tools/oxlint/nodevu/` holds the repo's own oxlint rule, which stops code from reaching into another package's folder by relative path, and `npm run lint:rules` tests it. `npm run lint:pack` packs every module and checks the tarball with [publint](https://publint.dev) and [Are the Types Wrong?](https://arethetypeswrong.github.io). `npm run lint:workspaces` checks that every config naming the modules (tsconfig, CI, release, Dependabot, the docs sidebar) matches `workspaces` in `package.json`. `npm run lint:docs` runs the JavaScript examples in `docs/pages/` with [readme-assert](https://readme-assert.laat.dev) against the `@nodevu/fixtures` snapshots, and checks each `//=> value` comment. `npm run knip` runs [knip](https://knip.dev) to find unused files, exports and dependencies. `knip.jsonc` lists what it skips and why. `npm run lint` runs all of them.
2727
- CI also checks spelling with [typos](https://github.com/crate-ci/typos) (`_typos.toml` lists words it shouldn't flag), relative links and anchors with [lychee](https://lychee.cli.rs), the workflows with [actionlint](https://github.com/rhysd/actionlint) and [zizmor](https://docs.zizmor.sh), and that a PR adds no dependency with a known advisory. A weekly run tests every module on Linux, macOS and Windows, tries 50 times as many fast-check cases, and checks external links.
2828
- `npm run types` type-checks the JSDoc, the tests and the scripts, and writes each module's TypeScript declarations to its `types/` folder. Commit them: CI fails when they're out of date.
2929
- `npm run docs:dev` builds the docs from `docs/pages/` with [doc-kit](https://doc-kit.nodejs.org/) and serves them locally. `npm run docs` only builds them, into `out/`.

‎docs/pages/aliases.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The module exports an array of them:
1818
```js
1919
const aliases = require('@nodevu/aliases');
2020

21-
aliases.includes('lts/active'); // true
21+
aliases.includes('lts/active'); //=> true
2222
```
2323

2424
## `aliases`

‎docs/pages/core.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ npm install @nodevu/core
1919
Then call it for the data:
2020

2121
```js
22-
const nodevu = require('@nodevu/core');
22+
import nodevu from '@nodevu/core';
2323

2424
const data = await nodevu();
2525

26-
console.log(data.v20.support.codename); // 'Iron'
26+
data.v20.support.codename; //=> 'Iron'
2727
```
2828

2929
## `nodevu([options])`

‎docs/pages/fetchindex.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ npm install @nodevu/fetchindex
1717
It has no defaults, so pass the `fetch` to use and the URL:
1818

1919
```js
20-
const fetchindex = require('@nodevu/fetchindex');
20+
import fetchindex from '@nodevu/fetchindex';
2121

2222
const index = await fetchindex({
2323
fetch: globalThis.fetch,

‎docs/pages/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ npm install @nodevu/core
1313
Then ask it about any release line:
1414

1515
```js
16-
const nodevu = require('@nodevu/core');
16+
import nodevu from '@nodevu/core';
1717

1818
const data = await nodevu();
1919

‎docs/pages/newest.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ npm install @nodevu/newest
1515
Pass it the name of a release line:
1616

1717
```js
18-
const { lts, security } = require('@nodevu/newest');
18+
import { lts, security } from '@nodevu/newest';
1919

20-
await lts('v16'); // '16.20.2'
21-
await security('v16'); // '16.20.2'
20+
await lts('v16'); //=> '16.20.2'
21+
await security('v16'); //=> '16.20.2'
2222
```
2323

2424
Every function fetches fresh data through [`@nodevu/core`](core.md), and

‎docs/pages/oldest.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ npm install @nodevu/oldest
1515
Pass it the name of a release line:
1616

1717
```js
18-
const { lts, security } = require('@nodevu/oldest');
18+
import { lts, security } from '@nodevu/oldest';
1919

20-
await lts('v16'); // '16.13.0'
21-
await security('v16'); // '16.4.1'
20+
await lts('v16'); //=> '16.13.0'
21+
await security('v16'); //=> '16.4.1'
2222
```
2323

2424
Every function fetches fresh data through [`@nodevu/core`](core.md), and

‎docs/pages/parsefiles.md‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ Pass it an identifier and the version it belongs to:
2121
```js
2222
const parsefiles = require('@nodevu/parsefiles');
2323

24-
parsefiles('linux-x64', '17.6.0');
25-
// {
26-
// id: 'linux-x64',
27-
// files: ['node-v17.6.0-linux-x64.tar.gz', 'node-v17.6.0-linux-x64.tar.xz'],
28-
// type: 'linux',
29-
// architecture: 'x64',
30-
// }
24+
const linux = parsefiles('linux-x64', '17.6.0');
25+
26+
linux.id; //=> 'linux-x64'
27+
linux.files; //=> ['node-v17.6.0-linux-x64.tar.gz', 'node-v17.6.0-linux-x64.tar.xz']
28+
linux.type; //=> 'linux'
29+
linux.architecture; //=> 'x64'
3130
```
3231

3332
## `parsefiles(file, version)`

‎docs/pages/ranges.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ npm install @nodevu/ranges
1717
Ask for one range, several, or all of them:
1818

1919
```js
20-
const ranges = require('@nodevu/ranges');
20+
import ranges from '@nodevu/ranges';
2121

2222
const data = await ranges(['current', 'lts/active']);
2323

24-
console.log(data.current.newest);
24+
console.log(data['lts/active'].newest);
25+
26+
// a range with no releases is left out, like `current` from when a line goes
27+
// LTS in October until the next one comes out in April
28+
console.log(data.current?.newest);
2529
```
2630
2731
## `ranges([filter[, options]])`
@@ -38,6 +42,8 @@ Rejects with an {Error} when `filter` holds an unknown alias, or is neither a
3842
string nor an array.
3943
4044
```js
45+
import ranges from '@nodevu/ranges';
46+
4147
const data = await ranges('alpha', { now: '2026-12-15' });
4248
```
4349

‎docs/pages/static.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Each export is a plain object, keyed by release line like core's result:
2020
```js
2121
const { default: data, support } = require('@nodevu/static');
2222

23-
console.log(support.v20.codename); // 'Iron'
23+
support.v20.codename; //=> 'Iron'
2424
```
2525

2626
## `static.default`

0 commit comments

Comments
 (0)