test: fix running a single test file by path on Windows - #370
Closed
nigrosimone wants to merge 1 commit into
Closed
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running one test file by path, the way the usage comment at the top of
tests/index.jsdocuments it:The category was derived with
path.dirname(filterPath).split(path.sep).pop(). On Windowspath.sepis a backslash, so a path typed with forward slashes never splitpath.dirnamereturnedtests/tests/middlewares,split('\')produced a single element, andpop()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.