fix: correct npm test script path to target root tests directory - #11
fix: correct npm test script path to target root tests directory#11snigdhaaX wants to merge 1 commit into
Conversation
|
@snigdhaaX is attempting to deploy a commit to the Parv Aggarwal's projects Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe npm test script in ChangesTest Script Scoping
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@barterly-backend/package.json`:
- Line 9: Update the npm "test" script in package.json to quote the glob so it
is passed verbatim to Node across platforms; change the "test" script value
referenced by the "test" key (currently node --test tests/**/*.test.js) to use a
quoted glob (e.g., "tests/**/*.test.js") so shells on Windows and POSIX behave
consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2cc46312-05df-4376-83b7-11f481741264
📒 Files selected for processing (1)
barterly-backend/package.json
| "start": "node -r dotenv/config server.js", | ||
| "dev": "node -r dotenv/config --watch server.js", | ||
| "test": "node --test", | ||
| "test": "node --test tests/**/*.test.js", |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Node.js test runner glob pattern best practices for npm scripts cross-platform
💡 Result:
To use glob patterns effectively and portably with the Node.js test runner in npm scripts, you must always enclose your patterns in quotes [1][2]. This practice prevents the host operating system's shell (e.g., bash, zsh, or cmd.exe) from attempting to expand the glob before the Node.js test runner receives it [1][3][4]. Key Best Practices for Cross-Platform npm Scripts: 1. Always Quote Patterns: Use double quotes around glob patterns in your package.json scripts to ensure they are passed as literal strings to the Node.js process [1][3]. This is non-negotiable for cross-platform compatibility, as different shells handle unquoted glob expansion inconsistently or not at all [3][5][6]. Example: "test": "node --test "/*.test.js"" [3] 2. Use Forward Slashes: Regardless of the operating system (including Windows), always use forward slashes (/) as path separators in your glob patterns [7]. Glob implementations typically interpret backslashes () as escape characters rather than directory separators [7]. 3. Rely on Node.js Globbing: By quoting your patterns, you delegate the responsibility of glob expansion to the Node.js test runner itself, which provides consistent behavior across different environments [1][6]. The built-in test runner supports standard glob syntax [1][8]. 4. Avoid Shell-Specific Syntax: Since npm scripts execute via different shells depending on the platform (/bin/sh on POSIX, cmd.exe on Windows), avoid relying on shell-dependent features like brace expansion or unquoted globstars [5][9][6]. Sticking to quoted, standard glob patterns ensures the script behaves the same way on every machine [5][6]. 5. Troubleshooting: If you encounter issues where files are not found, verify that you are running a Node.js version that supports glob patterns (Node.js 21+ for native glob support in the test runner) [3]. If patterns remain unexpanded, confirm they are properly quoted in the package.json file [3][6]. Top Results: [1], [3], [9], [7]
Citations:
- 1: https://nodejs.org/docs/latest-v26.x/api/test.html
- 2: https://beta.docs.nodejs.org/test.html
- 3: node:test --test with glob patterns and npm can't find files nodejs/node#50658
- 4: https://stackoverflow.com/questions/72262156/using-glob-in-yarn-npm-script
- 5: How to run the Node built-in testrunner for TypeScript files inside a specific directory? nodejs/help#3902
- 6: https://medium.com/@jakubsynowiec/you-should-always-quote-your-globs-in-npm-scripts-621887a2a784
- 7: https://registry.npmjs.org/glob
- 8: nodejs/node@7cd4e70948
- 9: https://docs.npmjs.com/cli/v11/commands/npm-run-script/
Quote the glob in the npm test script for cross-platform consistency.
Unquoted globs can be expanded or handled differently depending on the host shell/OS; quoting ensures Node receives the intended pattern.
🔧 Proposed fix
- "test": "node --test tests/**/*.test.js",
+ "test": "node --test \"tests/**/*.test.js\"",📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "test": "node --test tests/**/*.test.js", | |
| "test": "node --test \"tests/**/*.test.js\"", |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@barterly-backend/package.json` at line 9, Update the npm "test" script in
package.json to quote the glob so it is passed verbatim to Node across
platforms; change the "test" script value referenced by the "test" key
(currently node --test tests/**/*.test.js) to use a quoted glob (e.g.,
"tests/**/*.test.js") so shells on Windows and POSIX behave consistently.
|
Hey @Parvaggarwal01, Just wanted to clarify the failing The fix itself is a completely offline, structural change to the Whenever you get a chance to review, this will allow contributors to cleanly run the test suite locally. |
Description
I noticed the backend tests weren't running locally because the
npm testscript inpackage.jsonwas just a placeholder and didn't specify a file path.Since the
tests/folder is located at the root of the backend directory, I updated the script path so Node's native test runner can find it.Now, running
npm testworks perfectly and executes all 9 unit tests (Zod schemas and IP utilities) locally and offline in under 300ms.Changes Made
package.jsontest script to"node --test tests/**/*.test.js"Summary by CodeRabbit