Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows symlinks is-outside-dir bug #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const glob = promisify(require('glob'));
Expand Down Expand Up @@ -50,6 +51,8 @@ class TestExclude {

this.exclude = prepGlobPatterns([].concat(this.exclude));

this.cwd = fs.realpathSync(this.cwd);

this.handleNegation();
}

Expand Down
38 changes: 30 additions & 8 deletions test/test-exclude.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const fs = require('fs');
const path = require('path');
const t = require('tap');

Expand Down Expand Up @@ -59,14 +60,35 @@ t.test('does not instrument files outside cwd', t =>
);

if (process.platform === 'win32') {
t.test('does not instrument files on different drive (win32)', t =>
testHelper(t, {
options: {
cwd: 'C:\\project'
},
no: ['D:\\project\\foo.js']
})
);
t.test('does not instrument files on different drive (win32)', async t => {
const origRealPathSync = fs.realpathSync;
fs.realpathSync = s => s;
try {
await testHelper(t, {
options: {
cwd: 'C:\\project'
},
no: ['D:\\project\\foo.js']
})
} finally {
fs.realpathSync = origRealPathSync;
}
});

t.test('is not fooled by junctions (win32)', async t => {
const origRealPathSync = fs.realpathSync;
fs.realpathSync = s => s.replace(/symlink/, 'truedir');
Copy link
Author

@osher osher Feb 22, 2021

Choose a reason for hiding this comment

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

LMK if you prefer stubbing fs.realpathSync as part of testHelper

try {
await testHelper(t, {
options: {
cwd: 'C:\\project\\symlink'
},
yes: ['C:\\project\\truedir\\foo.js']
})
} finally {
fs.realpathSync = origRealPathSync;
}
});
}

t.test('can instrument files outside cwd if relativePath=false', t =>
Expand Down