-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathload-report.unit.test.ts
More file actions
67 lines (61 loc) · 1.61 KB
/
load-report.unit.test.ts
File metadata and controls
67 lines (61 loc) · 1.61 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
import { vol } from 'memfs';
import type { Report } from '@code-pushup/models';
import { REPORT_MOCK, reportMock } from '@code-pushup/test-fixtures';
import { MEMFS_VOLUME } from '@code-pushup/test-utils';
import { loadReport } from './load-report.js';
describe('loadReport', () => {
it('should load a valid JSON report', async () => {
vol.fromJSON(
{
[`report.json`]: JSON.stringify(reportMock()),
[`report.md`]: 'test-42',
},
MEMFS_VOLUME,
);
await expect(
loadReport({
outputDir: MEMFS_VOLUME,
filename: 'report',
format: 'json',
skipReports: false,
}),
).resolves.toEqual(reportMock());
});
it('should load a markdown file', async () => {
vol.fromJSON(
{
[`report.dummy.md`]: 'test-7',
[`report.json`]: '{"test":42}',
[`report.md`]: 'test-42',
},
MEMFS_VOLUME,
);
await expect(
loadReport({
outputDir: MEMFS_VOLUME,
format: 'md',
filename: 'report',
skipReports: false,
}),
).resolves.toBe('test-42');
});
it('should throw for an invalid JSON report', async () => {
vol.fromJSON(
{
[`report.json`]: JSON.stringify({
...REPORT_MOCK,
plugins: [{ ...REPORT_MOCK.plugins[0]!, slug: '-Invalid_slug' }],
} satisfies Report),
},
MEMFS_VOLUME,
);
await expect(
loadReport({
outputDir: MEMFS_VOLUME,
filename: 'report',
format: 'json',
skipReports: false,
}),
).rejects.toThrow('slug has to follow the pattern');
});
});