artillery-plugin-fake-data 1.0.1 → 1.0.2

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 (2) hide show
  1. package/index.js +22 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,5 +1,23 @@
1
1
  const falso = require('@ngneat/falso');
2
2
 
3
+ const getFalsoFunctions = () =>
4
+ Object.keys(falso).filter((funcName) => {
5
+ //functions that have the function signature we expect start with rand and aren't == rand (which takes an array)
6
+ if (!funcName.startsWith('rand') && funcName != 'rand') {
7
+ return false;
8
+ }
9
+
10
+ //don't add functions that have more than 1 argument, as we only support 1 argument
11
+ //we can look into adding support for more arguments later, but most of the functions available use 1 argument anyway
12
+ if (falso[funcName].length > 1) {
13
+ return false;
14
+ }
15
+
16
+ return true;
17
+ });
18
+
19
+ const falsoFunctions = getFalsoFunctions();
20
+
3
21
  function ArtilleryPluginFakeData(script, events) {
4
22
  this.script = script;
5
23
  this.events = events;
@@ -8,26 +26,14 @@ function ArtilleryPluginFakeData(script, events) {
8
26
  script.config['fake-data'] || script.config.plugins['fake-data'];
9
27
 
10
28
  function falsoHandler(context, ee, next) {
11
- for (let funcName of Object.keys(falso)) {
12
- //functions that have the function signature we expect start with rand and aren't == rand (which takes an array
13
- //e.g. seed,
14
- if (!funcName.startsWith('rand') && funcName != 'rand') {
15
- continue;
16
- }
17
-
18
- //don't add functions that have more than 1 argument, as we only support 1 argument
19
- //we can look into adding support for more arguments later, but most of the functions available use 1 argument anyway
20
- if (falso[funcName].length > 1) {
21
- continue;
22
- }
23
-
29
+ falsoFunctions.forEach((funcName) => {
24
30
  context.funcs[`$${funcName}`] = function () {
25
31
  if (pluginConfig[funcName]) {
26
32
  return falso[funcName](pluginConfig[funcName]);
27
33
  }
28
34
  return falso[funcName]();
29
35
  };
30
- }
36
+ });
31
37
 
32
38
  next();
33
39
  }
@@ -48,5 +54,6 @@ function ArtilleryPluginFakeData(script, events) {
48
54
  }
49
55
 
50
56
  module.exports = {
51
- Plugin: ArtilleryPluginFakeData
57
+ Plugin: ArtilleryPluginFakeData,
58
+ getFalsoFunctions
52
59
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "artillery-plugin-fake-data",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Add fake test data easily to your Artillery test scripts.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {