-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathtest.js
30 lines (25 loc) · 844 Bytes
/
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
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {loadJsonFile, loadJsonFileSync} from './index.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const fixture = path.join(__dirname, 'package.json');
test('async', async t => {
const data = await loadJsonFile(fixture);
t.is(data.name, 'load-json-file');
});
test('sync', t => {
t.is(loadJsonFileSync(fixture).name, 'load-json-file');
});
test('beforeParse option', async t => {
const data = await loadJsonFile(fixture, {
beforeParse: string => string.replace('"name": "load-json-file"', '"name": "foo"'),
});
t.is(data.name, 'foo');
});
test('reviver option', async t => {
const data = await loadJsonFile(fixture, {
reviver: (key, value) => key === 'name' ? 'foo' : value,
});
t.is(data.name, 'foo');
});