@gatling.io/cli 3.11.7 → 3.12.0

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 (52) hide show
  1. package/package.json +4 -4
  2. package/src/bundle.ts +36 -0
  3. package/src/commands/build.ts +30 -0
  4. package/src/commands/enterpriseDeploy.ts +88 -0
  5. package/src/commands/enterprisePackage.ts +41 -0
  6. package/src/commands/enterpriseStart.ts +113 -0
  7. package/src/commands/index.ts +25 -0
  8. package/src/commands/install.ts +19 -0
  9. package/src/commands/options.ts +263 -0
  10. package/src/commands/recorder.ts +41 -0
  11. package/src/commands/run.ts +78 -0
  12. package/src/commands/runOnly.ts +56 -0
  13. package/src/dependencies/coursier.ts +82 -0
  14. package/src/dependencies/download.ts +11 -0
  15. package/src/dependencies/graalVm.ts +74 -0
  16. package/src/dependencies/index.ts +44 -0
  17. package/src/dependencies/os.ts +24 -0
  18. package/src/dependencies/versions.ts +12 -0
  19. package/src/enterprise.ts +225 -0
  20. package/src/index.ts +5 -0
  21. package/src/java.ts +48 -0
  22. package/src/log.ts +19 -0
  23. package/src/readline.ts +39 -0
  24. package/src/run.ts +67 -0
  25. package/src/simulations.ts +29 -0
  26. package/target/commands/build.d.ts +3 -0
  27. package/target/commands/build.js +20 -0
  28. package/target/commands/enterpriseDeploy.d.ts +3 -0
  29. package/target/commands/enterpriseDeploy.js +59 -0
  30. package/target/commands/enterprisePackage.d.ts +3 -0
  31. package/target/commands/enterprisePackage.js +26 -0
  32. package/target/commands/enterpriseStart.d.ts +3 -0
  33. package/target/commands/enterpriseStart.js +75 -0
  34. package/target/commands/index.d.ts +2 -0
  35. package/target/commands/index.js +28 -0
  36. package/target/commands/install.d.ts +3 -0
  37. package/target/commands/install.js +18 -0
  38. package/target/commands/options.d.ts +46 -0
  39. package/target/commands/options.js +169 -0
  40. package/target/commands/recorder.d.ts +3 -0
  41. package/target/commands/recorder.js +28 -0
  42. package/target/commands/run.d.ts +3 -0
  43. package/target/commands/run.js +51 -0
  44. package/target/commands/runOnly.d.ts +3 -0
  45. package/target/commands/runOnly.js +37 -0
  46. package/target/dependencies/index.d.ts +1 -0
  47. package/target/dependencies/index.js +3 -1
  48. package/target/dependencies/versions.js +2 -2
  49. package/target/enterprise.js +5 -5
  50. package/target/index.js +2 -337
  51. package/target/run.js +4 -2
  52. package/tsconfig.json +18 -0
package/target/index.js CHANGED
@@ -1,340 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
3
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const commander_1 = require("commander");
8
- const os_1 = __importDefault(require("os"));
9
- const bundle_1 = require("./bundle");
10
- const dependencies_1 = require("./dependencies");
11
- const enterprise_1 = require("./enterprise");
12
- const simulations_1 = require("./simulations");
13
- const log_1 = require("./log");
14
- const readline_1 = require("./readline");
15
- const run_1 = require("./run");
16
- const program = new commander_1.Command()
17
- .name("gatling-js-cli")
18
- .version("0.0.1")
19
- .description("The Gatling Javascript run & packaging tool");
20
- const gatlingHomeOption = new commander_1.Option("--gatling-home <value>", 'The folder used to download and install Gatling components (default: "~/.gatling")');
21
- const gatlingHomeDirWithDefaults = (options) => options.gatlingHome || `${os_1.default.homedir()}/.gatling`;
22
- const sourcesFolderOption = new commander_1.Option("--sources-folder <value>", "The sources folder path").default("src");
23
- const simulationOption = new commander_1.Option("--simulation <value>", "The simulation entry point function name (default: if only one *.gatling.js or *.gatling.ts file is found, will execute that simulation)");
24
- const simulationWithDefaults = (options, simulationsFound, interactive) => {
25
- if (options.simulation !== undefined) {
26
- return options.simulation;
27
- }
28
- else if (simulationsFound.length === 1) {
29
- return simulationsFound[0].name;
30
- }
31
- else if (simulationsFound.length === 0) {
32
- throw new Error("No simulation found, simulations must be defined in a <simulation name>.gatling.js or <simulation name>.gatling.ts file)");
33
- }
34
- else if (interactive) {
35
- const idx = (0, readline_1.keyInSelectPaginated)(simulationsFound.map((s) => s.name).sort((a, b) => a.localeCompare(b)), "Choose a simulation to run");
36
- if (idx >= 0) {
37
- const simulation = simulationsFound[idx].name;
38
- log_1.logger.info(`Simulation '${simulation}' was chosen.`);
39
- return simulation;
40
- }
41
- else {
42
- throw new Error("Simulation choice was cancelled.");
43
- }
44
- }
45
- else {
46
- throw new Error(`Several simulations found, specify one using the --simulation option (available simulations: ${simulationsFound.map((s) => s.name)})`);
47
- }
48
- };
49
- const simulationRequiredOption = new commander_1.Option("--simulation <value>", "The simulation entry point function name").makeOptionMandatory(true);
50
- const bundleFileOption = new commander_1.Option("--bundle-file <value>", "The target bundle file path when building simulations (must have a .js extension)").default("target/bundle.js");
51
- const validateBundleFile = (options) => {
52
- if (!options.bundleFile.endsWith(".js")) {
53
- throw Error(`'${options.bundleFile}' is not a valid bundle file path: should have a .js extension`);
54
- }
55
- return options.bundleFile;
56
- };
57
- const packageFileOption = new commander_1.Option("--package-file <value>", "The target package file path when packaging simulations for Gatling Enterprise (must have a .zip extension)").default("target/package.zip");
58
- const validatePackageFile = (options) => {
59
- if (!options.packageFile.endsWith(".zip")) {
60
- throw Error(`'${options.packageFile}' is not a valid package file path: should have a .zip extension`);
61
- }
62
- return options.packageFile;
63
- };
64
- const resourcesFolderOption = new commander_1.Option("--resources-folder <value>", "The resources folder path").default("resources");
65
- const resultsFolderOption = new commander_1.Option("--results-folder <value>", "The results folder path").default("target/gatling");
66
- const typescriptOption = new commander_1.Option("--typescript", "Use the typescript compiler to compile your code (default: true if the sourcesFolder contains any *.gatling.ts file, false otherwise)");
67
- const typescriptWithDefaults = (options, simulationsFound) => options.typescript !== undefined
68
- ? options.typescript
69
- : simulationsFound.findIndex((s) => s.type === "typescript") >= 0;
70
- const graalvmHomeMandatoryOption = new commander_1.Option("--graalvm-home <value>", "Path to the GraalVM home").makeOptionMandatory(true);
71
- const jvmClasspathMandatoryOption = new commander_1.Option("--jvm-classpath <value>", "The classpath containing all Gatling JVM components").makeOptionMandatory(true);
72
- const memoryOption = new commander_1.Option("--memory <value>", "Heap space memory size in MiB for Gatling. Half the total available memory is usually a good default, as the Gatling process will use more memory than just the heap space.").argParser((value) => {
73
- const parsedValue = parseInt(value, 10);
74
- if (isNaN(parsedValue)) {
75
- throw new Error(`${value} is not a valid memory size, must be an integer number`);
76
- }
77
- return parsedValue;
78
- });
79
- const nonInteractiveOption = new commander_1.Option("--non-interactive", "Switch to non-interactive mode and fail if no simulation is explicitly specified").default(false);
80
- const runParametersArgument = new commander_1.Argument("[optionKey=optionValue...]", "Specify one or more parameter which can be read in the simulation script with the getParameter() function; format must be key=value");
81
- const parseRunParameters = (args) => {
82
- const parsedParameters = {};
83
- for (const arg of args) {
84
- const i = arg.indexOf("=");
85
- if (i < 0) {
86
- throw Error(`Parameter '${arg}' is not valid: format should be key=value`);
87
- }
88
- else {
89
- const key = arg.slice(0, i).trim();
90
- parsedParameters[key] = arg.slice(i + 1);
91
- }
92
- }
93
- return parsedParameters;
94
- };
95
- program
96
- .command("install")
97
- .description("Install all required components and dependencies for Gatling")
98
- .addOption(gatlingHomeOption)
99
- .action(async (options) => {
100
- const gatlingHome = gatlingHomeDirWithDefaults(options);
101
- const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installGatlingJs)({ gatlingHome });
102
- log_1.logger.info(`graalvmHome=${graalvmHome}`);
103
- log_1.logger.info(`coursierBinary=${coursierBinary}`);
104
- log_1.logger.info(`jvmClasspath=${jvmClasspath}`);
105
- });
106
- program
107
- .command("build")
108
- .description("Build Gatling simulations")
109
- .addOption(sourcesFolderOption)
110
- .addOption(bundleFileOption)
111
- .addOption(typescriptOption)
112
- .action(async (options) => {
113
- const sourcesFolder = options.sourcesFolder;
114
- const bundleFile = validateBundleFile(options);
115
- const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
116
- const typescript = typescriptWithDefaults(options, simulations);
117
- await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
118
- });
119
- program
120
- .command("run-only")
121
- .description("Run a Gatling simulation from an already built bundle")
122
- .addOption(graalvmHomeMandatoryOption)
123
- .addOption(jvmClasspathMandatoryOption)
124
- .addOption(simulationRequiredOption)
125
- .addOption(bundleFileOption)
126
- .addOption(resourcesFolderOption)
127
- .addOption(resultsFolderOption)
128
- .addOption(memoryOption)
129
- .addArgument(runParametersArgument)
130
- .action(async (args, options) => {
131
- const graalvmHome = options.graalvmHome;
132
- const jvmClasspath = options.jvmClasspath;
133
- const simulation = options.simulation;
134
- const bundleFile = validateBundleFile(options);
135
- const resourcesFolder = options.resourcesFolder;
136
- const resultsFolder = options.resultsFolder;
137
- const memory = options.memory;
138
- const runParameters = parseRunParameters(args);
139
- await (0, run_1.runSimulation)({
140
- graalvmHome,
141
- jvmClasspath,
142
- simulation: simulation,
143
- bundleFile,
144
- resourcesFolder,
145
- resultsFolder,
146
- memory,
147
- runParameters
148
- });
149
- });
150
- program
151
- .command("run")
152
- .description("Build and run a Gatling simulation, after installing all required components and dependencies for Gatling")
153
- .addOption(sourcesFolderOption)
154
- .addOption(simulationOption)
155
- .addOption(typescriptOption)
156
- .addOption(bundleFileOption)
157
- .addOption(resourcesFolderOption)
158
- .addOption(resultsFolderOption)
159
- .addOption(gatlingHomeOption)
160
- .addOption(memoryOption)
161
- .addOption(nonInteractiveOption)
162
- .addArgument(runParametersArgument)
163
- .action(async (args, options) => {
164
- const gatlingHome = gatlingHomeDirWithDefaults(options);
165
- const sourcesFolder = options.sourcesFolder;
166
- const bundleFile = validateBundleFile(options);
167
- const resourcesFolder = options.resourcesFolder;
168
- const resultsFolder = options.resultsFolder;
169
- const memory = options.memory;
170
- const nonInteractive = options.nonInteractive;
171
- const runParameters = parseRunParameters(args);
172
- const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
173
- const typescript = typescriptWithDefaults(options, simulations);
174
- const simulation = simulationWithDefaults(options, simulations, !nonInteractive);
175
- const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installGatlingJs)({ gatlingHome });
176
- log_1.logger.debug(`graalvmHome=${graalvmHome}`);
177
- log_1.logger.debug(`coursierBinary=${coursierBinary}`);
178
- log_1.logger.debug(`jvmClasspath=${jvmClasspath}`);
179
- await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
180
- await (0, run_1.runSimulation)({
181
- graalvmHome,
182
- jvmClasspath,
183
- simulation,
184
- bundleFile,
185
- resourcesFolder,
186
- resultsFolder,
187
- memory,
188
- runParameters
189
- });
190
- });
191
- program
192
- .command("recorder")
193
- .description("Run the Gatling recorder")
194
- .addOption(gatlingHomeOption)
195
- .addOption(sourcesFolderOption)
196
- .addOption(typescriptOption)
197
- .addOption(resourcesFolderOption)
198
- .action(async (options) => {
199
- const gatlingHome = gatlingHomeDirWithDefaults(options);
200
- const sourcesFolder = options.sourcesFolder;
201
- const resourcesFolder = options.resourcesFolder;
202
- const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
203
- const typescript = typescriptWithDefaults(options, simulations);
204
- const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installRecorder)({ gatlingHome });
205
- log_1.logger.debug(`graalvmHome=${graalvmHome}`);
206
- log_1.logger.debug(`coursierBinary=${coursierBinary}`);
207
- log_1.logger.debug(`jvmClasspath=${jvmClasspath}`);
208
- await (0, run_1.runRecorder)({ graalvmHome, jvmClasspath, sourcesFolder, typescript, resourcesFolder });
209
- });
210
- program
211
- .command("enterprise-package")
212
- .description("Build Gatling simulations and package them for Gatling Enterprise")
213
- .addOption(sourcesFolderOption)
214
- .addOption(resourcesFolderOption)
215
- .addOption(bundleFileOption)
216
- .addOption(packageFileOption)
217
- .addOption(typescriptOption)
218
- .action(async (options) => {
219
- const sourcesFolder = options.sourcesFolder;
220
- const resourcesFolder = options.resourcesFolder;
221
- const bundleFile = validateBundleFile(options);
222
- const packageFile = validatePackageFile(options);
223
- const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
224
- const typescript = typescriptWithDefaults(options, simulations);
225
- await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
226
- await (0, enterprise_1.enterprisePackage)({ bundleFile, resourcesFolder, packageFile, simulations });
227
- });
228
- const urlOption = new commander_1.Option("--url <value>", "URL of Gatling Enterprise")
229
- .default("https://cloud.gatling.io")
230
- .hideHelp();
231
- const apiTokenOption = new commander_1.Option("--api-token <value>", "API Token on Gatling Enterprise. Prefer configuration using `GATLING_ENTERPRISE_API_TOKEN` environment variable.");
232
- // Plugin configuration
233
- const controlPlaneUrlOption = new commander_1.Option("--control-plane-url <value>", "URL of a control plane for Gatling Enterprise providing a private repository. If this parameter is provided, packages will be registered as private packages and uploaded through this private control plane.");
234
- // Descriptor file
235
- const packageDescriptorFilenameOption = new commander_1.Option("--package-descriptor-filename <value>", "Path to a package descriptor inside the .gatling folder").default("package.conf");
236
- const enterpriseBundleAndPackage = async (options) => {
237
- const gatlingHome = gatlingHomeDirWithDefaults(options);
238
- const sourcesFolder = options.sourcesFolder;
239
- const bundleFile = validateBundleFile(options);
240
- const resourcesFolder = options.resourcesFolder;
241
- const resultsFolder = options.resultsFolder;
242
- const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
243
- const typescript = typescriptWithDefaults(options, simulations);
244
- // Base
245
- const url = options.url;
246
- const apiToken = options.apiToken;
247
- // Plugin configuration
248
- const controlPlaneUrl = options.controlPlaneUrl;
249
- const nonInteractive = options.nonInteractive;
250
- // Descriptor file
251
- const packageDescriptorFilename = options.packageDescriptorFilename;
252
- // Deployment info
253
- const packageFile = validatePackageFile(options);
254
- const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installGatlingJs)({ gatlingHome });
255
- log_1.logger.debug(`graalvmHome=${graalvmHome}`);
256
- log_1.logger.debug(`coursierBinary=${coursierBinary}`);
257
- log_1.logger.debug(`jvmClasspath=${jvmClasspath}`);
258
- await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
259
- await (0, enterprise_1.enterprisePackage)({ bundleFile, resourcesFolder, packageFile, simulations });
260
- return {
261
- graalvmHome,
262
- jvmClasspath,
263
- bundleFile,
264
- resourcesFolder,
265
- resultsFolder,
266
- // Base
267
- url,
268
- apiToken,
269
- // Plugin configuration
270
- controlPlaneUrl,
271
- nonInteractive,
272
- // Descriptor file
273
- packageDescriptorFilename,
274
- // Deployment info
275
- packageFile
276
- };
277
- };
278
- program
279
- .command("enterprise-deploy")
280
- .description("Deploy a package and configured simulations")
281
- .addOption(sourcesFolderOption)
282
- .addOption(resourcesFolderOption)
283
- .addOption(bundleFileOption)
284
- .addOption(resultsFolderOption)
285
- // Base
286
- .addOption(urlOption)
287
- .addOption(apiTokenOption)
288
- // Plugin configuration
289
- .addOption(controlPlaneUrlOption)
290
- .addOption(nonInteractiveOption)
291
- // Descriptor file
292
- .addOption(packageDescriptorFilenameOption)
293
- // Deployment info
294
- .addOption(packageFileOption)
295
- .action(async (options) => {
296
- const deployOptions = await enterpriseBundleAndPackage(options);
297
- await (0, enterprise_1.enterpriseDeploy)(deployOptions);
298
- });
299
- // Deployment info
300
- const enterpriseSimulationOption = new commander_1.Option("--enterprise-simulation <value>", "Specify the simulation name directly to bypass the prompt using the following command.");
301
- const runTitleOption = new commander_1.Option("--run-title <value>", "Allows setting a title for your run reports.");
302
- const runDescriptionOption = new commander_1.Option("--run-description <value>", "Allows setting a description for your run reports summary.");
303
- const waitForRunEndOption = new commander_1.Option("--wait-for-run-end", "Wait for the result after starting the simulation on Gatling Enterprise, and complete with an error if the simulation ends with any error status").default(false);
304
- program
305
- .command("enterprise-start")
306
- .description("Start a simulation deployed with `enterprise-deploy`")
307
- .addOption(sourcesFolderOption)
308
- .addOption(resourcesFolderOption)
309
- .addOption(bundleFileOption)
310
- .addOption(resultsFolderOption)
311
- // Base
312
- .addOption(urlOption)
313
- .addOption(apiTokenOption)
314
- // Plugin configuration
315
- .addOption(controlPlaneUrlOption)
316
- .addOption(nonInteractiveOption)
317
- // Descriptor file
318
- .addOption(packageDescriptorFilenameOption)
319
- // Deployment info
320
- .addOption(packageFileOption)
321
- // Start
322
- .addOption(enterpriseSimulationOption)
323
- .addOption(runTitleOption)
324
- .addOption(runDescriptionOption)
325
- .addOption(waitForRunEndOption)
326
- .action(async (options) => {
327
- const deployOptions = await enterpriseBundleAndPackage(options);
328
- if (options.nonInteractive && options.enterpriseSimulation === undefined) {
329
- throw new Error(`No simulation specified when using non-interactive mode`);
330
- }
331
- await (0, enterprise_1.enterpriseStart)({
332
- ...deployOptions,
333
- // Start
334
- enterpriseSimulation: options.enterpriseSimulation,
335
- runTitle: options.runTitle,
336
- runDescription: options.runDescription,
337
- waitForRunEnd: options.waitForRunEnd
338
- });
339
- });
340
- program.parse(process.argv);
4
+ const commands_1 = require("./commands");
5
+ commands_1.program.parse(process.argv);
package/target/run.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runRecorder = exports.runSimulation = void 0;
4
4
  const log_1 = require("./log");
5
- const versions_1 = require("./dependencies/versions");
5
+ const dependencies_1 = require("./dependencies");
6
6
  const java_1 = require("./java");
7
7
  const runSimulation = async (options) => {
8
8
  log_1.logger.info(`Running a Gatling simulation with options:
@@ -11,11 +11,13 @@ const runSimulation = async (options) => {
11
11
  - resourcesFolder: ${options.resourcesFolder}
12
12
  - resultsFolder: ${options.resultsFolder}`);
13
13
  const additionalClasspathElements = [options.resourcesFolder];
14
+ const jitTuningArgs = ["-XX:JVMCINativeLibraryThreadFraction=0.8", "-Dgraal.MethodInlineBailoutLimit=500"];
14
15
  const memoryArgs = options.memory !== undefined ? [`-Xms${options.memory}M`, `-Xmx${options.memory}M`] : [];
15
16
  const javaArgs = [
16
17
  ...Object.entries(options.runParameters).map(([key, value]) => `-D${key}=${value}`),
17
18
  `-Dgatling.js.bundle.filePath=${options.bundleFile}`,
18
19
  `-Dgatling.js.simulation=${options.simulation}`,
20
+ ...jitTuningArgs,
19
21
  ...memoryArgs
20
22
  ];
21
23
  const simulationArgs = [
@@ -26,7 +28,7 @@ const runSimulation = async (options) => {
26
28
  "--launcher",
27
29
  "gatling-js-cli",
28
30
  "--build-tool-version",
29
- versions_1.versions.gatling.jsAdapter
31
+ dependencies_1.versions.gatling.jsAdapter
30
32
  ];
31
33
  return (0, java_1.runJavaProcess)(options, "io.gatling.app.Gatling", additionalClasspathElements, javaArgs, simulationArgs);
32
34
  };
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "./",
4
+ "rootDir": "src",
5
+ "outDir": "target",
6
+ "lib": ["es2021", "dom"],
7
+ "target": "es2021",
8
+ "module": "node16",
9
+ "esModuleInterop": true,
10
+ "moduleResolution": "node16",
11
+ "declaration": true,
12
+ "strict": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "resolveJsonModule": true
15
+ },
16
+ "include": ["src/**/*.ts"],
17
+ "exclude": ["**/*.test.ts"]
18
+ }