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.
When I have
frontend-baseinstalled into thepackagesdirectory of frontend-app-instructor-dashboard, its tests fail with:Reason (thanks Claude!):
createConfig('test')setsrootDir: process.cwd()and leaves roots at its default ([rootDir]), sojest-haste-mapcrawls your whole app directory — includingpackages/frontend-base/. (It skipsnode_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.jspackages/frontend-base/shell/__mocks__/universal-cookie.js(the
dist/copies are excluded bymodulePathIgnorePatterns, 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 ofuniversal-cookie, and that mock is:An arrow function has no
[[Construct]], soruntime/i18n/lib.ts:10'snew Cookies()throws_universalCookie.default is not a constructor.A solution is to add
roots: ['<rootDir>/src'],tojest.config.js, or to fix the mock(s) to supportnewproperly 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.