diff --git a/index.js b/index.js index aecb72d..0c8477b 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ 'use strict'; +const fs = require('fs'); const path = require('path'); const { promisify } = require('util'); const glob = promisify(require('glob')); @@ -50,6 +51,8 @@ class TestExclude { this.exclude = prepGlobPatterns([].concat(this.exclude)); + this.cwd = fs.realpathSync(this.cwd); + this.handleNegation(); } diff --git a/test/test-exclude.js b/test/test-exclude.js index 643741c..953eff7 100644 --- a/test/test-exclude.js +++ b/test/test-exclude.js @@ -1,4 +1,5 @@ 'use strict'; +const fs = require('fs'); const path = require('path'); const t = require('tap'); @@ -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'); + 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 =>