-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcore-config.middleware.int.test.ts
More file actions
70 lines (64 loc) · 1.82 KB
/
core-config.middleware.int.test.ts
File metadata and controls
70 lines (64 loc) · 1.82 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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect } from 'vitest';
import { coreConfigMiddleware } from './core-config.middleware.js';
const configDirPath = path.join(
fileURLToPath(path.dirname(import.meta.url)),
'..',
'..',
'..',
'..',
'..',
'testing',
'test-utils',
'src',
'lib',
'fixtures',
'configs',
);
describe('coreConfigMiddleware', () => {
const CLI_DEFAULTS = {
plugins: [],
onlyPlugins: [],
skipPlugins: [],
};
it.each(['ts', 'mjs', 'js'])(
'should load a valid .%s config',
async extension => {
const config = await coreConfigMiddleware({
config: path.join(configDirPath, `code-pushup.config.${extension}`),
...CLI_DEFAULTS,
});
expect(config.config).toContain(`code-pushup.config.${extension}`);
expect(config.upload?.project).toContain(extension);
},
);
it('should throw with invalid config path', async () => {
await expect(
coreConfigMiddleware({ config: 'wrong/path/to/config', ...CLI_DEFAULTS }),
).rejects.toThrow(/File '.*' does not exist/);
});
it('should load config which relies on provided --tsconfig', async () => {
await expect(
coreConfigMiddleware({
config: path.join(
configDirPath,
'code-pushup.needs-tsconfig.config.ts',
),
tsconfig: path.join(configDirPath, 'tsconfig.json'),
...CLI_DEFAULTS,
}),
).resolves.toBeTruthy();
});
it('should throw if --tsconfig is missing but needed to resolve import', async () => {
await expect(
coreConfigMiddleware({
config: path.join(
configDirPath,
'code-pushup.needs-tsconfig.config.ts',
),
...CLI_DEFAULTS,
}),
).rejects.toThrow("Cannot find package '@example/custom-plugin'");
});
});