-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconfiguration.unit.test.ts
More file actions
127 lines (112 loc) · 4.21 KB
/
configuration.unit.test.ts
File metadata and controls
127 lines (112 loc) · 4.21 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { describe, expect, it } from 'vitest';
import {
artifactGenerationCommandSchema,
pluginArtifactOptionsSchema,
} from './configuration.js';
describe('artifactGenerationCommandSchema', () => {
it('should validate a command with required fields', () => {
const data = { command: 'npx' };
expect(artifactGenerationCommandSchema.safeParse(data)).toStrictEqual({
success: true,
data: { command: 'npx' },
});
});
it('should validate a command with args', () => {
const data = { command: 'npx', args: ['eslint', 'src/'] };
expect(artifactGenerationCommandSchema.safeParse(data)).toStrictEqual({
success: true,
data: { command: 'npx', args: ['eslint', 'src/'] },
});
});
it('should fail if command is missing', () => {
const data = { args: ['eslint', 'src/'] };
expect(artifactGenerationCommandSchema.safeParse(data).success).toBe(false);
});
it('should fail if command is empty', () => {
const data = { command: '' };
expect(artifactGenerationCommandSchema.safeParse(data).success).toBe(false);
});
it('should fail if args is not an array of strings', () => {
const data = { command: 'npx', args: [123, true] };
expect(artifactGenerationCommandSchema.safeParse(data).success).toBe(false);
});
});
describe('pluginArtifactOptionsSchema', () => {
it('should validate with only artifactsPaths as string', () => {
const data = { artifactsPaths: 'dist/report.json' };
expect(pluginArtifactOptionsSchema.safeParse(data)).toStrictEqual({
success: true,
data: {
artifactsPaths: 'dist/report.json',
},
});
});
it('should validate with artifactsPaths as array of strings', () => {
const data = { artifactsPaths: ['dist/report.json', 'dist/summary.json'] };
expect(pluginArtifactOptionsSchema.safeParse(data)).toStrictEqual({
success: true,
data: {
artifactsPaths: ['dist/report.json', 'dist/summary.json'],
},
});
});
it('should fail if artifactsPaths is an empty array', () => {
const data = { artifactsPaths: [] };
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
});
it('should validate with generateArtifactsCommand and artifactsPaths', () => {
const data = {
generateArtifactsCommand: { command: 'npm', args: ['run', 'build'] },
artifactsPaths: ['dist/report.json'],
};
expect(pluginArtifactOptionsSchema.safeParse(data)).toStrictEqual({
success: true,
data: {
generateArtifactsCommand: { command: 'npm', args: ['run', 'build'] },
artifactsPaths: ['dist/report.json'],
},
});
});
it('should fail if artifactsPaths is missing', () => {
const data = { generateArtifactsCommand: { command: 'npm' } };
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
});
it('should fail if artifactsPaths is not string or array of strings', () => {
const data = { artifactsPaths: 123 };
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
});
it('should fail if generateArtifactsCommand is invalid', () => {
const data = {
generateArtifactsCommand: { command: '' },
artifactsPaths: 'dist/report.json',
};
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
});
it('should validate with generateArtifactsCommand as a string', () => {
const data = {
generateArtifactsCommand: 'yarn test --coverage',
artifactsPaths: 'coverage/lcov.info',
};
expect(pluginArtifactOptionsSchema.safeParse(data)).toStrictEqual({
success: true,
data: {
generateArtifactsCommand: 'yarn test --coverage',
artifactsPaths: 'coverage/lcov.info',
},
});
});
it('should fail if generateArtifactsCommand is an empty string', () => {
const data = {
generateArtifactsCommand: '',
artifactsPaths: 'coverage/lcov.info',
};
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
});
it('should fail if generateArtifactsCommand is a number', () => {
const data = {
generateArtifactsCommand: 123,
artifactsPaths: 'coverage/lcov.info',
};
expect(pluginArtifactOptionsSchema.safeParse(data).success).toBe(false);
});
});