@@ -6,54 +6,6 @@ import type {
66 UserBenchmarkConfig ,
77} from '../../types/user-benchmark-config'
88
9- /**
10- * Validates BaseBenchmarkSettings (iterations, timeout, warmup).
11- *
12- * @param {Partial<BaseBenchmarkSettings> } [settings] - The settings object to
13- * validate. Defaults to an empty object if not provided.
14- * @returns {string[] } Array of validation error messages.
15- */
16- let validateBaseBenchmarkSettings = (
17- settings : Partial < BaseBenchmarkSettings > = { } ,
18- ) : string [ ] => {
19- let errors : string [ ] = [ ]
20-
21- if (
22- settings . iterations !== undefined &&
23- ( typeof settings . iterations !== 'number' || settings . iterations <= 0 )
24- ) {
25- errors . push ( `"iterations" must be a positive number` )
26- }
27-
28- if (
29- settings . timeout !== undefined &&
30- ( typeof settings . timeout !== 'number' || settings . timeout <= 0 )
31- ) {
32- errors . push ( `"timeout" must be a positive number` )
33- }
34-
35- if ( settings . warmup !== undefined ) {
36- if ( typeof settings . warmup === 'object' ) {
37- if (
38- settings . warmup . iterations !== undefined &&
39- ( typeof settings . warmup . iterations !== 'number' ||
40- settings . warmup . iterations < 0 )
41- ) {
42- errors . push ( `"warmup.iterations" must be a non-negative number` )
43- }
44- if (
45- settings . warmup . enabled !== undefined &&
46- typeof settings . warmup . enabled !== 'boolean'
47- ) {
48- errors . push ( `"warmup.enabled" must be a boolean` )
49- }
50- } else {
51- errors . push ( `"warmup" must be an object` )
52- }
53- }
54- return errors
55- }
56-
579/**
5810 * Validates the user benchmark configuration according to the new structure,
5911 * including global settings, individual test specifications (`testSpec`), and
@@ -78,10 +30,10 @@ let validateBaseBenchmarkSettings = (
7830 * @returns {Promise<string[]> } A promise that resolves to an array of
7931 * validation error messages. An empty array indicates a valid configuration.
8032 */
81- export let validateConfig = async (
33+ export async function validateConfig (
8234 config : Partial < UserBenchmarkConfig > ,
8335 configDirectory : string ,
84- ) : Promise < string [ ] > => {
36+ ) : Promise < string [ ] > {
8537 let errors : string [ ] = [ ]
8638
8739 if (
@@ -202,3 +154,51 @@ export let validateConfig = async (
202154
203155 return errors
204156}
157+
158+ /**
159+ * Validates BaseBenchmarkSettings (iterations, timeout, warmup).
160+ *
161+ * @param {Partial<BaseBenchmarkSettings> } [settings] - The settings object to
162+ * validate. Defaults to an empty object if not provided.
163+ * @returns {string[] } Array of validation error messages.
164+ */
165+ function validateBaseBenchmarkSettings (
166+ settings : Partial < BaseBenchmarkSettings > = { } ,
167+ ) : string [ ] {
168+ let errors : string [ ] = [ ]
169+
170+ if (
171+ settings . iterations !== undefined &&
172+ ( typeof settings . iterations !== 'number' || settings . iterations <= 0 )
173+ ) {
174+ errors . push ( `"iterations" must be a positive number` )
175+ }
176+
177+ if (
178+ settings . timeout !== undefined &&
179+ ( typeof settings . timeout !== 'number' || settings . timeout <= 0 )
180+ ) {
181+ errors . push ( `"timeout" must be a positive number` )
182+ }
183+
184+ if ( settings . warmup !== undefined ) {
185+ if ( typeof settings . warmup === 'object' ) {
186+ if (
187+ settings . warmup . iterations !== undefined &&
188+ ( typeof settings . warmup . iterations !== 'number' ||
189+ settings . warmup . iterations < 0 )
190+ ) {
191+ errors . push ( `"warmup.iterations" must be a non-negative number` )
192+ }
193+ if (
194+ settings . warmup . enabled !== undefined &&
195+ typeof settings . warmup . enabled !== 'boolean'
196+ ) {
197+ errors . push ( `"warmup.enabled" must be a boolean` )
198+ }
199+ } else {
200+ errors . push ( `"warmup" must be an object` )
201+ }
202+ }
203+ return errors
204+ }
0 commit comments