From 6bc104fc1e2ee03b99d49127c413cbd841e620d0 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Thu, 11 Jul 2019 19:20:51 -0400 Subject: [PATCH] chore: Fix windows testing --- test/nyc-index.js | 66 --------------------------------- test/should-instrument.js | 78 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 66 deletions(-) create mode 100644 test/should-instrument.js diff --git a/test/nyc-index.js b/test/nyc-index.js index 2b7fb1805..40fefd096 100644 --- a/test/nyc-index.js +++ b/test/nyc-index.js @@ -88,72 +88,6 @@ describe('nyc', function () { }) }) - describe('shouldInstrumentFile', function () { - it('should exclude appropriately with defaults', function () { - var nyc = new NYC(configUtil.buildYargs('/cwd').parse([ - '--exclude=test/**', - '--exclude=test{,-*}.js', - '--exclude=**/*.test.js', - '--exclude=**/__tests__/**' - ])) - - // nyc always excludes "node_modules/**" - nyc.exclude.shouldInstrument('/cwd/foo.js', 'foo.js').should.equal(true) - nyc.exclude.shouldInstrument('/cwd/node_modules/bar.js', 'node_modules/bar.js').should.equal(false) - nyc.exclude.shouldInstrument('/cwd/foo/node_modules/bar.js', 'foo/node_modules/bar.js').should.equal(false) - nyc.exclude.shouldInstrument('/cwd/test.js', 'test.js').should.equal(false) - nyc.exclude.shouldInstrument('/cwd/testfoo.js', 'testfoo.js').should.equal(true) - nyc.exclude.shouldInstrument('/cwd/test-foo.js', 'test-foo.js').should.equal(false) - nyc.exclude.shouldInstrument('/cwd/lib/test.js', 'lib/test.js').should.equal(true) - nyc.exclude.shouldInstrument('/cwd/foo/bar/test.js', './test.js').should.equal(false) - nyc.exclude.shouldInstrument('/cwd/foo/bar/test.js', '.\\test.js').should.equal(false) - nyc.exclude.shouldInstrument('/cwd/foo/bar/foo.test.js', './foo.test.js').should.equal(false) - nyc.exclude.shouldInstrument('/cwd/foo/bar/__tests__/foo.js', './__tests__/foo.js').should.equal(false) - }) - - it('should exclude appropriately with config.exclude', function () { - var nyc = new NYC(configUtil.buildYargs(fixtures).parse()) - - // fixtures/package.json configures excludes: "blarg", "blerg" - nyc.exclude.shouldInstrument('blarg.js', 'blarg.js').should.equal(false) - nyc.exclude.shouldInstrument('blarg/foo.js', 'blarg/foo.js').should.equal(false) - nyc.exclude.shouldInstrument('blerg.js', 'blerg.js').should.equal(false) - nyc.exclude.shouldInstrument('./blerg.js', './blerg.js').should.equal(false) - nyc.exclude.shouldInstrument('./blerg.js', '.\\blerg.js').should.equal(false) - }) - - it('should exclude outside of the current working directory', function () { - var nyc = new NYC(configUtil.buildYargs('/cwd/foo/').parse()) - nyc.exclude.shouldInstrument('/cwd/bar.js', '../bar.js').should.equal(false) - }) - - it('should not exclude if the current working directory is inside node_modules', function () { - var nyc = new NYC(configUtil.buildYargs('/cwd/node_modules/foo/').parse()) - nyc.exclude.shouldInstrument('/cwd/node_modules/foo/bar.js', './bar.js').should.equal(true) - nyc.exclude.shouldInstrument('/cwd/node_modules/foo/bar.js', '.\\bar.js').should.equal(true) - }) - - it('allows files to be explicitly included, rather than excluded', function () { - var nyc = new NYC(configUtil.buildYargs('/cwd/').parse(['--include=foo.js'])) - - nyc.exclude.shouldInstrument('/cwd/foo.js', 'foo.js').should.equal(true) - nyc.exclude.shouldInstrument('/cwd/index.js', 'index.js').should.equal(false) - }) - - it('exclude overrides include', function () { - var nyc = new NYC(configUtil.buildYargs('/cwd/').parse([ - '--include=foo.js', - '--include=test.js', - '--exclude=**/node_modules/**', - '--exclude=test/**', - '--exclude=test{,-*}.js' - ])) - - nyc.exclude.shouldInstrument('/cwd/foo.js', 'foo.js').should.equal(true) - nyc.exclude.shouldInstrument('/cwd/test.js', 'test.js').should.equal(false) - }) - }) - describe('wrap', function () { it('wraps modules with coverage counters when they are required', function () { var nyc = new NYC(configUtil.buildYargs().parse()) diff --git a/test/should-instrument.js b/test/should-instrument.js new file mode 100644 index 000000000..81b612914 --- /dev/null +++ b/test/should-instrument.js @@ -0,0 +1,78 @@ +const path = require('path') +const NYC = require('../self-coverage') +const configUtil = require('../self-coverage/lib/config-util') +const fixtures = path.resolve(__dirname, './fixtures') + +const t = require('tap') + +const rootDir = path.resolve('/') +t.test('should exclude appropriately with defaults', t => { + const nyc = new NYC(configUtil.buildYargs(rootDir).parse([ + '--exclude=test/**', + '--exclude=test{,-*}.js', + '--exclude=**/*.test.js', + '--exclude=**/__tests__/**' + ])) + + // nyc always excludes "node_modules/**" + t.true(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo.js'), 'foo.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'node_modules/bar.js'), 'node_modules/bar.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo/node_modules/bar.js'), 'foo/node_modules/bar.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'test.js'), 'test.js')) + t.true(nyc.exclude.shouldInstrument(path.join(rootDir, 'testfoo.js'), 'testfoo.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'test-foo.js'), 'test-foo.js')) + t.true(nyc.exclude.shouldInstrument(path.join(rootDir, 'lib/test.js'), 'lib/test.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo/bar/test.js'), './test.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo/bar/test.js'), '.\\test.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo/bar/foo.test.js'), './foo.test.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo/bar/__tests__/foo.js'), './__tests__/foo.js')) + t.done() +}) + +t.test('should exclude appropriately with config.exclude', t => { + const nyc = new NYC(configUtil.buildYargs(fixtures).parse()) + + // fixtures/package.json configures excludes: "blarg", "blerg" + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'blarg.js'), 'blarg.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'blarg/foo.js'), 'blarg/foo.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'blerg.js'), 'blerg.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'blerg.js'), './blerg.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'blerg.js'), '.\\blerg.js')) + t.done() +}) + +t.test('should exclude outside of the current working directory', t => { + const nyc = new NYC(configUtil.buildYargs(path.join(rootDir, 'foo')).parse()) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'bar.js'), '../bar.js')) + t.done() +}) + +t.test('should not exclude if the current working directory is inside node_modules', t => { + const cwd = path.join(rootDir, 'node_modules', 'foo') + const nyc = new NYC(configUtil.buildYargs(cwd).parse()) + t.true(nyc.exclude.shouldInstrument(path.join(cwd, 'bar.js'), './bar.js')) + t.true(nyc.exclude.shouldInstrument(path.join(cwd, 'bar.js'), '.\\bar.js')) + t.done() +}) + +t.test('allows files to be explicitly included, rather than excluded', t => { + const nyc = new NYC(configUtil.buildYargs(rootDir).parse(['--include=foo.js'])) + + t.true(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo.js'), 'foo.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'index.js'), 'index.js')) + t.done() +}) + +t.test('exclude overrides include', t => { + const nyc = new NYC(configUtil.buildYargs(rootDir).parse([ + '--include=foo.js', + '--include=test.js', + '--exclude=**/node_modules/**', + '--exclude=test/**', + '--exclude=test{,-*}.js' + ])) + + t.true(nyc.exclude.shouldInstrument(path.join(rootDir, 'foo.js'), 'foo.js')) + t.false(nyc.exclude.shouldInstrument(path.join(rootDir, 'test.js'), 'test.js')) + t.done() +})