test(mock): reproduce manual mock ignored for workspace-linked package - #1851
Conversation
Adds an e2e/mock fixture with two workspace-linked packages: a
'styles-lib' package that ships its own manual mock colocated at
styles-lib/__mocks__/index.js (Jest's documented convention for
mocking node_modules / workspace packages), and a 'consumer' package
that mocks it with a bare rs.mock('styles-lib') call (no factory).
Rstest's manual-mock lookup only checks a single fixed
<rootPath-of-the-package-under-test>/__mocks__ directory, so it never
finds the mocked package's own colocated manual mock and silently
falls back to automocking instead. This turns the mocked makeStyles
export into a stub that returns undefined, and the consumer crashes
with 'useCardStyles is not a function'.
The new manualMockWorkspacePackage.test.ts wires the fixture into the
e2e harness via runRstestCli + expectExecFailed(), documenting the
current (buggy) behavior. Once manual-mock resolution follows the
resolved module's real path (matching Jest), this should be flipped to
expectExecSuccess().
Closes web-infra-dev#1850
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4b232e17c0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| "version": "1.0.0", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@rstest/test-mock-manual-mock-workspace-package-styles-lib": "workspace:*" |
There was a problem hiding this comment.
Add the new workspace packages to the lockfile
Both new package manifests are included by the repository's e2e/** workspace glob, but this commit adds neither corresponding importers nor their workspace link to pnpm-lock.yaml. The test workflow runs pnpm install --frozen-lockfile --prefer-offline at .github/workflows/test.yml:132 and :212, so a clean CI checkout will reject the stale lockfile before any tests run. Regenerate and commit the lockfile after adding both packages.
AGENTS.md reference: AGENTS.md:L48-L50
Useful? React with 👍 / 👎.
|
|
||
| // TODO: once manual-mock resolution follows the resolved module's real path (matching | ||
| // Jest), this should become `expectExecSuccess()` instead. | ||
| await expectExecFailed(); |
There was a problem hiding this comment.
Assert the specific manual-mock failure
When the child command exits nonzero for any reason—such as dependency resolution, configuration loading, or an unrelated runtime regression—expectExecFailed() still makes this test pass. Consequently, the test does not establish that Rstest reached the intended automock fallback or produced useCardStyles is not a function; assert that diagnostic with expectLog/expectStderrLog in addition to the exit status so unrelated failures cannot masquerade as this reproduction.
Useful? React with 👍 / 👎.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@kelleyma49 Thanks for reporting this issue and contributing the regression test! The issue has been fixed, and the test now passes. The fix will be included in Rstest 0.12. |
Adds a failing-by-design e2e fixture + test reproducing #1850.
What
e2e/mock/fixtures/manualMockWorkspacePackage/styles-lib— a workspace package that ships a manual mock colocated at its own__mocks__/index.js(Jest's documented convention for mocking node_modules / workspace packages).e2e/mock/fixtures/manualMockWorkspacePackage/consumer— a workspace-linked consumer that callsrs.mock("...")(bare, no factory) onstyles-lib.e2e/mock/tests/manualMockWorkspacePackage.test.ts— wires the fixture into the harness viarunRstestCli+expectExecFailed().Why it's written to expect failure
Rstest's manual-mock lookup only checks
<rootPath-of-the-package-under-test>/__mocks__, so it never findsstyles-lib's own colocated manual mock and falls back to automockingmakeStyles, which then returnsundefined. The consumer crashes withuseCardStyles is not a function. Jest, by contrast, resolves the real (symlinked) module path and correctly finds the colocated mock.expectExecFailed()documents this current (buggy) behavior as an explicit e2e test. Once manual-mock resolution is fixed to follow the resolved module's real path (matching Jest), this one line should be flipped toexpectExecSuccess()— that flip is intended to be the regression test for the eventual fix.Verification
pnpm install --filter ...+pnpm --filter @rstest/core run build, thenrstest rundirectly insideconsumer/→ fails withuseCardStyles is not a function.cd e2e && npx rstest run mock/tests/manualMockWorkspacePackage.test.ts(the real e2e harness) → passes, correctly asserting the CLI run currently fails.Closes #1850 (as a repro; the underlying manual-mock resolution bug is still open).
Checklist