Skip to content

Commit

Permalink
Fix: when converting to patterns to directories, append path.sep to p…
Browse files Browse the repository at this point in the history
…revent overlapping dirs from being omitted. Fixes gh-135
  • Loading branch information
rwaldron committed Mar 23, 2020
1 parent f7fd157 commit 76bd8b2
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/test-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function patternsToDirectories(patterns) {
return true;
});

return parts.join(path.sep)
return `${parts.join(path.sep)}${path.sep}`;
})
.filter((name) => name !== '')
// Remove elements that would cause the same files to be visited more than
Expand All @@ -50,7 +50,7 @@ function patternsToDirectories(patterns) {
// All other values are unique and should be allowed
return true;
});
});
}).map(dir => dir.slice(0, -1));
}

class TestStream extends Subject {
Expand Down
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/collateral-nested-similar-names/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version": "3.0.0"}
6 changes: 6 additions & 0 deletions test/collateral-nested-similar-names/test/get/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---
description: Should not test in sloppy mode
flags: [onlyStrict]
expected:
pass: true
---*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---
description: Should not test in sloppy mode
flags: [onlyStrict]
expected:
pass: true
---*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---
description: Should not test in sloppy mode
flags: [onlyStrict]
expected:
pass: true
---*/
38 changes: 34 additions & 4 deletions test/file-matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ const path = require('path');
const tap = require('tap');

const sameMembers = (assert, actual, expected) => {
const expectedSet = expected.map((expectedMember) => {
return expectedMember.split('/').join(path.sep);
});
assert.equal(actual.length, expected.length);
const expectedSet = expected.map((expectedMember) => path.normalize(expectedMember));
assert.equal(actual.length, expected.length, `
Expected:
${actual}
to have the same length as:
${expected}
`);

for (let actualMember of actual) {
assert.assert(expectedSet.includes(actualMember), actualMember);
Expand Down Expand Up @@ -102,6 +108,30 @@ tap.test('file matching: file names (siblings)', assert => {
}).then(assert.done, assert.fail);
});

tap.test('file matching: directories with name overlap', assert => {
run([
'test/collateral-nested-similar-names/test/get/index.js',
'test/collateral-nested-similar-names/test/getOwnPropertyDescriptor/index.js',
'test/collateral-nested-similar-names/test/getPrototypeOf/index.js',
])
.then((results) => {
const files = results.map((result) => result.file);
const relativePaths = results.map((result) => result.relative);
const expectedFiles = [
'test/collateral-nested-similar-names/test/get/index.js',
'test/collateral-nested-similar-names/test/getOwnPropertyDescriptor/index.js',
'test/collateral-nested-similar-names/test/getPrototypeOf/index.js',
];
sameMembers(assert, files, expectedFiles);
const expectedRelPaths = [
'get/index.js',
'getOwnPropertyDescriptor/index.js',
'getPrototypeOf/index.js',
];
sameMembers(assert, relativePaths, expectedRelPaths);
}).then(assert.done, assert.fail);
});

tap.test('file matching: file names (subdirectory first)', assert => {
run([
'test/collateral-nested/test/evens/deep/26.js',
Expand Down

0 comments on commit 76bd8b2

Please sign in to comment.