Skip to content

Commit 3101c6e

Browse files
ASAS
authored andcommitted
feat(nx-plugin): fix tests and mr comments
1 parent 7641e57 commit 3101c6e

File tree

5 files changed

+39
-13916
lines changed

5 files changed

+39
-13916
lines changed

packages/models/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ export {
133133
} from './lib/tree.js';
134134
export { uploadConfigSchema, type UploadConfig } from './lib/upload-config.js';
135135
export {
136-
artifactGenerationCommand as toolCommandSchema,
136+
artifactGenerationCommand,
137137
pluginArtefactOptionsSchema,
138138
} from './lib/configuration';

packages/models/src/lib/configuration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { z } from 'zod';
44
* Generic schema for a tool command configuration, reusable across plugins.
55
*/
66
export const artifactGenerationCommand = z.object({
7-
command: z.string({ description: 'Command to run the tool.' }).min(1),
7+
command: z.string({ description: 'Generate artifact files' }).min(1),
88
args: z
99
.array(z.string(), {
10-
description: 'Arguments to be passed to the tool.',
10+
description: 'Arguments to be passed to the artefact generation command.',
1111
})
1212
.optional(),
1313
});

packages/models/src/lib/configuration.unit.test.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,89 +7,93 @@ import {
77
describe('artifactGenerationCommand', () => {
88
it('should validate a command with required fields', () => {
99
const data = { command: 'npx' };
10-
const result = artifactGenerationCommand.safeParse(data);
11-
expect(result.success).toBe(true);
12-
if (result.success) {
13-
expect(result.data.command).toBe('npx');
14-
expect(result.data.args).toBeUndefined();
15-
}
10+
expect(artifactGenerationCommand.safeParse(data)).toStrictEqual({
11+
success: true,
12+
data: { command: 'npx' },
13+
});
1614
});
1715

1816
it('should validate a command with args', () => {
1917
const data = { command: 'npx', args: ['eslint', 'src/'] };
20-
const result = artifactGenerationCommand.safeParse(data);
21-
expect(result.success).toBe(true);
22-
if (result.success) {
23-
expect(result.data.command).toBe('npx');
24-
expect(result.data.args).toEqual(['eslint', 'src/']);
25-
}
18+
expect(artifactGenerationCommand.safeParse(data)).toStrictEqual({
19+
success: true,
20+
data: { command: 'npx', args: ['eslint', 'src/'] },
21+
});
2622
});
2723

2824
it('should fail if command is missing', () => {
2925
const data = { args: ['eslint', 'src/'] };
30-
const result = artifactGenerationCommand.safeParse(data);
31-
expect(result.success).toBe(false);
26+
expect(artifactGenerationCommand.safeParse(data).success).toBe(false);
3227
});
3328

3429
it('should fail if command is empty', () => {
3530
const data = { command: '' };
36-
const result = artifactGenerationCommand.safeParse(data);
37-
expect(result.success).toBe(false);
31+
expect(artifactGenerationCommand.safeParse(data).success).toBe(false);
3832
});
3933

4034
it('should fail if args is not an array of strings', () => {
4135
const data = { command: 'npx', args: [123, true] };
42-
const result = artifactGenerationCommand.safeParse(data);
43-
expect(result.success).toBe(false);
36+
expect(artifactGenerationCommand.safeParse(data).success).toBe(false);
4437
});
4538
});
4639

4740
describe('pluginArtefactOptionsSchema', () => {
4841
it('should validate with only artefactsPaths as string', () => {
4942
const data = { artefactsPaths: 'dist/report.json' };
50-
const { success } = pluginArtefactOptionsSchema.safeParse(data);
51-
expect(success).toBe(true);
43+
expect(pluginArtefactOptionsSchema.safeParse(data)).toStrictEqual({
44+
success: true,
45+
data: {
46+
artefactsPaths: 'dist/report.json',
47+
generateArtefacts: undefined,
48+
},
49+
});
5250
});
5351

5452
it('should validate with artefactsPaths as array of strings', () => {
5553
const data = { artefactsPaths: ['dist/report.json', 'dist/summary.json'] };
56-
const { success } = pluginArtefactOptionsSchema.safeParse(data);
57-
expect(success).toBe(true);
54+
expect(pluginArtefactOptionsSchema.safeParse(data)).toStrictEqual({
55+
success: true,
56+
data: {
57+
artefactsPaths: ['dist/report.json', 'dist/summary.json'],
58+
generateArtefacts: undefined,
59+
},
60+
});
5861
});
5962

6063
it('should fail if artefactsPaths is an empty array', () => {
6164
const data = { artefactsPaths: [] };
62-
const { success } = pluginArtefactOptionsSchema.safeParse(data);
63-
expect(success).toBe(false);
65+
expect(pluginArtefactOptionsSchema.safeParse(data).success).toBe(false);
6466
});
6567

6668
it('should validate with generateArtefacts and artefactsPaths', () => {
6769
const data = {
6870
generateArtefacts: { command: 'npm', args: ['run', 'build'] },
6971
artefactsPaths: ['dist/report.json'],
7072
};
71-
const { success } = pluginArtefactOptionsSchema.safeParse(data);
72-
expect(success).toBe(true);
73+
expect(pluginArtefactOptionsSchema.safeParse(data)).toStrictEqual({
74+
success: true,
75+
data: {
76+
generateArtefacts: { command: 'npm', args: ['run', 'build'] },
77+
artefactsPaths: ['dist/report.json'],
78+
},
79+
});
7380
});
7481

7582
it('should fail if artefactsPaths is missing', () => {
7683
const data = { generateArtefacts: { command: 'npm' } };
77-
const { success } = pluginArtefactOptionsSchema.safeParse(data);
78-
expect(success).toBe(false);
84+
expect(pluginArtefactOptionsSchema.safeParse(data).success).toBe(false);
7985
});
8086

8187
it('should fail if artefactsPaths is not string or array of strings', () => {
8288
const data = { artefactsPaths: 123 };
83-
const { success } = pluginArtefactOptionsSchema.safeParse(data);
84-
expect(success).toBe(false);
89+
expect(pluginArtefactOptionsSchema.safeParse(data).success).toBe(false);
8590
});
8691

8792
it('should fail if generateArtefacts is invalid', () => {
8893
const data = {
8994
generateArtefacts: { command: '' },
9095
artefactsPaths: 'dist/report.json',
9196
};
92-
const { success } = pluginArtefactOptionsSchema.safeParse(data);
93-
expect(success).toBe(false);
97+
expect(pluginArtefactOptionsSchema.safeParse(data).success).toBe(false);
9498
});
9599
});

packages/plugin-coverage/src/lib/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { z } from 'zod';
2-
import { toolCommandSchema } from '@code-pushup/models';
32

43
export const coverageTypeSchema = z.enum(['function', 'branch', 'line']);
54
export type CoverageType = z.infer<typeof coverageTypeSchema>;

0 commit comments

Comments
 (0)