-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathread-rc-file.int.test.ts
More file actions
72 lines (65 loc) · 2.02 KB
/
read-rc-file.int.test.ts
File metadata and controls
72 lines (65 loc) · 2.02 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
72
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { readRcByPath } from './read-rc-file.js';
describe('readRcByPath', () => {
const configDirPath = path.join(
fileURLToPath(path.dirname(import.meta.url)),
'..',
'..',
'..',
'mocks',
'fixtures',
'configs',
);
it('should load the configuration', async () => {
await expect(
readRcByPath(path.join(configDirPath, 'code-pushup.config.js')),
).resolves.toEqual(
expect.objectContaining({
upload: expect.objectContaining({
project: 'cli-js',
}),
categories: expect.any(Array),
plugins: expect.arrayContaining([
expect.objectContaining({
slug: 'node',
}),
]),
}),
);
});
it('should load the configuration using provided tsconfig', async () => {
await expect(
readRcByPath(
path.join(configDirPath, 'code-pushup.needs-tsconfig.config.ts'),
path.join(configDirPath, 'tsconfig.json'),
),
).resolves.toEqual({
plugins: [
expect.objectContaining({
slug: 'good-feels',
audits: [{ slug: 'always-perfect', title: 'Always perfect' }],
runner: expect.any(Function),
}),
],
});
});
it('should throw if the path is empty', async () => {
await expect(readRcByPath('')).rejects.toThrow("File '' does not exist");
});
it('should throw if the file does not exist', async () => {
await expect(
readRcByPath(path.join('non-existent', 'config.file.js')),
).rejects.toThrow(/File '.*' does not exist/);
});
it('should throw if the configuration is empty', async () => {
await expect(
readRcByPath(path.join(configDirPath, 'code-pushup.empty.config.js')),
).rejects.toThrow('Invalid input');
});
it('should throw if the configuration is invalid', async () => {
await expect(
readRcByPath(path.join(configDirPath, 'code-pushup.invalid.config.ts')),
).rejects.toThrow('has duplicate references');
});
});