Skip to content

Commit 3428c50

Browse files
committed
refactor: fix int-test
1 parent 2f53690 commit 3428c50

File tree

11 files changed

+207
-11
lines changed

11 files changed

+207
-11
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export default {
2+
upload: {
3+
organization: 'code-pushup',
4+
project: 'cli-js',
5+
apiKey: 'e2e-api-key',
6+
server: 'https://e2e.com/api',
7+
},
8+
categories: [
9+
{
10+
slug: 'category-1',
11+
title: 'Category 1',
12+
refs: [
13+
{
14+
type: 'audit',
15+
plugin: 'node',
16+
slug: 'node-version',
17+
weight: 1,
18+
},
19+
],
20+
},
21+
],
22+
plugins: [
23+
{
24+
audits: [
25+
{
26+
slug: 'node-version',
27+
title: 'Node version',
28+
description: 'prints node version to file',
29+
docsUrl: 'https://nodejs.org/',
30+
},
31+
],
32+
runner: {
33+
command: 'node',
34+
args: ['-v'],
35+
outputFile: 'output.json',
36+
},
37+
groups: [],
38+
slug: 'node',
39+
title: 'Node.js',
40+
icon: 'javascript',
41+
},
42+
],
43+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export default {
2+
upload: {
3+
organization: 'code-pushup',
4+
project: 'cli-mjs',
5+
apiKey: 'e2e-api-key',
6+
server: 'https://e2e.com/api',
7+
},
8+
categories: [
9+
{
10+
slug: 'category-1',
11+
title: 'Category 1',
12+
refs: [
13+
{
14+
type: 'audit',
15+
plugin: 'node',
16+
slug: 'node-version',
17+
weight: 1,
18+
},
19+
],
20+
},
21+
],
22+
plugins: [
23+
{
24+
audits: [
25+
{
26+
slug: 'node-version',
27+
title: 'Node version',
28+
description: 'prints node version to file',
29+
docsUrl: 'https://nodejs.org/',
30+
},
31+
],
32+
runner: {
33+
command: 'node',
34+
args: ['-v'],
35+
outputFile: 'output.json',
36+
},
37+
groups: [],
38+
slug: 'node',
39+
title: 'Node.js',
40+
icon: 'javascript',
41+
},
42+
],
43+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { type CoreConfig } from '@code-pushup/models';
2+
3+
export default {
4+
upload: {
5+
organization: 'code-pushup',
6+
project: 'cli-ts',
7+
apiKey: 'e2e-api-key',
8+
server: 'https://e2e.com/api',
9+
},
10+
categories: [
11+
{
12+
slug: 'category-1',
13+
title: 'Category 1',
14+
refs: [
15+
{
16+
type: 'audit',
17+
plugin: 'node',
18+
slug: 'node-version',
19+
weight: 1,
20+
},
21+
],
22+
},
23+
],
24+
plugins: [
25+
{
26+
audits: [
27+
{
28+
slug: 'node-version',
29+
title: 'Node version',
30+
description: 'prints node version to file',
31+
docsUrl: 'https://nodejs.org/',
32+
},
33+
],
34+
runner: {
35+
command: 'node',
36+
args: ['-v'],
37+
outputFile: 'output.json',
38+
},
39+
groups: [],
40+
slug: 'node',
41+
title: 'Node.js',
42+
icon: 'javascript',
43+
},
44+
],
45+
} satisfies CoreConfig;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// the point is to test runtime import which relies on alias defined in tsconfig.json "paths"
2+
// non-type import from '@example/custom-plugin' wouldn't work without --tsconfig
3+
// eslint-disable-next-line import/no-unresolved
4+
import customPlugin from '@definitely-non-existent-package/custom-plugin';
5+
6+
const config = {
7+
plugins: [customPlugin],
8+
};
9+
10+
export default config;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// the point is to test runtime import which relies on alias defined in tsconfig.json "paths"
2+
// non-type import from '@example/custom-plugin' wouldn't work without --tsconfig
3+
// eslint-disable-next-line import/no-unresolved
4+
import customPlugin from '@definitely-non-existent-package/custom-plugin';
5+
6+
const config = {
7+
plugins: [customPlugin],
8+
};
9+
10+
export default config;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const customPluginConfig = {
2+
slug: 'good-feels',
3+
title: 'Good feels',
4+
icon: 'javascript',
5+
audits: [
6+
{
7+
slug: 'always-perfect',
8+
title: 'Always perfect',
9+
},
10+
],
11+
runner: () => [
12+
{
13+
slug: 'always-perfect',
14+
score: 1,
15+
value: 100,
16+
displayValue: '✅ Perfect! 👌',
17+
},
18+
],
19+
};
20+
21+
export function customPlugin() {
22+
return customPluginConfig;
23+
}
24+
export default customPluginConfig;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@definitely-non-existent-package/custom-plugin": ["./custom-plugin.ts"]
5+
}
6+
}
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {}
4+
}
5+
}

packages/cli/src/lib/implementation/core-config.middleware.int.test.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ const configDirPath = path.join(
1818
'configs',
1919
);
2020

21+
const localMocks = path.join(
22+
fileURLToPath(path.dirname(import.meta.url)),
23+
'..',
24+
'..',
25+
'..',
26+
'mocks',
27+
'fixtures',
28+
'configs',
29+
);
30+
2131
describe('coreConfigMiddleware', () => {
2232
const CLI_DEFAULTS = {
2333
plugins: [],
@@ -29,7 +39,7 @@ describe('coreConfigMiddleware', () => {
2939
'should load a valid .%s config',
3040
async extension => {
3141
const config = await coreConfigMiddleware({
32-
config: path.join(configDirPath, `code-pushup.config.${extension}`),
42+
config: path.join(localMocks, `code-pushup.config.${extension}`),
3343
...CLI_DEFAULTS,
3444
});
3545
expect(config.config).toContain(`code-pushup.config.${extension}`);
@@ -46,11 +56,8 @@ describe('coreConfigMiddleware', () => {
4656
it('should load config which relies on provided --tsconfig', async () => {
4757
await expect(
4858
coreConfigMiddleware({
49-
config: path.join(
50-
configDirPath,
51-
'code-pushup.needs-tsconfig.config.ts',
52-
),
53-
tsconfig: path.join(configDirPath, 'tsconfig.json'),
59+
config: path.join(localMocks, 'code-pushup.needs-tsconfig.config.ts'),
60+
tsconfig: path.join(localMocks, 'tsconfig.alias.json'),
5461
...CLI_DEFAULTS,
5562
}),
5663
).resolves.toBeTruthy();
@@ -60,11 +67,13 @@ describe('coreConfigMiddleware', () => {
6067
await expect(
6168
coreConfigMiddleware({
6269
config: path.join(
63-
configDirPath,
64-
'code-pushup.needs-tsconfig.config.ts',
70+
localMocks,
71+
'code-pushup.needs-tsconfig-fail.config.ts',
6572
),
6673
...CLI_DEFAULTS,
6774
}),
68-
).rejects.toThrow("Cannot find package '@example/custom-plugin'");
75+
).rejects.toThrow(
76+
"Cannot find module '@definitely-non-existent-package/custom-plugin'",
77+
);
6978
});
7079
});

testing/test-fixtures/src/lib/fixtures/configs/code-pushup.needs-tsconfig.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// the point is to test runtime import which relies on alias defined in tsconfig.json "paths"
22
// non-type import from '@example/custom-plugin' wouldn't work without --tsconfig
33
// eslint-disable-next-line import/no-unresolved
4-
import customPlugin from '@example/custom-plugin';
4+
import customPlugin from '@definitely-non-existent-package/custom-plugin';
55

66
const config = {
77
plugins: [customPlugin],

0 commit comments

Comments
 (0)