artillery-plugin-fake-data 1.22.0 → 1.23.0-67648ae

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 (3) hide show
  1. package/README.md +8 -2
  2. package/index.js +107 -21
  3. package/package.json +11 -3
package/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # artillery-plugin-fake-data
2
2
 
3
- ## Easy randomised test data leveraging falso
3
+ ## Easy randomised test data leveraging Faker
4
4
 
5
- With this plugin, you can add random test data using [falso](https://ngneat.github.io/falso/docs) straight into YAML, giving you a wide range of test data options to choose from. You'll also be able to use the same functions in your `beforeRequest`/`afterResponse` hooks. Check the documentation for more information.
5
+ With this plugin, you can add random test data using [Faker](https://fakerjs.dev/api/) straight into YAML, giving you a wide range of test data options to choose from. You'll also be able to use the same functions in your `beforeRequest`/`afterResponse` hooks. Check the documentation for more information.
6
+
7
+ Faker functions are exposed with flattened names: `faker.internet.email()` becomes `$internetEmail()`, `faker.person.fullName()` becomes `$personFullName()`, and so on.
8
+
9
+ ### Migrating from falso
10
+
11
+ Earlier versions of this plugin used [falso](https://ngneat.github.io/falso/). The most commonly used falso-style names (e.g. `$randEmail`, `$randFullName`, `$randPassword`) still work as deprecated aliases, but will be removed in a future release. Function configuration options now use Faker's option shapes (e.g. `internetPassword: { length: 5 }` instead of `randPassword: { size: 5 }`). See the [plugin documentation](https://www.artillery.io/docs/reference/extensions/fake-data) for a migration table.
6
12
 
7
13
  ## Documentation
8
14
 
package/index.js CHANGED
@@ -1,22 +1,94 @@
1
- const falso = require('@ngneat/falso');
1
+ const { faker } = require('@faker-js/faker');
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;
3
+ // Modules that don't expose simple data-generation functions
4
+ const SKIPPED_MODULES = new Set(['helpers', 'definitions', 'rawDefinitions']);
5
+
6
+ // Deprecated falso-style aliases kept for backwards compatibility.
7
+ // Maps legacy `$rand*` names to their faker equivalents (flattened names).
8
+ // NOTE: configuration options are NOT translated - options must be provided
9
+ // using the faker option shape, under the faker function name.
10
+ const DEPRECATED_ALIASES = {
11
+ randEmail: 'internetEmail',
12
+ randFullName: 'personFullName',
13
+ randFirstName: 'personFirstName',
14
+ randLastName: 'personLastName',
15
+ randUserName: 'internetUsername',
16
+ randPassword: 'internetPassword',
17
+ randUuid: 'stringUuid',
18
+ randPhoneNumber: 'phoneNumber',
19
+ randCity: 'locationCity',
20
+ randCountry: 'locationCountry',
21
+ randStreetAddress: 'locationStreetAddress',
22
+ randZipCode: 'locationZipCode',
23
+ randCompanyName: 'companyName',
24
+ randNumber: 'numberInt',
25
+ randBoolean: 'datatypeBoolean',
26
+ randUrl: 'internetUrl',
27
+ randIp: 'internetIpv4',
28
+ randWord: 'loremWord',
29
+ randSentence: 'loremSentence',
30
+ randParagraph: 'loremParagraph',
31
+ randText: 'loremText',
32
+ randJobTitle: 'personJobTitle',
33
+ randColor: 'colorHuman',
34
+ randProductName: 'commerceProductName'
35
+ };
36
+
37
+ const flattenName = (moduleName, functionName) =>
38
+ `${moduleName}${functionName[0].toUpperCase()}${functionName.slice(1)}`;
39
+
40
+ // Builds a map of flattened function names (e.g. `internetEmail`) to
41
+ // zero/one-argument faker functions (e.g. `faker.internet.email`)
42
+ const buildFakerFunctionMap = () => {
43
+ const functions = {};
44
+
45
+ for (const moduleName of Object.keys(faker)) {
46
+ if (SKIPPED_MODULES.has(moduleName) || moduleName.startsWith('_')) {
47
+ continue;
8
48
  }
9
49
 
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;
50
+ const mod = faker[moduleName];
51
+ if (!mod || typeof mod !== 'object') {
52
+ continue;
14
53
  }
15
54
 
16
- return true;
17
- });
55
+ // Walk the prototype chain: some faker modules inherit methods
56
+ // (e.g. DateModule extends SimpleDateModule)
57
+ let proto = Object.getPrototypeOf(mod);
58
+ while (proto && proto !== Object.prototype) {
59
+ for (const functionName of Object.getOwnPropertyNames(proto)) {
60
+ if (functionName === 'constructor' || functionName.startsWith('_')) {
61
+ continue;
62
+ }
63
+
64
+ if (typeof mod[functionName] !== 'function') {
65
+ continue;
66
+ }
67
+
68
+ // Only functions taking at most one argument are supported, as
69
+ // configuration is passed as a single (object) argument
70
+ if (mod[functionName].length > 1) {
71
+ continue;
72
+ }
73
+
74
+ const flatName = flattenName(moduleName, functionName);
75
+ if (!functions[flatName]) {
76
+ functions[flatName] = mod[functionName].bind(mod);
77
+ }
78
+ }
18
79
 
19
- const falsoFunctions = getFalsoFunctions();
80
+ proto = Object.getPrototypeOf(proto);
81
+ }
82
+ }
83
+
84
+ return functions;
85
+ };
86
+
87
+ const fakerFunctionMap = buildFakerFunctionMap();
88
+
89
+ const getFakerFunctions = () => Object.keys(fakerFunctionMap);
90
+
91
+ const warnedAliases = new Set();
20
92
 
21
93
  function ArtilleryPluginFakeData(script, events) {
22
94
  this.script = script;
@@ -25,22 +97,35 @@ function ArtilleryPluginFakeData(script, events) {
25
97
  const pluginConfig =
26
98
  script.config['fake-data'] || script.config.plugins['fake-data'];
27
99
 
28
- function falsoHandler(context, _ee, next) {
29
- falsoFunctions.forEach((funcName) => {
100
+ function fakeDataHandler(context, _ee, next) {
101
+ for (const [funcName, fakerFunc] of Object.entries(fakerFunctionMap)) {
30
102
  context.funcs[`$${funcName}`] = () => {
31
103
  if (pluginConfig[funcName]) {
32
- return falso[funcName](pluginConfig[funcName]);
104
+ return fakerFunc(pluginConfig[funcName]);
33
105
  }
34
- return falso[funcName]();
106
+ return fakerFunc();
35
107
  };
36
- });
108
+ }
109
+
110
+ for (const [aliasName, funcName] of Object.entries(DEPRECATED_ALIASES)) {
111
+ context.funcs[`$${aliasName}`] = () => {
112
+ if (!warnedAliases.has(aliasName)) {
113
+ warnedAliases.add(aliasName);
114
+ console.warn(
115
+ `[fake-data] $${aliasName} is deprecated and will be removed in a future release. Use $${funcName} instead.`
116
+ );
117
+ }
118
+
119
+ return context.funcs[`$${funcName}`]();
120
+ };
121
+ }
37
122
 
38
123
  next();
39
124
  }
40
125
 
41
126
  script.scenarios = script.scenarios.map((scenario) => {
42
127
  scenario.beforeScenario = [].concat(scenario.beforeScenario || []);
43
- scenario.beforeScenario.push('falsoHandler');
128
+ scenario.beforeScenario.push('fakeDataHandler');
44
129
  return scenario;
45
130
  });
46
131
 
@@ -48,12 +133,13 @@ function ArtilleryPluginFakeData(script, events) {
48
133
  script.config.processor = {};
49
134
  }
50
135
 
51
- script.config.processor.falsoHandler = falsoHandler;
136
+ script.config.processor.fakeDataHandler = fakeDataHandler;
52
137
 
53
138
  return this;
54
139
  }
55
140
 
56
141
  module.exports = {
57
142
  Plugin: ArtilleryPluginFakeData,
58
- getFalsoFunctions
143
+ getFakerFunctions,
144
+ getDeprecatedAliases: () => ({ ...DEPRECATED_ALIASES })
59
145
  };
package/package.json CHANGED
@@ -1,16 +1,24 @@
1
1
  {
2
2
  "name": "artillery-plugin-fake-data",
3
- "version": "1.22.0",
3
+ "version": "1.23.0-67648ae",
4
4
  "description": "Add fake test data easily to your Artillery test scripts.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 0"
10
+ "test": "tap ./test/*.spec.js --timeout 120"
11
+ },
12
+ "tap": {
13
+ "disable-coverage": true,
14
+ "allow-empty-coverage": true,
15
+ "color": true
11
16
  },
12
17
  "license": "MPL-2.0",
13
18
  "dependencies": {
14
- "@ngneat/falso": "^8.0.2"
19
+ "@faker-js/faker": "10.4.0"
20
+ },
21
+ "devDependencies": {
22
+ "tap": "^19.0.2"
15
23
  }
16
24
  }