-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest.js
102 lines (82 loc) · 2.43 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {fileURLToPath} from 'node:url';
import path from 'node:path';
import test from 'ava';
import {packageConfig, packageConfigSync, packageJsonPath} from './index.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const cwd = path.join(__dirname, 'fixture');
const nestedCwd = path.join(cwd, 'nested');
const pacagePath = path.join(__dirname, 'package.json');
const nestedPath = path.join(nestedCwd, 'package.json');
test('async', async t => {
const config = await packageConfig('fixture', {cwd});
t.true(config.foo);
t.is(packageJsonPath(config), pacagePath);
});
test('async - non-existent namespace', async t => {
const config = await packageConfig('noop', {cwd});
t.is(typeof config, 'object');
});
test('sync', t => {
const config = packageConfigSync('fixture', {cwd});
t.true(config.foo);
t.is(packageJsonPath(config), pacagePath);
});
test('sync - non-existent namespace', t => {
const config = packageConfigSync('noop', {cwd});
t.is(typeof config, 'object');
});
test('defaults option', t => {
const config = packageConfigSync('fixture', {cwd, defaults: {bar: false}});
t.true(config.foo);
t.false(config.bar);
const config2 = packageConfigSync('noop', {defaults: {unicorn: true}});
t.true(config2.unicorn);
});
test('async - nested default', async t => {
const config = await packageConfig('fixture', {
cwd: nestedCwd,
defaults: {cat: true},
});
t.true(config.cat);
t.is(packageJsonPath(config), nestedPath);
});
test('async - nested skipOnFalse', async t => {
const config = await packageConfig('fixture', {
cwd: nestedCwd,
skipOnFalse: true,
});
t.true(config.foo);
t.is(packageJsonPath(config), pacagePath);
});
test('async - normal skipOnFalse', async t => {
const config = await packageConfig('fixture', {
cwd,
skipOnFalse: true,
});
t.true(config.foo);
t.is(packageJsonPath(config), pacagePath);
});
test('sync - nested default', t => {
const config = packageConfigSync('fixture', {
cwd: nestedCwd,
defaults: {cat: true},
});
t.true(config.cat);
t.is(packageJsonPath(config), nestedPath);
});
test('sync - nested skipOnFalse', t => {
const config = packageConfigSync('fixture', {
cwd: nestedCwd,
skipOnFalse: true,
});
t.true(config.foo);
t.is(packageJsonPath(config), pacagePath);
});
test('sync - normal skipOnFalse', t => {
const config = packageConfigSync('fixture', {
cwd,
skipOnFalse: true,
});
t.true(config.foo);
t.is(packageJsonPath(config), pacagePath);
});