-
Notifications
You must be signed in to change notification settings - Fork 654
Expand file tree
/
Copy pathis-package-json.test.ts
More file actions
71 lines (59 loc) · 1.75 KB
/
Copy pathis-package-json.test.ts
File metadata and controls
71 lines (59 loc) · 1.75 KB
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
import assert from 'assert';
import { isPackageJson } from './is-package-json';
import { getPackageJson } from '../../test-utils';
import { VirtualFile } from '../../virtual-file';
describe('isPackageJson', () => {
it("does nothing if file doesn't exist", async () => {
const report = jest.fn();
assert(isPackageJson.structureCheck);
await isPackageJson.structureCheck(
{
localizationFiles: [],
auxiliaryFiles: [],
},
{ report },
);
expect(report).toHaveBeenCalledTimes(0);
});
it('does nothing on valid package.json', async () => {
const packageJson = getPackageJson();
const packageJsonFile = new VirtualFile({
value: JSON.stringify(packageJson),
result: packageJson,
path: '/package.json',
});
const report = jest.fn();
assert(isPackageJson.structureCheck);
await isPackageJson.structureCheck(
{
packageJson: packageJsonFile,
localizationFiles: [],
auxiliaryFiles: [],
},
{ report },
);
expect(report).toHaveBeenCalledTimes(0);
});
it('reports on invalid package.json', async () => {
const packageJson = getPackageJson({ version: 'foo' });
const packageJsonFile = new VirtualFile({
value: JSON.stringify(packageJson),
result: packageJson,
path: '/package.json',
});
const report = jest.fn();
assert(isPackageJson.structureCheck);
await isPackageJson.structureCheck(
{
packageJson: packageJsonFile,
localizationFiles: [],
auxiliaryFiles: [],
},
{ report },
);
expect(report).toHaveBeenCalledWith(
'is-package-json',
'"package.json" is invalid: At path: version — Expected SemVer version, got "foo".',
);
});
});