Skip to content

fix: correct the fetch and translate types, await static's writes, and keep tests offline - #148

Merged
botandbang merged 6 commits into
mainfrom
bnb/test-and-type-fixes
Nov 11, 2026
Merged

botandbang merged 6 commits into
mainfrom
bnb/test-and-type-fixes

Conversation

@botandbang

Copy link
Copy Markdown
Contributor

Six small fixes the CI work turned up, one commit each.

translate's return type

translate() returns a fresh copy of its alias list, so callers can change it, but its JSDoc declared a readonly tuple. It now declares a mutable array of the same aliases, and the regenerated translate/types/index.d.ts follows. A type test in test/types.mts assigns the result to Alias[] and pushes to it. The @ts-expect-error in translate's own test now says why it's still needed: 'eol' isn't one of 'lts''s aliases.

The fetch option type

core, opt and fetchindex typed their fetch option as typeof fetch. undici's fetch doesn't match that type, since its Request has fields the global one lacks, so passing it (as the tests do, and users may) was a type error.

  • fetchindex now exports a Fetch type that describes what the modules use: a function taking a URL string and resolving to something with ok, status, statusText and json(). Both fetches fit it.
  • core's Fetch is import('@nodevu/fetchindex').Fetch, since core already depends on fetchindex. opt keeps a copy, because it depends on neither.
  • json() resolves to unknown, as undici declares it, so fetchindex and core's schedule fetcher now say what shape they expect.
  • core's schedule fetcher declares the options it reads (fetch and urls.schedule) instead of all of ParsedOptions, so its tests pass partial options without a cast.
  • The tests drop the casts through unknown they needed to pass undici's fetch.
  • test/types.mts passes both fetches to each module. undici is now a root dev dependency for that test.

static's build scripts

static/build/*.js called the async write() without awaiting it. They await it now, and their loops over Object.keys() drop a for await that a plain array doesn't need. A new test runs each build script with nowhere to write its output and expects it to exit with code 1. The top-level calls stay as they are: since Node 15 an unhandled rejection exits the process with code 1 anyway.

ranges' tests

  • unknownFilter.test.js had two identical tests. One is gone. Another test said "the first entry" where its unknown alias is the last entry, and it's renamed to match. All of them used try/catch with an if (data) throw guard that let the test pass if ranges() ever resolved to something falsy. They now use assert.rejects with the same messages.
  • matrixAlias.test.js had comments naming the wrong alias above three checks, and a duplicated "supported" test. The comments now say what each check checks, and the duplicate is gone.

Tests that fetched nodejs.org

The "should work with..." tests in core/test/schedule.js and fetchindex/test/test.js fetched the live schedule.json and index.json. They now serve the @nodevu/fixtures snapshots and assert that the default URL was requested. fetchindex gets @nodevu/fixtures as a dev dependency, and its CI path filter now includes fixtures/**. Where a test uses the global fetch, it gets mocked with t.mock.method. Where a test uses undici's fetch, an undici MockAgent with network connections disabled stands in. With network connections blocked, every module's tests pass. Two describe titles also lose a typo ("condiditons").

The snapshot refresh

fixtures/util/updateStaticData.js saved whatever JSON came back, so an error response with a JSON body would have replaced the test snapshot. It now rejects on a response that isn't ok, with the same message core's own fetch uses, and writes nothing. A test serves a 503 and checks that the script exits 1 and leaves the snapshot folder empty.

@botandbang
botandbang merged commit d528a2a into main Nov 11, 2026
36 checks passed
@botandbang
botandbang deleted the bnb/test-and-type-fixes branch November 11, 2026 21:01
@nodevu-ci nodevu-ci Bot mentioned this pull request Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants