Skip to content

test_runner: remove stray quotes from module mock error - #67569

Open
farisbasha wants to merge 2 commits into
nodejs:mainfrom
farisbasha:test-runner-mock-error-quotes
Open

farisbasha wants to merge 2 commits into
nodejs:mainfrom
farisbasha:test-runner-mock-error-quotes

Conversation

@farisbasha

Copy link
Copy Markdown
Contributor

The generated CommonJS mock source threw
new Error('${JSONStringify(kBadExportsMessage)}'). JSONStringify already returns a quoted string literal, so the extra single quotes made the double quotes part of the message:
"Cannot create mock because ...". Pass the JSON literal directly and check the start of the message in the test.

Disclosure: I used an AI assistant to help find this and draft the change and this description.

The generated CommonJS mock source threw
new Error('${JSONStringify(kBadExportsMessage)}'). JSONStringify
already returns a quoted string literal, so the extra single quotes
made the double quotes part of the message:
"Cannot create mock because ...". Pass the JSON literal directly and
check the start of the message in the test.

Signed-off-by: farisbasha <farisbashatm@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Nov 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

Caution

AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context.

@MikeMcC399

Copy link
Copy Markdown
Member

The recommendations in:

advise you should tackle only one issue at a time and that you should not open any new PRs until your first PR has been approved.

You already have another unapproved PR #67555 open at this time.

Until the first PR has been approved and has landed in the main branch, GitHub classifies you as "first-time contributor". Each PR commit you push needs to be individually approved by team members to run in GitHub Actions CI. This causes delays for you as a contributor, and it adds to the work load for the team.

Waiting until the first PR has landed ensures that you as a contributor have experienced the complete process from PR submission to successful landing. After this has been completed, any new PRs or new commits to an existing PR are treated to rules for regular Contributors. GitHub Actions CI workflows are then run automatically without intervention by a team member.

@farisbasha

Copy link
Copy Markdown
Contributor Author

Thanks for the guidance and for pointing me to the first-time contributor docs. Understood - I'll focus on getting #67555 approved and landed first, and won't open any new PRs here until then.

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.71%. Comparing base (9305353) to head (f7a0dac).
⚠️ Report is 55 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #67569    +/-   ##
========================================
  Coverage   90.71%   90.71%            
========================================
  Files         801      801            
  Lines      280740   280945   +205     
  Branches    54171    54245    +74     
========================================
+ Hits       254661   254871   +210     
+ Misses      16258    16253     -5     
  Partials     9821     9821            
Files with missing lines Coverage Δ
lib/internal/test_runner/mock/loader.js 99.35% <100.00%> (+<0.01%) ⬆️

... and 58 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@farisbasha

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the clear explanation of the fix!

@Renegade334 Renegade334 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is fine, although since it's a constant, it would make more sense to wrap JSONStringify around the original definition of kBadExportsMessage, rather than re-stringifying it on every error with the same result.

Signed-off-by: farisbasha <farisbashatm@gmail.com>
@farisbasha

Copy link
Copy Markdown
Contributor Author

Thanks @Renegade334, good point. I couldn't wrap the definition itself because kBadExportsMessage is also exported and thrown directly in mock.js (throw new Error(kBadExportsMessage)), so I added a kBadExportsMessageSource constant that stringifies it once at load time and used that in the generated source. Thanks @jasnell for the review too.

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

Labels

agentscan:automated-account needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants