Skip to content

fix: correct npm test script path to target root tests directory - #11

Open
snigdhaaX wants to merge 1 commit into
Parvaggarwal01:mainfrom
snigdhaaX:fix/test-runner-path
Open

fix: correct npm test script path to target root tests directory#11
snigdhaaX wants to merge 1 commit into
Parvaggarwal01:mainfrom
snigdhaaX:fix/test-runner-path

Conversation

@snigdhaaX

@snigdhaaX snigdhaaX commented Jun 3, 2026

Copy link
Copy Markdown

Description

I noticed the backend tests weren't running locally because the npm test script in package.json was 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 test works perfectly and executes all 9 unit tests (Zod schemas and IP utilities) locally and offline in under 300ms.

Changes Made

  • Updated package.json test script to "node --test tests/**/*.test.js"

Summary by CodeRabbit

  • Chores
    • Updated test execution configuration to ensure consistent test coverage and discovery.

@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The npm test script in package.json is updated to explicitly target test files matching the tests/**/*.test.js pattern, replacing the default Node test runner discovery behavior with an explicit file glob.

Changes

Test Script Scoping

Layer / File(s) Summary
Explicit test file discovery
barterly-backend/package.json
The test npm script is updated from node --test to node --test tests/**/*.test.js, explicitly scoping test discovery to files matching the project's test naming convention.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A test script now knows where to look so clean,
With tests/**/*.test.js in between,
No wandering paths, no guessing the way—
Just focused discovery, brighter today! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and specifically describes the main change: updating the npm test script path to target the root tests directory, which matches the changeset's primary alteration to package.json.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@snigdhaaX snigdhaaX changed the title fix: correct test script path in package.json to target root tests di… fix: correct npm test script path to target root tests directory Jun 3, 2026

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 54d5f37 and de5433f.

📒 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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 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:


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.

Suggested change
"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.

@snigdhaaX

Copy link
Copy Markdown
Author

Hey @Parvaggarwal01,

Just wanted to clarify the failing CI / Backend check here. The automated GitHub Actions run is failing because it's trying to connect to a live MongoDB cluster, which throws a connection error since outside forks don't have access to the project's secret environment variables.

The fix itself is a completely offline, structural change to the package.json test runner path ("node --test tests/**/*.test.js"). I verified it locally—with this path update, all 9 validation and utility unit tests run and pass perfectly in isolation in under 300ms.

Whenever you get a chance to review, this will allow contributors to cleanly run the test suite locally.

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.

1 participant