@loadmill/core 0.3.51 → 0.3.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/package.json +2 -2
  2. package/src/conf/defaults.ts +0 -25
  3. package/src/conf/extrema.ts +0 -36
  4. package/src/conf/index.ts +0 -95
  5. package/src/conf/notifications.ts +0 -17
  6. package/src/conf/types.ts +0 -100
  7. package/src/conf/validate.ts +0 -559
  8. package/src/distributed-logger-reporter.ts +0 -19
  9. package/src/echo/firehose.ts +0 -64
  10. package/src/echo/index.ts +0 -4
  11. package/src/echo/stats.ts +0 -84
  12. package/src/har/index.ts +0 -81
  13. package/src/multipart-form-data/form-data-utils.ts +0 -81
  14. package/src/multipart-form-data/is-binary-file.ts +0 -206
  15. package/src/multipart-form-data/multipart-text-to-post-form-data.ts +0 -149
  16. package/src/parameters/extractions.ts +0 -53
  17. package/src/parameters/extractors/cheerio-extractor.ts +0 -57
  18. package/src/parameters/extractors/expression-extractor.ts +0 -13
  19. package/src/parameters/extractors/extractor.ts +0 -3
  20. package/src/parameters/extractors/header-extractor.ts +0 -24
  21. package/src/parameters/extractors/index.ts +0 -10
  22. package/src/parameters/extractors/json-path-extractor.ts +0 -63
  23. package/src/parameters/extractors/parametrized-extractor.ts +0 -27
  24. package/src/parameters/extractors/regex-extractor.ts +0 -18
  25. package/src/parameters/extractors/regex-matcher.ts +0 -17
  26. package/src/parameters/extractors/ws-extractor.ts +0 -91
  27. package/src/parameters/generate-random.ts +0 -114
  28. package/src/parameters/index.ts +0 -624
  29. package/src/parameters/json-path-utils.ts +0 -20
  30. package/src/parameters/operators/binary-operator.ts +0 -23
  31. package/src/parameters/operators/index.ts +0 -39
  32. package/src/parameters/parameter-functions/boolean-parameter-functions.ts +0 -24
  33. package/src/parameters/parameter-functions/crypto.ts +0 -55
  34. package/src/parameters/parameter-functions/json-schema.ts +0 -29
  35. package/src/parameters/parameter-functions/numeric-input-parameter-functions.ts +0 -22
  36. package/src/parameters/parameter-functions/numeric-parameter-functions.ts +0 -37
  37. package/src/parameters/parameter-functions/parameter-function-utils.ts +0 -55
  38. package/src/parameters/parameter-functions/parameter-function.ts +0 -7
  39. package/src/parameters/parameter-functions/parameter-functions.ts +0 -54
  40. package/src/parameters/parameter-functions/random-parameter-functions.ts +0 -22
  41. package/src/parameters/parameter-functions/textual-parameter-functions.ts +0 -464
  42. package/src/parameters/parameter-regex-providers.ts +0 -78
  43. package/src/parameters/resolvers/random-parameters-resolver.ts +0 -8
  44. package/src/parameters/type.ts +0 -7
  45. package/src/parameters/value-utils.ts +0 -47
  46. package/src/request/index.ts +0 -526
  47. package/src/schema/json-schema-generator.ts +0 -76
  48. package/test/conf/validate.spec.js +0 -141
  49. package/test/har/is-har.spec.js +0 -33
  50. package/test/multipart-form-data/form-data-utils.spec.ts +0 -142
  51. package/test/multipart-form-data/resources/multipart-form-data-file-text-content.json +0 -5
  52. package/test/parameters/builtin-functions.spec.js +0 -85
  53. package/test/parameters/json-path-utils.spec.ts +0 -50
  54. package/test/parameters/parameter-functions.spec.js +0 -48
  55. package/test/parameters/parameter-utils.spec.js +0 -185
  56. package/test/parameters/regex-functions.spec.ts +0 -57
  57. package/test/parameters/value-utils.spec.js +0 -73
  58. package/test/schema/json-schema-generator.spec.js +0 -227
  59. package/tsconfig.json +0 -9
@@ -1,624 +0,0 @@
1
- import isEmpty = require('lodash/isEmpty');
2
- import isEqual = require('lodash/isEqual');
3
- import uniqWith = require('lodash/uniqWith');
4
- import { Parameters, ParametersScope, SequenceExecutorParameters } from './type';
5
- import { pickRandom } from './value-utils';
6
- import * as valueUtils from './value-utils';
7
- import { operators, operatorsAsStrings } from './operators';
8
- import { resolveRandomParameter } from './resolvers/random-parameters-resolver';
9
- import {
10
- canHaveNullParameterValue,
11
- getParameterFunction,
12
- parameterFunctionOperations,
13
- } from './parameter-functions/parameter-functions';
14
- import {
15
- globalUsageRegExpProvider,
16
- spacesRegExpProvider,
17
- getParameterUsageRegexp,
18
- getParameterfunctionGroupingRegexp,
19
- getParameterOperatorsGroupingRegexp,
20
- usageRegExpProvider,
21
- PARAMETER_USAGE_PATTERN,
22
- LEGAL_PARAM_CHARS,
23
- CAPTURE_REGEX,
24
- PARAM_USAGE_REGEXP,
25
- CSRF_REGEXP,
26
- getCsrfTokenByRegexp
27
- } from './parameter-regex-providers';
28
- import * as arrayUtils from '@loadmill/universal/dist/array-utils';
29
- import { PresentableError } from '@loadmill/universal/dist/errors';
30
- import { applyJSONSchema } from './parameter-functions/json-schema';
31
- import { Assertions, Extractions, RequestLike } from '../request';
32
- import { TestConfLike, validate } from '../conf';
33
- import { getLongestJsonPathToken } from './json-path-utils';
34
-
35
- class ParameterFunctionError extends PresentableError {
36
- constructor(
37
- public readonly functionName: string,
38
- public readonly prettyError: string
39
- ) {
40
- super(`Error in function '${functionName}': ${prettyError}`);
41
-
42
- // Workaround suggested in: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
43
- Object.setPrototypeOf(this, ParameterFunctionError.prototype);
44
- }
45
- }
46
-
47
- export const BUILT_IN_VOLATILE_PARAMS = {
48
- requestBody: '__requestBody',
49
- };
50
-
51
- export const MAX_PARAM_ARRAY_SIZE = 100;
52
- export {
53
- CAPTURE_REGEX,
54
- getLongestJsonPathToken,
55
- LEGAL_PARAM_CHARS,
56
- parameterFunctionOperations,
57
- Parameters,
58
- ParametersScope,
59
- PresentableError,
60
- SequenceExecutorParameters,
61
- usageRegExpProvider,
62
- valueUtils,
63
- CSRF_REGEXP,
64
- getCsrfTokenByRegexp
65
- };
66
- export class ParameterError extends PresentableError {
67
- constructor(
68
- public readonly prettyError: string,
69
- public readonly parameter: Parameters
70
- ) {
71
- super(`Error in parameter ${parameterUtils.getParameterName(parameter)}: ${prettyError}`);
72
-
73
- // Workaround suggested in: https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
74
- Object.setPrototypeOf(this, ParameterError.prototype);
75
- }
76
- }
77
-
78
- // Order of resolving!
79
- const parameterResolvers = [
80
- resolveNoArgFunctionParameter,
81
- // This one is legacy for e.g. __random_boolean_75:
82
- resolveRandomParameter,
83
- resolvePlainParameter,
84
- ];
85
-
86
- export const parameterUtils = {
87
- isParametrized(expression: string) {
88
- return globalUsageRegExpProvider.use((regExp) => regExp.test(expression));
89
- },
90
-
91
- resolveAllExpressions(parameters: Parameters[]): Parameters {
92
- const context: Parameters = {};
93
-
94
- parameters.forEach((currentParameters: Parameters, index) => {
95
- const temp: Parameters = {};
96
-
97
- Object.keys(currentParameters).forEach(name => {
98
- try {
99
- const value = currentParameters[name];
100
- temp[name] = parameterUtils.resolveExpression(
101
- pickValue(value),
102
- context
103
- );
104
- } catch (e) {
105
- e['parameterName'] = name;
106
- e['parameterIndex'] = index;
107
- throw e;
108
- }
109
- });
110
-
111
- Object.assign(context, temp);
112
- });
113
-
114
- return context;
115
- },
116
-
117
- resolveParameter(parameterName: string, parameters: Parameters, onError?) {
118
- try {
119
- for (const resolver of parameterResolvers) {
120
- const value = resolver(parameterName, parameters);
121
-
122
- if (value != null) {
123
- return value;
124
- }
125
- }
126
- } catch (e) {
127
- if (onError) {
128
- onError(e);
129
- }
130
-
131
- throw e;
132
- }
133
- },
134
-
135
- resolveExpression(
136
- parametrized: string,
137
- parameters: Parameters | Parameters[],
138
- onError?
139
- ): string {
140
- try {
141
- if (Array.isArray(parameters)) {
142
- parameters = parameterUtils.resolveAllExpressions(parameters);
143
- }
144
-
145
- return globalUsageRegExpProvider.use((usageRegExp) => typeof parametrized !== 'string' ? parametrized :
146
- parametrized.replace(usageRegExp, (usage: string) => {
147
- // No ${}:
148
- const strippedExpression = usage.slice(2, -1).trim();
149
-
150
- // [expression, ...[operator, expression, ...]]
151
- const tokens = spacesRegExpProvider.use((spacesRegExp) =>
152
- strippedExpression.split(spacesRegExp)
153
- );
154
-
155
- // null if undefined or invalid parameters:
156
- const value = resolveTokens(tokens, parameters as Parameters);
157
-
158
- /* log.trace(`Parameter found in [${parametrized}]:`, {
159
- usage,
160
- tokens,
161
- value,
162
- }); */
163
- return value != null ? value : usage;
164
- })
165
- );
166
- } catch (e) {
167
- if (onError) {
168
- onError(e);
169
- }
170
-
171
- throw e;
172
- }
173
- },
174
-
175
- addParamToArray(key, value, arr) {
176
- arr.push({ [key]: value });
177
- },
178
-
179
- findIndex(key, arr) {
180
- if (!arr) {
181
- return -1;
182
- }
183
- return arr.findIndex((obj) => {
184
- return Object.keys(obj)[0] === key;
185
- });
186
- },
187
-
188
- getParametersRegexGroups(src: string) {
189
- return {
190
- functionGroupingRegexp: getParameterfunctionGroupingRegexp(
191
- src
192
- ),
193
- operatorsGroupingRegexp: getParameterOperatorsGroupingRegexp(
194
- src
195
- )
196
- };
197
- },
198
-
199
- suggestNewParamName(paramKey, flowConfParameters) {
200
- let flowIndex;
201
- do {
202
- let suffix = parseInt(
203
- paramKey.substr(paramKey.length - 1, paramKey.length),
204
- 10
205
- );
206
- if (Number.isInteger(suffix)) {
207
- suffix += 1;
208
- paramKey = paramKey.substr(0, paramKey.length - 1) + suffix;
209
- } else {
210
- paramKey = paramKey + '_1';
211
- }
212
-
213
- flowIndex = this.findIndex(paramKey, flowConfParameters); // new name might exist in flow conf
214
- } while (flowIndex > -1);
215
-
216
- return paramKey;
217
- },
218
-
219
- /** Search any parameters with the following patterns:
220
- * ${param1}
221
- * ${__encode_url(param1)}
222
- * ${__if_then_else(param12,'good','bad')}
223
- */
224
- searchParameterizedExpressionOccurrences(
225
- parameterName: string,
226
- data: string
227
- ): Array<string> {
228
- return data.match(getParameterUsageRegexp(parameterName)) || [];
229
- },
230
-
231
- getUsedConfParams(conf: TestConfLike, parameters: Parameters[]): Parameters[] {
232
- let usedParameters: Parameters[] = [];
233
- if (parameters) {
234
- const stringifyConf = JSON.stringify(conf);
235
- parameters.forEach((p) => {
236
- const paramName = this.getParameterName(p);
237
- if (isParamUsedInConf(paramName, conf, stringifyConf)) {
238
- const currentUsedParams = this.findUsedParameters(parameters ,p, []);
239
- usedParameters = usedParameters.concat(currentUsedParams);
240
- }
241
- });
242
- }
243
- return uniqWith(usedParameters, isEqual);
244
- },
245
-
246
- getUsedRequestParams(request, parameters: Parameters[]): Parameters[] {
247
- return this.getUsedConfParams({ requests: [request] }, parameters);
248
- },
249
-
250
- getValueByKeyFromArr(key: string, parameters: Parameters[] | undefined = [], returnArray: boolean = false) {
251
- let res;
252
- const param = getParameterByKey(key, parameters);
253
- if (param) {
254
- res = this.getParameterValue(param);
255
- if (Array.isArray(res)) {
256
- if (returnArray && res.length > 1) {
257
- return res;
258
- }
259
- return res[0];
260
- }
261
- }
262
- return res;
263
- },
264
-
265
- pickFirstValue(p: Parameters): Parameters {
266
- const name = parameterUtils.getParameterName(p);
267
- const value = parameterUtils.getParameterValue(p);
268
- if (Array.isArray(value) && value.length > 0) {
269
- return { [name]: value[0] };
270
- }
271
- return { [name]: value };
272
- },
273
- getParameterValue(parameter: Parameters) {
274
- const [value] = Object.values(parameter);
275
- return value;
276
- },
277
- getParameterName(parameter: Parameters | Extractions): string {
278
- const [name] = Object.keys(parameter);
279
- return name;
280
- },
281
- getParametersNames(parameters: Parameters[]) {
282
- return parameters.map((p) => {
283
- const [pName] = Object.keys(p);
284
- return pName;
285
- });
286
- },
287
- setParameterValue(name: string, value: string| string[], parameters: Parameters[]) {
288
- const index = this.findIndex(name, parameters);
289
- parameters[index][name] = value;
290
- },
291
- getUsedRequestParamNames(stringifiedRequest: string): string[] {
292
- const usedParams: string[] = [];
293
-
294
- const allParametersOccurrences = searchExpressionOccurrences(
295
- stringifiedRequest
296
- );
297
-
298
- allParametersOccurrences.map((paramOccurrence) => {
299
- const tokensWithoutOperators = getTokensWithoutOperators(paramOccurrence);
300
- for (const token of tokensWithoutOperators) {
301
- if (isBuiltInFunction(token)) {
302
- if (hasLeftParenthesis(token)) {
303
- const [ , ...args] = stripToFunctionAndArgs(token);
304
- for (const arg of args) {
305
- if (!isSingleQuoted(arg)) {
306
- usedParams.push(arg);
307
- }
308
- }
309
- }
310
- } else {
311
- if (!isSingleQuoted(token)) {
312
- usedParams.push(token);
313
- }
314
- }
315
- }
316
- });
317
-
318
- return usedParams;
319
- },
320
- deleteAllSrcElementsFromParamArr(paramArr, src) {
321
- let isSrcInParamArr = this.isParamKeyInArr(src, paramArr);
322
- while (isSrcInParamArr) {
323
- this.removeParameterFromArrayByKey(src, paramArr);
324
- isSrcInParamArr = this.isParamKeyInArr(src, paramArr);
325
- }
326
- },
327
- removeParameterFromArrayByKey(src, paramArr) {
328
- const index = this.findIndex(src, paramArr);
329
- paramArr.splice(index, 1);
330
- },
331
- isParamKeyInArr(key, arr) {
332
- return this.findIndex(key, arr) >= 0;
333
- },
334
- /**
335
- * Returns a Parameter ({name:value}) obj with the given value to search for.
336
- * if non found, returns undefined
337
- * @param value string | string[]
338
- * @param arr Parameters[]
339
- */
340
- findParamValueInArr(value, arr) {
341
- return arr.find(p => isEqual(this.getParameterValue(p), value));
342
- },
343
- findUsedParameters(
344
- suiteParameters: Parameters[], param: Parameters, usedParameters: Parameters[]
345
- ) {
346
- try {
347
- return findUsedParametersRecursively(suiteParameters, param, usedParameters).reverse();
348
- }
349
- catch (error) {
350
- if (error instanceof RangeError) {
351
- throw new ParameterError(
352
- 'circular dependency value' , param
353
- );
354
- } else {
355
- throw new Error(error);
356
- }
357
- }
358
- },
359
- applyJSONSchema(instance, schema) {
360
- return applyJSONSchema(instance, schema);
361
- },
362
- isUsingParameterizedValue(value: string) {
363
- return PARAM_USAGE_REGEXP.test(value);
364
- },
365
- };
366
-
367
- function resolvePlainParameter(parameterName: string, parameters) {
368
- if (parameters.hasOwnProperty(parameterName)) {
369
- return pickValue(parameters[parameterName]);
370
- }
371
- }
372
-
373
- function resolveNoArgFunctionParameter(parameterName: string, parameters) {
374
- return applyParameterFunction(
375
- parameterName,
376
- getParameterFunction(parameterName),
377
- [],
378
- parameters
379
- );
380
- }
381
-
382
- function pickValue(parameterValue: string | string[]) {
383
- return Array.isArray(parameterValue)
384
- ? pickRandom(parameterValue)
385
- : parameterValue;
386
- }
387
-
388
- function resolveTokens(tokens: string[], parameters: Parameters) {
389
- const [leftSide, operator, ...rest] = tokens;
390
-
391
- const leftSideValue = resolveArgument(leftSide, parameters);
392
-
393
- if (!operator) {
394
- return leftSideValue;
395
- }
396
-
397
- if (leftSideValue == null) {
398
- throw new ParameterFunctionError(
399
- operator,
400
- `No value for left side operand '${leftSide}'`
401
- );
402
- }
403
-
404
- const rightSideValue = resolveTokens(rest, parameters);
405
-
406
- if (rightSideValue == null) {
407
- throw new ParameterFunctionError(
408
- operator,
409
- `No value for right side operand '${rest[0]}'`
410
- );
411
- }
412
-
413
- return applyParameterFunction(operator, resolveOperator(operator), [
414
- leftSideValue,
415
- rightSideValue,
416
- ]);
417
- }
418
-
419
- function resolveArgument(arg: string, parameters: Parameters) {
420
- if (arg.startsWith('\'')) {
421
- return resolveLiteral(arg);
422
- } else if (arg.includes('(')) {
423
- return resolveParameterFunction(arg, parameters);
424
- } else {
425
- return parameterUtils.resolveParameter(arg, parameters);
426
- }
427
- }
428
-
429
- function resolveLiteral(literal: string) {
430
- return literal.slice(1, -1);
431
- }
432
-
433
- function resolveParameterFunction(
434
- functionUsage: string,
435
- parameters: Parameters
436
- ) {
437
- let [functionName, ...args] = functionUsage
438
- .replace(/\(/, ',')
439
- .slice(0, -1)
440
- .split(',');
441
-
442
- if (args.length === 1 && args[0] === '') {
443
- /// No args case, e.g. ${func()}
444
- args = [];
445
- }
446
-
447
- return applyParameterFunction(
448
- functionName,
449
- getParameterFunction(functionName),
450
- args,
451
- parameters
452
- );
453
- }
454
-
455
- function applyParameterFunction(
456
- functionName: string,
457
- parameterFunction,
458
- args,
459
- parameters?
460
- ) {
461
- if (parameterFunction) {
462
- const { minArgs, maxArgs, operate } = parameterFunction;
463
-
464
- if (minArgs != null && args.length < minArgs) {
465
- throw new ParameterFunctionError(
466
- functionName,
467
- `Must have at least ${minArgs} arguments`
468
- );
469
- } else if (maxArgs != null && args.length > maxArgs) {
470
- throw new ParameterFunctionError(
471
- functionName,
472
- `Cannot have more than ${maxArgs} arguments`
473
- );
474
- }
475
-
476
- if (parameters) {
477
- args = args.map((arg, index) => {
478
- const value = resolveArgument(arg, parameters);
479
-
480
- if (value == null) {
481
- if (canHaveNullParameterValue(functionName)) {
482
- return '';
483
- }
484
- throw new ParameterFunctionError(
485
- functionName,
486
- `No value for '${arg}' at index ${index}`
487
- );
488
- }
489
-
490
- return value;
491
- });
492
- }
493
- try {
494
- return operate(...args);
495
- } catch (e) {
496
- // log.debug('Parameter function error caught:', { functionName }, e);
497
- throw new ParameterFunctionError(
498
- functionName,
499
- e.prettyMessage || 'Unexpected error'
500
- );
501
- }
502
- }
503
- }
504
-
505
- function resolveOperator(opSymbol: string) {
506
- return operators[opSymbol].parameterFunction;
507
- }
508
-
509
- function findUsedParametersRecursively(
510
- suiteParameters: Parameters[], param: Parameters, usedParameters: Parameters[]
511
- ) : Parameters[] {
512
- const paramValueStringified = JSON.stringify(parameterUtils.getParameterValue(param));
513
- const currentUsedParameterNames = parameterUtils.getUsedRequestParamNames(paramValueStringified);
514
-
515
- if (!usedParameters.some(p => isEqual(p, param))) {
516
- const smallestIndex = getSmallestIndexInParamArr(currentUsedParameterNames, usedParameters);
517
- usedParameters.splice(smallestIndex, 0, param);
518
- }
519
- if (isEmpty(currentUsedParameterNames)) {
520
- return usedParameters;
521
- }
522
- for (const paramName of currentUsedParameterNames) {
523
- const newParam = getParameterByKey(paramName, suiteParameters);
524
- if (newParam) {
525
- findUsedParametersRecursively(suiteParameters, newParam, usedParameters);
526
- }
527
- }
528
- return usedParameters;
529
- }
530
-
531
- const getSmallestIndexInParamArr = (paramNames: string[], parameters: Parameters[]): number => {
532
- let smallestIndex = 0;
533
- if (arrayUtils.isNonEmptyArray(parameters)) {
534
- smallestIndex = parameters.length;
535
- for (const name of paramNames) {
536
- const candidateIndex = parameterUtils.findIndex(name, parameters);
537
- if (candidateIndex > -1 && candidateIndex < smallestIndex) {
538
- smallestIndex = candidateIndex;
539
- }
540
- }
541
- }
542
- return smallestIndex;
543
- };
544
-
545
- const getParameterByKey = (key: string, parameters: Parameters[]): Parameters | null => {
546
- const index = parameterUtils.findIndex(key, parameters);
547
- return index > -1 ? parameters[index] : null;
548
- };
549
-
550
- /**
551
- * a single quoted string starts and ends with a ' (single quote) char
552
- * for example str = "'arnon'"
553
- */
554
- const isSingleQuoted = (s: string): boolean => s.startsWith('\'') && s.endsWith('\'');
555
-
556
- const hasLeftParenthesis = (s: string): boolean => s.includes('(');
557
-
558
- export const stripToFunctionAndArgs = (s: string): string[] =>
559
- s.replace(/\(/, ',').slice(0, -1).split(',');
560
-
561
- export const stripParam = (s: string): string => s.replace(/\$|{|}/g, '');
562
-
563
- const getTokens = (strippedExpression: string): string[] =>
564
- spacesRegExpProvider.use((spacesRegExp) =>
565
- strippedExpression.split(spacesRegExp)
566
- );
567
-
568
- const stripOperators = (tokens: string[]): string[] =>
569
- tokens.filter((t) => !operatorsAsStrings.includes(t));
570
-
571
- const getSubstringUntilChar = (s: string, c: string) => typeof s === 'string' ? s.split(c)[0] : '';
572
-
573
- const isBuiltInFunction = (s: string) => getParameterFunction(getSubstringUntilChar(s, '('));
574
-
575
- /* gets a string and returns all occurrences of ${...something/nothing..} */
576
- export const searchExpressionOccurrences = (s: string): string[] =>
577
- s.match(new RegExp(PARAMETER_USAGE_PATTERN, 'g')) || [];
578
-
579
- export const getTokensWithoutOperators = (paramOccurrence: string): string[] => {
580
- const strippedParam = stripParam(paramOccurrence);
581
- const tokens = getTokens(strippedParam);
582
- return stripOperators(tokens);
583
- };
584
-
585
- function isParamUsedInConf(paramName: string, conf: TestConfLike, stringifyConf: string): boolean {
586
- return !isEmpty(parameterUtils.searchParameterizedExpressionOccurrences(paramName, stringifyConf)) ||
587
- isParamNameUsedInConf(paramName, conf);
588
- }
589
-
590
- function isParamNameUsedInField(paramName: string, fieldValue?: string): boolean {
591
- return !!fieldValue && fieldValue === paramName;
592
- }
593
-
594
- function isParamNameUsedInAssertions(paramName: string, assertions: Assertions = []): boolean {
595
- return assertions.some(assertion => assertion.check === paramName);
596
- }
597
-
598
- function isParamNameUsedInRequest(paramName: string, request: RequestLike): boolean {
599
- return isParamNameUsedInAssertions(paramName, request.assert) ||
600
- isParamNameUsedInField(paramName, request.loop?.assert?.check) ||
601
- isParamNameUsedInField(paramName, request.skipBefore?.condition) ||
602
- isParamNameUsedInField(paramName, request.stopBefore);
603
- }
604
-
605
- function isParamNameUsedInConf(paramName: string, conf: TestConfLike): boolean {
606
- if (!isEmpty(conf.requests)) {
607
- return conf.requests.some(req => isParamNameUsedInRequest(paramName, req));
608
- }
609
- return false;
610
- }
611
-
612
- export function removeNonStringParameters(conf) {
613
- const parameters = conf.parameters as Parameters[];
614
- if (parameters) {
615
- conf.parameters = parameters.filter(p =>
616
- isEmpty(
617
- validate.parameter(
618
- parameterUtils.getParameterName(p),
619
- parameterUtils.getParameterValue(p)
620
- )
621
- )
622
- );
623
- }
624
- }
@@ -1,20 +0,0 @@
1
- import jsonpath from 'jsonpath';
2
-
3
- type jsonPathComponent = {
4
- expression: {
5
- type: string,
6
- value: string
7
- };
8
- scope: string;
9
- operation: string;
10
- };
11
-
12
- export const getLongestJsonPathToken = (jsonPath: string) => {
13
- const pathExpressionsValues = (jsonpath.parse(jsonPath) as jsonPathComponent[])
14
- .map(p => p.expression.value);
15
-
16
- const longestToken = pathExpressionsValues.reduce(longestStringReducer);
17
- return longestToken;
18
- };
19
-
20
- const longestStringReducer = (prev: string, curr: string) => curr.length > prev.length ? curr : prev;
@@ -1,23 +0,0 @@
1
- import { ParameterFunction } from '../parameter-functions/parameter-function';
2
-
3
- export class BinaryOperator {
4
- readonly regexSymbol;
5
-
6
- /**
7
- *
8
- * @param {string[]} symbols
9
- * @param {ParameterFunction} parameterFunction
10
- * @param {string} regexSymbol Must NOT contain any capture groups! I.e. use non-capturing (?:) instead.
11
- */
12
- constructor(
13
- readonly symbols: string[],
14
- readonly parameterFunction: ParameterFunction,
15
- regexSymbol?: string
16
- ) {
17
- this.regexSymbol =
18
- regexSymbol ||
19
- symbols
20
- .map((symbol) => (symbol.length > 1 ? `(?:${symbol})` : symbol))
21
- .join('|');
22
- }
23
- }
@@ -1,39 +0,0 @@
1
- import { BinaryOperator } from './binary-operator';
2
- import { textualParameterFunctions } from '../parameter-functions/textual-parameter-functions';
3
- import { booleanParameterFunctions } from '../parameter-functions/boolean-parameter-functions';
4
- import { numericInputParameterFunctions } from '../parameter-functions/numeric-input-parameter-functions';
5
- import { numericParameterFunctions } from '../parameter-functions/numeric-parameter-functions';
6
-
7
- export const operators = mapOperators(
8
- new BinaryOperator(['=', '==', '==='], textualParameterFunctions.__eq),
9
- new BinaryOperator(['!=', '!=='], textualParameterFunctions.__neq),
10
-
11
- new BinaryOperator(['&', '&&'], booleanParameterFunctions.__and),
12
- new BinaryOperator(
13
- ['|', '||'],
14
- booleanParameterFunctions.__or,
15
- '\\||(?:\\|\\|)'
16
- ),
17
-
18
- new BinaryOperator(['<'], numericInputParameterFunctions.__lt),
19
-
20
- new BinaryOperator(['>'], numericInputParameterFunctions.__gt),
21
-
22
- new BinaryOperator(['<='], numericInputParameterFunctions.__lte),
23
-
24
- new BinaryOperator(['>='], numericInputParameterFunctions.__gte),
25
-
26
- new BinaryOperator(['+'], numericParameterFunctions.__add, '\\+'),
27
- new BinaryOperator(['-'], numericParameterFunctions.__sub),
28
- new BinaryOperator(['*'], numericParameterFunctions.__mult, '\\*'),
29
- new BinaryOperator(['/'], numericParameterFunctions.__div)
30
- );
31
-
32
- function mapOperators(...operators: BinaryOperator[]) {
33
- return operators.reduce((obj, op) => {
34
- op.symbols.forEach((symbol) => (obj[symbol] = op));
35
- return obj;
36
- }, {} as { [symbol: string]: BinaryOperator });
37
- }
38
-
39
- export const operatorsAsStrings = Object.keys(operators);