Regression in repo - setTimeout is not defined

Viewed 7

For some reason when trying to re-run previously passing test suites I now get a Typescript build error error TS2304: Cannot find name 'setTimeout'

I think the issue is something that arrived with a more recent Typescript version and hasn't changed since. However, I don't see a lot of examples of setTimeout not being defined so I'm stuck to know what I need to change.

Does anyone know what I can do to mitigate?

The Error

The error in full...

 FAIL  test/core/partition.test.ts
  ● Test suite failed to run
    test/core/partition.test.ts:86:36 - error TS2304: Cannot find name 'setTimeout'.
    86     await new Promise((resolve) => setTimeout(resolve, 10));

The failing line is this one https://github.com/cefn/lauf/blob/f95614e808df33fe951ed0830732c40307ddeee5/modules/store/test/core/partition.test.ts#L86

The failure happens against the same checked-out commit from a repo which had CI running on every commit and which previously passed.

The commit is the latest on main... https://github.com/cefn/lauf/commit/f95614e808df33fe951ed0830732c40307ddeee5

The record that this same commit passed green in the past is at https://github.com/cefn/lauf/actions/runs/1714116971/jobs/2345711821

Unfortunately the CI build steps had pnpm install without --frozen-lockfile so it's not totally clear what minor version of each package was used when it last passed (8 months ago).

Attempts to solve

It happens whether I run pnpm install --frozen-lockfile or pnpm install. The same issue remains after running pnpm up --latest across the repo to try and upgrade e.g. jest, typescript.

The same error persists if I set compilerOptions.lib:["dom", "ES2020"] in tsconfig.json and if I add testEnvironment:"jsdom" to jest.config.js

1 Answers

Today I was implicitly running the test suite with pnpm@7 (which failed) while the test suite ran in CI implicitly 8 months ago with pnpm@6 (which passed).

Between one date and the next, pnpm@7 became the latest package so the CI build line npm install -g pnpm installed a different version in the past.

Pinning the package in CI with the line...

npm install -g pnpm@6

...brings back the green tick from passing tests. From here I will be able to update all the packages (still using pnpm@6) then try to work out if I can get the same code to pass with pnpm@7 somehow.

I still don't understand why running the suite with pnpm@7 leads to an unresolved setTimeout.

Related