From f55e5378eb515080691dec45e907a61d02648b5f Mon Sep 17 00:00:00 2001 From: Nigro Simone Date: Sat, 1 Aug 2026 08:11:24 +0200 Subject: [PATCH] test: fix running a single test file by path on Windows `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. --- tests/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/index.js b/tests/index.js index 9d68fe3..db7dc3f 100644 --- a/tests/index.js +++ b/tests/index.js @@ -21,7 +21,10 @@ if(filterPath) { if(!filterPath.endsWith('.js')) { testCategories = testCategories.filter(category => category.startsWith(path.basename(filterPath))); } else { - testCategories = [path.dirname(filterPath).split(path.sep).pop()]; + // basename, not split(path.sep): on Windows path.sep is a backslash, so a path typed with + // forward slashes never split and the whole "tests/tests/middlewares" came back as the + // category name. path.basename handles either separator on both platforms + testCategories = [path.basename(path.dirname(filterPath))]; } }