Skip to content

Check that flow-typed/jest.js covers the jest-mock MockInstance API - #2165

Closed
vzaidman wants to merge 2 commits into
react:mainfrom
vzaidman:check-jest-libdef
Closed

vzaidman wants to merge 2 commits into
react:mainfrom
vzaidman:check-jest-libdef

Conversation

@vzaidman

@vzaidman vzaidman commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

flow-typed/jest.js is hand-maintained, so it drifted from the Jest API: it was missing getMockImplementation() until #2163, and the missing declaration surfaced only as an internal Flow error, hidden in OSS behind $FlowFixMe[prop-missing].

scripts/tests/checkJestLibdef-test.js fails when a jest-mock MockInstance method is missing from JestMockFn, comparing against the jest-mock types pinned in node_modules (jest-mock internals _isMockFunction / _protoImpl are intentionally excluded). The next omission fails OSS CI instead of internal Flow. Member extraction uses the TypeScript compiler API for the .d.ts side and flow-parser for the Flow side, not regexes over source text.

Generating flow-typed/jest.js from the TypeScript definitions was evaluated and is not viable: flowgen 1.21.0 crashes on jest-mock's own index.d.ts (TypeError in its printer), and the file also covers more than jest-mock (expect, test, fake timers) from several sources, so there is no single TS source to generate it from. flow-api-translator in this repo goes the other direction (Flow to TS).

It brings the libdef up to date first, adding getMockName() and withImplementation().

Validation:

  • Test fails on the previous libdef reporting exactly the missing methods, passes with them; removing getMockName from the libdef makes the parser-based test fail reporting exactly getMockName.
  • OSS flow focus-check on Server-test.js: 0 errors. prettier --check: pass.

flow-typed/jest.js is hand-maintained, so it drifted from the Jest API: it was missing getMockImplementation() until react#2163, and the missing declaration surfaced only as an internal Flow error, hidden in OSS behind $FlowFixMe[prop-missing]. scripts/__tests__/checkJestLibdef-test.js fails when a jest-mock MockInstance method is missing from JestMockFn, so the next omission fails OSS CI instead. It brings the libdef up to date first, adding getMockName() and withImplementation().
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 3, 2026
@vzaidman
vzaidman marked this pull request as draft November 3, 2026 20:16
Extract MockInstance members with the TypeScript compiler API and JestMockFn members with flow-parser, instead of brace counting and regexes over source text.
@vzaidman

vzaidman commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Dropping this: the check is too specific and sketchy. The libdef additions (getMockName, withImplementation) go with it; getMockImplementation stays via #2163.

@vzaidman vzaidman closed this Nov 3, 2026
@vzaidman
vzaidman deleted the check-jest-libdef branch November 3, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. needs-meta-import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant