Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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