| 1 |
'use strict' |
| 2 |
|
| 3 |
const path = require('path') |
| 4 |
|
| 5 |
const t = require('tap') |
| 6 |
|
| 7 |
const NYC = require('../self-coverage') |
| 8 |
|
| 9 |
const { parseArgv } = require('./helpers') |
| 10 |
|
| 11 |
t.beforeEach(async () => { |
| 12 |
delete process.env.NYC_CWD |
| 13 |
}) |
| 14 |
|
| 15 |
t.test('sets cwd to process.cwd() if no environment variable is set', async t => { |
| 16 |
const nyc = new NYC(await parseArgv()) |
| 17 |
|
| 18 |
t.strictEqual(nyc.cwd, process.cwd()) |
| 19 |
}) |
| 20 |
|
| 21 |
t.test('uses NYC_CWD environment variable for cwd if it is set', async t => { |
| 22 |
const fixtures = path.resolve(__dirname, './fixtures') |
| 23 |
process.env.NYC_CWD = fixtures |
| 24 |
const nyc = new NYC(await parseArgv()) |
| 25 |
|
| 26 |
t.strictEqual(nyc.cwd, fixtures) |
| 27 |
}) |
| 28 |
|
| 29 |
t.test('will look upwards for package.json from cwd', async t => { |
| 30 |
const nyc = new NYC(await parseArgv(__dirname)) |
| 31 |
|
| 32 |
t.strictEqual(nyc.cwd, path.join(__dirname, '..')) |
| 33 |
}) |
| 34 |
|
| 35 |
t.test('uses --cwd for cwd if it is set (highest priority and does not look upwards for package.json) ', async t => { |
| 36 |
const nyc = new NYC(await parseArgv(__dirname, ['--cwd', __dirname])) |
| 37 |
|
| 38 |
t.strictEqual(nyc.cwd, __dirname) |
| 39 |
}) |