Skip to content

Commit d953e35

Browse files
committed
refactor: wip
1 parent 36aa855 commit d953e35

File tree

10 files changed

+225
-86
lines changed

10 files changed

+225
-86
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: 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-ts',
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// the point is to test runtime import which requires tsconfig for path aliases
2+
import customPlugin from '@example/custom-plugin';
3+
4+
const config = {
5+
plugins: [customPlugin],
6+
};
7+
8+
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"allowImportingTsExtensions": true,
5+
"moduleResolution": "node",
6+
"paths": {
7+
"@example/custom-plugin": ["./custom-plugin.ts"]
8+
}
9+
},
10+
"include": ["*.ts"]
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { coreConfigMiddleware } from '../src/lib/implementation/core-config.middleware.js';
2+
3+
// Suppress all console output except our JSON
4+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
5+
const originalStderrWrite = process.stderr.write.bind(process.stderr);
6+
7+
process.stdout.write = () => true;
8+
process.stderr.write = () => true;
9+
10+
const CLI_DEFAULTS = {
11+
plugins: [],
12+
onlyPlugins: [],
13+
skipPlugins: [],
14+
};
15+
16+
const result = await coreConfigMiddleware({
17+
config: 'code-pushup.needs-tsconfig.config.ts', // relative path
18+
// No tsconfig - should fallback to ./tsconfig.json
19+
...CLI_DEFAULTS,
20+
});
21+
22+
// Restore stdout and stderr, then write only JSON
23+
process.stdout.write = originalStdoutWrite;
24+
process.stderr.write = originalStderrWrite;
25+
process.stdout.write(JSON.stringify({ success: true, config: result.config }));

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path';
22
import { fileURLToPath } from 'node:url';
3+
import { executeProcess } from '@code-pushup/utils';
34
import { coreConfigMiddleware } from './core-config.middleware.js';
45

56
const configDirPath = path.join(
@@ -8,15 +9,26 @@ const configDirPath = path.join(
89
'..',
910
'..',
1011
'..',
11-
'..',
12-
'testing',
13-
'test-fixtures',
14-
'src',
15-
'lib',
16-
'fixtures',
12+
'cli',
13+
'mocks',
1714
'configs',
1815
);
19-
16+
const helperPath = path.join(
17+
fileURLToPath(path.dirname(import.meta.url)),
18+
'..',
19+
'..',
20+
'..',
21+
'..',
22+
'cli',
23+
'mocks',
24+
'core-config-middleware.int-helper.ts',
25+
);
26+
const runMiddlewareInCwd = async () =>
27+
await executeProcess({
28+
command: 'npx',
29+
args: ['tsx', helperPath],
30+
cwd: configDirPath,
31+
});
2032
describe('coreConfigMiddleware', () => {
2133
const CLI_DEFAULTS = {
2234
plugins: [],
@@ -43,16 +55,14 @@ describe('coreConfigMiddleware', () => {
4355
});
4456

4557
it('should load config which relies on provided --tsconfig', async () => {
46-
await expect(
47-
coreConfigMiddleware({
48-
config: path.join(
49-
configDirPath,
50-
'code-pushup.needs-tsconfig.config.ts',
51-
),
52-
tsconfig: path.join(configDirPath, 'tsconfig.json'),
53-
...CLI_DEFAULTS,
54-
}),
55-
).resolves.toBeTruthy();
58+
const { stdout, code } = await runMiddlewareInCwd();
59+
60+
expect(code).toBe(0);
61+
const output = JSON.parse(stdout);
62+
expect(output).toStrictEqual({
63+
success: true,
64+
config: expect.any(String),
65+
});
5666
});
5767

5868
it('should throw if --tsconfig is missing but needed to resolve import', async () => {

packages/utils/src/lib/file-system.int.test.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { type CoreConfig } from '@code-pushup/models';
2-
31
export default {
42
upload: {
53
organization: 'code-pushup',
@@ -42,4 +40,4 @@ export default {
4240
icon: 'javascript',
4341
},
4442
],
45-
} satisfies CoreConfig;
43+
};

0 commit comments

Comments
 (0)