Skip to content

Make the tests pass, with a key that carries the properties they read - #8

Merged
jwrosewell merged 8 commits into
rcfrom
fix/run-test
Nov 6, 2026
Merged

jwrosewell merged 8 commits into
rcfrom
fix/run-test

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Nov 5, 2026 •

Copy link
Copy Markdown

Problem

The ua-parser-js-run-test workflow (.github/workflows/run-test.yml) has failed on every run in its history, from 3 November, including the pushes to rc and main on 4 November (run 41786620555 on main). There were six faults, each hidden behind the one before.

  1. yarn build stopped in the declarations step, with node_modules/@types/node/ffi.d.ts(94,21): error TS1139: Type parameter declaration expected and many like it. tsc -p tsconfig.json reads every @types package in node_modules, and @types/node comes in through jest and its packages at any version. There is no lockfile, so yarn installs the newest, 26.6.6, which needs TypeScript 5.6, while this package builds with TypeScript 4.9.
  2. The browser tests could not start Chrome. They call puppeteer.launch themselves, so the CI options in jest-puppeteer.config.js, which turn the sandbox off, never reach them, and on the GitHub hosted Ubuntu runner Chrome stopped with "No usable sandbox!".
  3. The test of an unknown resource key expected the cloud's old message. The cloud now answers "The resource key '...' could not be found. Check that you copied it correctly, or create a new key at ...", where the test expected "The Resource Key '...' was not found. See ... for more information.".
  4. The resource key the tests used does not carry PlatformName or PlatformVersion. The key in the USER_KEY_VALID secret, and the one written into the two browser test pages, are free CloudV5Basic keys. The cloud answers each property with null and "PlatformVersion is a paid feature", and the tests failed on null.toLowerCase().
  5. The injection test could not fail. It caught every error in its body, a failed expectation among them, logged it and passed.
  6. The injection test read the page too early. With a key that carries the location product, the cloud's script asks the browser for its location and waits for the answer before it gives the result. Headless Chrome never answers, so the result never came, and the test read the empty element after two seconds.

Change

  1. package.json gains a yarn resolutions entry that holds @types/node at 22.9.3, the newest version for TypeScript 4.9 according to its typeScriptVersion on the npm registry.
  2. The browser tests launch Chrome with --no-sandbox and --disable-setuid-sandbox when CI is set, the arguments jest-puppeteer.config.js already uses.
  3. src/__mocks__/errors.ts gives the start of the cloud's current message, which names the key, and the node integration test matches that start rather than the whole message, which goes on to say where to create a key.
  4. The test and publish workflows set USER_KEY_VALID from the organisation's _51DEGREES_RESOURCE_KEY_BESPOKE secret, a CloudV5Bespoke key that carries every property the README recommends. The two browser test pages hold the placeholder __USER_KEY_VALID__, which server.js replaces with that key as it serves them, loading .env as the tests already do, so no key is kept in the repository.
  5. The injection test only closes the browser in finally, so a failed expectation fails it.
  6. The injection test allows the page a location, as a visitor would, and waits up to 20 seconds for the page to write its result rather than two seconds. The page writes any error it meets in place of the result, and the test expects none.

Checks

  • The workflow passes on this branch, 94 of 94 tests, on the pull request and on the push (run 42124992094 and run 42124979981).
  • Before the key change, the cloud answered the happy path request with null and "PlatformVersion is a paid feature" for the repository's key, and with macOS 12.2.1 for _51DEGREES_RESOURCE_KEY_BESPOKE. Each key's accessible properties were read without printing the key.
  • In headless Chrome the injection page never resolved with any of the organisation's paid keys, each of which carries the location product, and resolved within a second with the location allowed. With the free key, which has no location product, it resolved either way.

Not changed

A page that uses UAParser without a header map, with a key that carries the location product, waits for its visitor to answer the browser's location prompt before UAParser resolves. That is how the cloud's script behaves, and this change only lets the test answer the prompt.

Release note

The tests run and pass again, with a key that carries the properties they check.

The declarations step, tsc -p tsconfig.json, reads every @types package
in node_modules, including @types/node, which jest and its packages
require at any version. There is no lockfile, so yarn installs the
newest, 26.6.6, which needs TypeScript 5.6. Its ffi.d.ts does not parse
with the TypeScript 4.9 this package builds with, so yarn build stopped
with "node_modules/@types/node/ffi.d.ts(94,21): error TS1139: Type
parameter declaration expected" in every run of the tests in the
workflow's history, from 3 November. The resolution holds @types/node
at 22.9.3, the newest version for TypeScript 4.9.
The browser tests launch their own Chrome with puppeteer.launch, so the
CI options in jest-puppeteer.config.js, which turn the sandbox off, do
not reach them. On the GitHub hosted Ubuntu runner Chrome stopped with
"No usable sandbox!", so both tests failed before reaching the page.
They now launch it with the same arguments when CI is set.
The cloud now answers "The resource key '...' could not be found. Check
that you copied it correctly, or create a new key at ...", where the test
expected "The Resource Key '...' was not found. See ... for more
information.". The test now matches the start of the message, which
names the key, and the mock gives that start as its error.
The happy path tests read PlatformName and PlatformVersion, and the key in
the USER_KEY_VALID secret is a free CloudV5Basic key, so the cloud answers
each with "PlatformVersion is a paid feature" and a null value, and the tests
fail on null.toLowerCase(). The organisation's _51DEGREES_RESOURCE_KEY_BESPOKE
key carries every property the README recommends, and the cloud answers the
happy path request with macOS 12.2.1. The test and publish workflows now use
it as USER_KEY_VALID.
The happy injection test caught every error in its body, including a failed
expectation, logged it and closed the browser, so it passed whatever the
page showed. It now only closes the browser, in finally, so a failed
expectation fails the test.
The two pages the browser tests load asked the cloud with a key written
into each page, a free key without PlatformName or PlatformVersion, so both
tests read null. server.js now puts the key from USER_KEY_VALID, which the
workflows set and .env can give locally, in place of __USER_KEY_VALID__ in
each page as it serves it, so the browser tests ask with the same key as
the Node tests and no key is kept in the repository.
The injection test read the page's result two seconds after the page
loaded, but the result is written only once the cloud's script has done its
own requests, so the test read an empty element and failed to parse it. It
now waits for the page to write the result, for up to 20 seconds. The page
writes an error it meets in place of the result, so a failure says why.
The test key carries the location product, and the cloud's script then asks
the browser for its location and waits for the answer before it resolves the
result. Headless Chrome leaves the request unanswered, so the result never
came. A check in headless Chrome showed the page resolve within a second with
the location allowed, with each of the organisation's paid keys, and never
without it. The test now allows the page a location, as a visitor would.
@jwrosewell jwrosewell changed the title Make the tests run: pin @types/node, start Chrome in CI, expect the cloud's current message Make the tests pass, with a key that carries the properties they read Nov 5, 2026
@jwrosewell
jwrosewell marked this pull request as ready for review November 6, 2026 07:10
@jwrosewell
jwrosewell merged commit b203d2f into rc Nov 6, 2026
3 checks passed
@jwrosewell
jwrosewell deleted the fix/run-test branch November 6, 2026 07:10
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.

1 participant