| 1 |
'use strict' |
| 2 |
|
| 3 |
const path = require('path') |
| 4 |
|
| 5 |
const { test } = require('tap') |
| 6 |
|
| 7 |
const NYC = require('../self-coverage') |
| 8 |
|
| 9 |
const { parseArgv } = require('./helpers') |
| 10 |
|
| 11 |
test("loads 'exclude' patterns from package.json#nyc", async t => { |
| 12 |
const nyc = new NYC(await parseArgv(path.resolve(__dirname, './fixtures'))) |
| 13 |
|
| 14 |
t.strictEqual(nyc.exclude.exclude.length, 8) |
| 15 |
}) |
| 16 |
|
| 17 |
test("loads 'extension' patterns from package.json#nyc", async t => { |
| 18 |
const nyc = new NYC(await parseArgv(path.resolve(__dirname, './fixtures/conf-multiple-extensions'))) |
| 19 |
|
| 20 |
t.strictEqual(nyc.extensions.length, 3) |
| 21 |
}) |
| 22 |
|
| 23 |
test("ignores 'include' option if it's falsy or []", async t => { |
| 24 |
const nyc1 = new NYC(await parseArgv(path.resolve(__dirname, './fixtures/conf-empty'))) |
| 25 |
|
| 26 |
t.strictEqual(nyc1.exclude.include, false) |
| 27 |
|
| 28 |
const nyc2 = new NYC({ |
| 29 |
include: [] |
| 30 |
}) |
| 31 |
|
| 32 |
t.strictEqual(nyc2.exclude.include, false) |
| 33 |
}) |
| 34 |
|
| 35 |
test("ignores 'exclude' option if it's falsy", async t => { |
| 36 |
const nyc = new NYC(await parseArgv(path.resolve(__dirname, './fixtures/conf-empty'))) |
| 37 |
|
| 38 |
t.strictEqual(nyc.exclude.exclude.length, 27) |
| 39 |
}) |
| 40 |
|
| 41 |
test("allows for empty 'exclude'", async t => { |
| 42 |
const nyc = new NYC({ exclude: [] }) |
| 43 |
|
| 44 |
// an empty exclude still has **/node_modules/**, node_modules/** and added. |
| 45 |
t.strictEqual(nyc.exclude.exclude.length, 2) |
| 46 |
}) |
| 47 |
|
| 48 |
test("allows for completely empty 'exclude' with exclude-node-modules", async t => { |
| 49 |
const nyc = new NYC({ exclude: [], excludeNodeModules: false }) |
| 50 |
|
| 51 |
t.strictEqual(nyc.exclude.exclude.length, 0) |
| 52 |
}) |
| 53 |
|
| 54 |
test('should resolve default cache folder to absolute path', async t => { |
| 55 |
const nyc = new NYC({ |
| 56 |
cache: true |
| 57 |
}) |
| 58 |
|
| 59 |
t.strictEqual(path.isAbsolute(nyc.cacheDirectory), true) |
| 60 |
}) |
| 61 |
|
| 62 |
test('should resolve custom cache folder to absolute path', async t => { |
| 63 |
const nyc = new NYC({ |
| 64 |
cacheDir: '.nyc_cache', |
| 65 |
cache: true |
| 66 |
}) |
| 67 |
|
| 68 |
t.strictEqual(path.isAbsolute(nyc.cacheDirectory), true) |
| 69 |
}) |
| 70 |
|
| 71 |
test('if cache is false _disableCachingTransform is true', async t => { |
| 72 |
const nycParent = new NYC({ cache: false, isChildProcess: false }) |
| 73 |
const nycChild = new NYC({ cache: false, isChildProcess: true }) |
| 74 |
|
| 75 |
t.strictEqual(nycParent._disableCachingTransform(), true) |
| 76 |
t.strictEqual(nycChild._disableCachingTransform(), true) |
| 77 |
}) |
| 78 |
|
| 79 |
test('if cache is true _disableCachingTransform is equal to !isChildProcess', async t => { |
| 80 |
const nycParent = new NYC({ cache: true, isChildProcess: false }) |
| 81 |
const nycChild = new NYC({ cache: true, isChildProcess: true }) |
| 82 |
|
| 83 |
t.strictEqual(nycParent._disableCachingTransform(), true) |
| 84 |
t.strictEqual(nycChild._disableCachingTransform(), false) |
| 85 |
}) |