Skip to content

test: fix running a single test file by path on Windows - #370

Closed
nigrosimone wants to merge 1 commit into
dimdenGD:mainfrom
nigrosimone:test/windows-path-filter
Closed

test: fix running a single test file by path on Windows#370
nigrosimone wants to merge 1 commit into
dimdenGD:mainfrom
nigrosimone:test/windows-path-filter

Conversation

@nigrosimone

@nigrosimone nigrosimone commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Running one test file by path, the way the usage comment at the top of tests/index.js documents it:

$ node tests/index.js tests/tests/middlewares/body-limit-chunked.js

ENOENT: no such file or directory, scandir
'...\ultimate-express\tests\tests\tests\tests\middlewares'

The category was derived with path.dirname(filterPath).split(path.sep).pop(). On Windows path.sep is a backslash, so a path typed with forward slashes never split path.dirname returned tests/tests/middlewares, split('\') produced a single element, and pop() handed back the whole thing as the category name. It was then joined onto the tests directory again, hence the doubled path.

path.basename(path.dirname(filterPath)) handles either separator on both platforms.

Verified on Windows with all four forms forward slashes, backslashes, a leading ./, and a bare filename and by running the same file both ways and confirming it selects one test rather than the whole category.

`node tests/index.js tests/tests/middlewares/body-limit-chunked.js` failed with

  ENOENT: no such file or directory, scandir
  '...\tests\tests\tests\tests\middlewares'

The category was derived with `path.dirname(filterPath).split(path.sep).pop()`.
On Windows `path.sep` is a backslash, so a path typed with forward slashes -
which is what the usage comment at the top of the file shows - never split, and
the whole "tests/tests/middlewares" came back as the category name and was then
joined onto the tests directory again.

path.basename handles either separator on both platforms. Verified with forward
slashes, backslashes, a leading ./ and a bare filename.
@dimdenGD dimdenGD closed this Aug 2, 2026
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.

2 participants