Skip to content

fix: keep frontend-base out of a consuming app's jest crawl - #302

Merged
arbrandes merged 1 commit into
openedx:mainfrom
arbrandes:arbrandes/fix-jest-mock-leak
Aug 29, 2026
Merged

fix: keep frontend-base out of a consuming app's jest crawl#302
arbrandes merged 1 commit into
openedx:mainfrom
arbrandes:arbrandes/fix-jest-mock-leak

Conversation

@arbrandes

@arbrandes arbrandes commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Description

When frontend-base is checked out into a consuming app's packages/ directory, every one of that app's test suites fails to start with TypeError: _universalCookie.default is not a constructor.

jest-haste-map crawls the whole app, packages/ included, and registers the two __mocks__/universal-cookie.js files it finds there. A manual mock for a node module is applied automatically, with no jest.mock() call, and that mock body is an arrow function, which cannot be constructed. The same crawl also collects frontend-base's own suites and runs them as the app's.

Both mocks were already unreachable inside frontend-base, since each setupTest.js registers its own factory. They are deleted rather than repaired: a working mock would still silently stub a third-party package in every consuming suite. The remaining asset mocks are only moduleNameMapper targets, so they move to testMocks/.

createConfig('test') now excludes <rootDir>/packages/, where the migration guide already says gitignored dev bind-mounts live. roots: ['<rootDir>/src'] would also work, but it hard-errors for an app without a src/ directory and silently drops any suite outside it - frontend-app-authoring keeps nine under plugins/. It is documented as an opt-in instead.

test-site gains a jest config and two smoke tests, giving the shipped test config its first coverage.

Fixes #287

LLM usage notice

Built with assistance from Claude.

A checkout in an app's packages/ directory was crawled by jest-haste-map,
which registered frontend-base's manual mock of universal-cookie for every
one of the app's test suites and collected frontend-base's own suites
alongside the app's.  That mock is not constructible, so every suite failed
to start.

The universal-cookie mocks were unreachable inside frontend-base anyway,
since both setupTest files register their own factory.  The remaining asset
mocks move out of __mocks__ so they are no longer registered as manual mocks
at all.

test-site now runs a jest suite of its own, giving the shipped test config
its first coverage.

Fixes openedx#287

Co-Authored-By: Claude <noreply@anthropic.com>
@arbrandes
arbrandes enabled auto-merge (rebase) August 29, 2026 12:49
@arbrandes
arbrandes merged commit 96ff188 into openedx:main Aug 29, 2026
5 checks passed
@openedx-semantic-release-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.0.0-alpha.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jest fails with universal-cookie error when frontend-base is in packages

2 participants