Skip to content

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

Closed

Description

@bradenmacdonald

When I have frontend-base installed into the packages directory of frontend-app-instructor-dashboard, its tests fail with:

 FAIL  src/Main.test.tsx
  ● Test suite failed to run

    TypeError: _universalCookie.default is not a constructor

       8 | import { publish } from '../subscriptions';
       9 |
    > 10 | const cookies = new Cookies();
         |                 ^

Reason (thanks Claude!):

createConfig('test') sets rootDir: process.cwd() and leaves roots at its default ([rootDir]), so jest-haste-map crawls your whole app directory — including packages/frontend-base/. (It skips node_modules, so when frontend-base comes from npm as usual, its __mocks__ folders are invisible). Now that it's a real workspace directory, two of them get registered:

  • packages/frontend-base/runtime/__mocks__/universal-cookie.js
  • packages/frontend-base/shell/__mocks__/universal-cookie.js
    (the dist/ copies are excluded by modulePathIgnorePatterns, which is why it's exactly two.)

For a node module, a registered manual mock is applied automatically — no jest.mock() call needed. So every one of your test suites silently gets frontend-base's mock of universal-cookie, and that mock is:

module.exports = () => mockCookiesImplementation;

An arrow function has no [[Construct]], so runtime/i18n/lib.ts:10's new Cookies() throws _universalCookie.default is not a constructor.

A solution is to add roots: ['<rootDir>/src'], to jest.config.js, or to fix the mock(s) to support new properly like the code they're mocking.


Side node: jest-haste-map is always throwing warnings about duplicate mocks, and I'm unclear why we're using it at all.

Activity

  1. added theissue type on Aug 20, 2026
  2. added this to the Willow Cutoff milestone on Aug 20, 2026
  3. self-assigned this
    on Aug 28, 2026
  4. moved this from Todo to In Progress in frontend-baseon Aug 29, 2026
  5. openedx-semantic-release-bot commented on Aug 29, 2026

    @openedx-semantic-release-bot

    🎉 This issue has been resolved in version 2.0.0-alpha.6 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  6. moved this from In Progress to Done in frontend-baseon Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions