Skip to content

test(mock): reproduce manual mock ignored for workspace-linked package - #1851

Merged
9aoy merged 4 commits into
web-infra-dev:mainfrom
kelleyma49:repro/manual-mock-workspace-package
Sep 16, 2026
Merged

9aoy merged 4 commits into
web-infra-dev:mainfrom
kelleyma49:repro/manual-mock-workspace-package

Conversation

@kelleyma49

Copy link
Copy Markdown
Contributor

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 calls rs.mock("...") (bare, no factory) on styles-lib.
  • e2e/mock/tests/manualMockWorkspacePackage.test.ts — wires the fixture into the harness via runRstestCli + 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 finds styles-lib's own colocated manual mock and falls back to automocking makeStyles, which then returns undefined. The consumer crashes with useCardStyles 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 to expectExecSuccess() — that flip is intended to be the regression test for the eventual fix.

Verification

  • pnpm install --filter ... + pnpm --filter @rstest/core run build, then rstest run directly inside consumer/ → fails with useCardStyles 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

  • Tests updated (or not required).
  • Documentation updated (or not required).

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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:*"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-16T08:36:38.298276Z 1938e34 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@9aoy
9aoy merged commit 4f133dd into web-infra-dev:main Sep 16, 2026
10 checks passed
@9aoy

9aoy commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

@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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Manual mock colocated inside a workspace/node_modules package's own __mocks__ is ignored (falls back to automock)

2 participants