File: test.js

package info (click to toggle)
node-load-json-file 7.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 156 kB
  • sloc: javascript: 93; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 891 bytes parent folder | download
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
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import test from 'tape';
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');
	t.end();
});

test('sync', t => {
	t.is(loadJsonFileSync(fixture).name, 'load-json-file');
	t.end();
});

/*
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');
	t.end();
});
*/

test('reviver option', async t => {
	const data = await loadJsonFile(fixture, {
		reviver: (key, value) => key === 'name' ? 'foo' : value,
	});
	t.is(data.name, 'foo');
	t.end();
});