@gatling.io/cli 3.11.3 → 3.11.4-M2
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.
- package/package.json +3 -1
- package/target/bundle.d.ts +2 -0
- package/target/bundle.js +4 -8
- package/target/dependencies/versions.js +1 -1
- package/target/enterprisePackage.d.ts +8 -0
- package/target/enterprisePackage.js +82 -0
- package/target/index.js +69 -15
- package/target/run.js +7 -2
- package/target/simulations.d.ts +6 -0
- package/target/simulations.js +23 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gatling.io/cli",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.4-M2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"bin": {
|
|
6
6
|
"gatling": "target/index.js"
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"main": "target/index.js",
|
|
9
9
|
"types": "target/index.d.ts",
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"archiver": "7.0.1",
|
|
11
12
|
"axios": "1.6.8",
|
|
12
13
|
"commander": "12.0.0",
|
|
13
14
|
"decompress": "4.2.1",
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
"esbuild-plugin-tsc": "0.4.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
19
|
+
"@types/archiver": "6.0.2",
|
|
18
20
|
"@types/decompress": "4.2.7",
|
|
19
21
|
"@types/node": "20.12.12",
|
|
20
22
|
"prettier": "3.2.5",
|
package/target/bundle.d.ts
CHANGED
package/target/bundle.js
CHANGED
|
@@ -29,17 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.bundle = void 0;
|
|
30
30
|
const esbuild = __importStar(require("esbuild"));
|
|
31
31
|
const esbuild_plugin_tsc_1 = __importDefault(require("esbuild-plugin-tsc"));
|
|
32
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
33
32
|
const log_1 = require("./log");
|
|
34
33
|
const bundle = async (options) => {
|
|
35
|
-
log_1.logger.info(`
|
|
34
|
+
log_1.logger.info(`Bundling a Gatling simulation with options:
|
|
36
35
|
- sourcesFolder: ${options.sourcesFolder}
|
|
37
|
-
- bundleFile: ${options.bundleFile}
|
|
38
|
-
|
|
39
|
-
const contents =
|
|
40
|
-
.filter((f) => (options.typescript ? f.endsWith(".gatling.ts") : f.endsWith(".gatling.js")))
|
|
41
|
-
.map((f) => `export { default as "${f.slice(0, -11)}" } from "./${f}";`)
|
|
42
|
-
.join("\n");
|
|
36
|
+
- bundleFile: ${options.bundleFile}
|
|
37
|
+
- typescript: ${options.typescript}`);
|
|
38
|
+
const contents = options.simulations.map((s) => `export { default as "${s.name}" } from "./${s.path}";`).join("\n");
|
|
43
39
|
const plugins = options.typescript ? [(0, esbuild_plugin_tsc_1.default)({ force: true })] : [];
|
|
44
40
|
await esbuild.build({
|
|
45
41
|
stdin: {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SimulationFile } from "./simulations";
|
|
2
|
+
export interface EnterprisePackageOptions {
|
|
3
|
+
bundleFile: string;
|
|
4
|
+
resourcesFolder: string;
|
|
5
|
+
enterprisePackageFile: string;
|
|
6
|
+
simulations: SimulationFile[];
|
|
7
|
+
}
|
|
8
|
+
export declare const enterprisePackage: (options: EnterprisePackageOptions) => Promise<void>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.enterprisePackage = void 0;
|
|
7
|
+
const archiver_1 = __importDefault(require("archiver"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const promises_1 = require("stream/promises");
|
|
10
|
+
const zlib_1 = require("zlib");
|
|
11
|
+
const versions_1 = require("./dependencies/versions");
|
|
12
|
+
const log_1 = require("./log");
|
|
13
|
+
const enterprisePackage = async (options) => {
|
|
14
|
+
log_1.logger.info(`Packaging a Gatling simulation with options:
|
|
15
|
+
- bundleFile: ${options.bundleFile}
|
|
16
|
+
- enterprisePackageFile: ${options.enterprisePackageFile}`);
|
|
17
|
+
const manifest = generateManifest(options.simulations.map((s) => s.name));
|
|
18
|
+
const output = fs_1.default.createWriteStream(options.enterprisePackageFile);
|
|
19
|
+
const archive = (0, archiver_1.default)("zip", {
|
|
20
|
+
zlib: { level: zlib_1.constants.Z_MAX_LEVEL }
|
|
21
|
+
});
|
|
22
|
+
archive.on("warning", (err) => {
|
|
23
|
+
// The pipeline will rethrow errors but not warnings. We don't want to ignore warnings from the archiver, because
|
|
24
|
+
// they include things like 'no such file or directory'.
|
|
25
|
+
throw err;
|
|
26
|
+
});
|
|
27
|
+
archive.file(options.bundleFile, { name: "bundle.js" });
|
|
28
|
+
archive.append(Buffer.from(manifest), { name: "META-INF/MANIFEST.MF" });
|
|
29
|
+
archive.directory(options.resourcesFolder + "/", false);
|
|
30
|
+
archive.finalize();
|
|
31
|
+
await (0, promises_1.pipeline)(archive, output);
|
|
32
|
+
log_1.logger.info(`Package for Gatling Enterprise created at ${options.enterprisePackageFile}`);
|
|
33
|
+
};
|
|
34
|
+
exports.enterprisePackage = enterprisePackage;
|
|
35
|
+
const generateManifest = (simulationNames) => {
|
|
36
|
+
const utf8Encoder = new TextEncoder();
|
|
37
|
+
const eol = utf8Encoder.encode("\n");
|
|
38
|
+
const continuation = utf8Encoder.encode("\n ");
|
|
39
|
+
const lines = [
|
|
40
|
+
"Manifest-Version: 1.0",
|
|
41
|
+
"Implementation-Title: gatling-javascript",
|
|
42
|
+
`Implementation-Version: ${versions_1.versions.gatling.jsAdapter}`,
|
|
43
|
+
"Implementation-Vendor: GatlingCorp",
|
|
44
|
+
"Specification-Vendor: GatlingCorp",
|
|
45
|
+
"Gatling-Context: js",
|
|
46
|
+
`Gatling-Version: ${versions_1.versions.gatling.core}`,
|
|
47
|
+
"Gatling-Packager: javascript",
|
|
48
|
+
`Gatling-Packager-Version: ${versions_1.versions.gatling.jsAdapter}`,
|
|
49
|
+
`Gatling-Simulations: ${simulationNames.join(",")}`,
|
|
50
|
+
`Java-Version: ${versions_1.versions.graalvm.jdk.split(".")[0]}`
|
|
51
|
+
];
|
|
52
|
+
let totalLength = 0;
|
|
53
|
+
const buffer = [];
|
|
54
|
+
for (const line of lines) {
|
|
55
|
+
let lineLength = 0;
|
|
56
|
+
for (const char of line) {
|
|
57
|
+
const bytes = utf8Encoder.encode(char);
|
|
58
|
+
const byteLength = bytes.byteLength;
|
|
59
|
+
if (lineLength + byteLength > 71) {
|
|
60
|
+
buffer.push(continuation);
|
|
61
|
+
buffer.push(bytes);
|
|
62
|
+
// reset length for the new line (with +1 for leading space)
|
|
63
|
+
lineLength = byteLength + 1;
|
|
64
|
+
totalLength += byteLength + 2;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
buffer.push(bytes);
|
|
68
|
+
lineLength += byteLength;
|
|
69
|
+
totalLength += byteLength;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
buffer.push(eol);
|
|
73
|
+
totalLength += 1;
|
|
74
|
+
}
|
|
75
|
+
const manifest = new Uint8Array(totalLength);
|
|
76
|
+
let cursor = 0;
|
|
77
|
+
for (const elt of buffer) {
|
|
78
|
+
manifest.set(elt, cursor);
|
|
79
|
+
cursor += elt.byteLength;
|
|
80
|
+
}
|
|
81
|
+
return manifest;
|
|
82
|
+
};
|
package/target/index.js
CHANGED
|
@@ -8,6 +8,8 @@ const commander_1 = require("commander");
|
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const bundle_1 = require("./bundle");
|
|
10
10
|
const dependencies_1 = require("./dependencies");
|
|
11
|
+
const enterprisePackage_1 = require("./enterprisePackage");
|
|
12
|
+
const simulations_1 = require("./simulations");
|
|
11
13
|
const log_1 = require("./log");
|
|
12
14
|
const run_1 = require("./run");
|
|
13
15
|
const program = new commander_1.Command()
|
|
@@ -17,11 +19,42 @@ const program = new commander_1.Command()
|
|
|
17
19
|
const gatlingHomeOption = new commander_1.Option("--gatling-home <value>", 'The folder used to download and install Gatling components (default: "~/.gatling")');
|
|
18
20
|
const gatlingHomeDirWithDefaults = (options) => options.gatlingHome || `${os_1.default.homedir()}/.gatling`;
|
|
19
21
|
const sourcesFolderOption = new commander_1.Option("--sources-folder <value>", "The sources folder path").default("src");
|
|
20
|
-
const simulationOption = new commander_1.Option("--simulation <value>", "The simulation entry point function name
|
|
21
|
-
const
|
|
22
|
+
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)");
|
|
23
|
+
const simulationWithDefaults = (options, simulationsFound) => {
|
|
24
|
+
if (options.simulation !== undefined) {
|
|
25
|
+
return options.simulation;
|
|
26
|
+
}
|
|
27
|
+
else if (simulationsFound.length === 1) {
|
|
28
|
+
return simulationsFound[0].name;
|
|
29
|
+
}
|
|
30
|
+
else if (simulationsFound.length === 0) {
|
|
31
|
+
throw new Error("No simulation found, simulations must be defined in a <simulation name>.gatling.js or <simulation name>.gatling.ts file)");
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
throw new Error(`Several simulations found, specify one using the --simulation option (available simulations: ${simulationsFound.map((s) => s.name)})`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const simulationRequiredOption = new commander_1.Option("--simulation <value>", "The simulation entry point function name").makeOptionMandatory(true);
|
|
38
|
+
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");
|
|
39
|
+
const validateBundleFile = (options) => {
|
|
40
|
+
if (!options.bundleFile.endsWith(".js")) {
|
|
41
|
+
throw Error(`'${options.bundleFile}' is not a valid bundle file path: should have a .js extension`);
|
|
42
|
+
}
|
|
43
|
+
return options.bundleFile;
|
|
44
|
+
};
|
|
45
|
+
const enterprisePackageFileOption = new commander_1.Option("--enterprise-package-file <value>", "The target package file path when packaging simulations for Gatling Enterprise (must have a .zip extension)").default("target/package.zip");
|
|
46
|
+
const validateEnterprisePackageFile = (options) => {
|
|
47
|
+
if (!options.enterprisePackageFile.endsWith(".zip")) {
|
|
48
|
+
throw Error(`'${options.enterprisePackageFile}' is not a valid package file path: should have a .zip extension`);
|
|
49
|
+
}
|
|
50
|
+
return options.enterprisePackageFile;
|
|
51
|
+
};
|
|
22
52
|
const resourcesFolderOption = new commander_1.Option("--resources-folder <value>", "The resources folder path").default("resources");
|
|
23
53
|
const resultsFolderOption = new commander_1.Option("--results-folder <value>", "The results folder path").default("target/gatling");
|
|
24
|
-
const typescriptOption = new commander_1.Option("--typescript", "Use the typescript compiler to compile your code
|
|
54
|
+
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)");
|
|
55
|
+
const typescriptWithDefaults = (options, simulationsFound) => options.typescript !== undefined
|
|
56
|
+
? options.typescript
|
|
57
|
+
: simulationsFound.findIndex((s) => s.type === "typescript") >= 0;
|
|
25
58
|
const graalvmHomeMandatoryOption = new commander_1.Option("--graalvm-home <value>", "Path to the GraalVM home").makeOptionMandatory(true);
|
|
26
59
|
const jvmClasspathMandatoryOption = new commander_1.Option("--jvm-classpath <value>", "The classpath containing all Gatling JVM components").makeOptionMandatory(true);
|
|
27
60
|
program
|
|
@@ -37,22 +70,23 @@ program
|
|
|
37
70
|
});
|
|
38
71
|
program
|
|
39
72
|
.command("build")
|
|
40
|
-
.description("Build
|
|
73
|
+
.description("Build Gatling simulations")
|
|
41
74
|
.addOption(sourcesFolderOption)
|
|
42
75
|
.addOption(bundleFileOption)
|
|
43
76
|
.addOption(typescriptOption)
|
|
44
77
|
.action(async (options) => {
|
|
45
78
|
const sourcesFolder = options.sourcesFolder;
|
|
46
|
-
const bundleFile = options
|
|
47
|
-
const
|
|
48
|
-
|
|
79
|
+
const bundleFile = validateBundleFile(options);
|
|
80
|
+
const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
|
|
81
|
+
const typescript = typescriptWithDefaults(options, simulations);
|
|
82
|
+
await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
|
|
49
83
|
});
|
|
50
84
|
program
|
|
51
85
|
.command("run-only")
|
|
52
|
-
.description("Run a Gatling simulation")
|
|
86
|
+
.description("Run a Gatling simulation from an already built bundle")
|
|
53
87
|
.addOption(graalvmHomeMandatoryOption)
|
|
54
88
|
.addOption(jvmClasspathMandatoryOption)
|
|
55
|
-
.addOption(
|
|
89
|
+
.addOption(simulationRequiredOption)
|
|
56
90
|
.addOption(bundleFileOption)
|
|
57
91
|
.addOption(resourcesFolderOption)
|
|
58
92
|
.addOption(resultsFolderOption)
|
|
@@ -60,7 +94,7 @@ program
|
|
|
60
94
|
const graalvmHome = options.graalvmHome;
|
|
61
95
|
const jvmClasspath = options.jvmClasspath;
|
|
62
96
|
const simulation = options.simulation;
|
|
63
|
-
const bundleFile = options
|
|
97
|
+
const bundleFile = validateBundleFile(options);
|
|
64
98
|
const resourcesFolder = options.resourcesFolder;
|
|
65
99
|
const resultsFolder = options.resultsFolder;
|
|
66
100
|
await (0, run_1.runSimulation)({
|
|
@@ -85,16 +119,17 @@ program
|
|
|
85
119
|
.action(async (options) => {
|
|
86
120
|
const gatlingHome = gatlingHomeDirWithDefaults(options);
|
|
87
121
|
const sourcesFolder = options.sourcesFolder;
|
|
88
|
-
const
|
|
89
|
-
const bundleFile = options.bundleFile;
|
|
122
|
+
const bundleFile = validateBundleFile(options);
|
|
90
123
|
const resourcesFolder = options.resourcesFolder;
|
|
91
124
|
const resultsFolder = options.resultsFolder;
|
|
92
|
-
const
|
|
125
|
+
const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
|
|
126
|
+
const typescript = typescriptWithDefaults(options, simulations);
|
|
127
|
+
const simulation = simulationWithDefaults(options, simulations);
|
|
93
128
|
const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installGatlingJs)({ gatlingHome });
|
|
94
129
|
log_1.logger.debug(`graalvmHome=${graalvmHome}`);
|
|
95
130
|
log_1.logger.debug(`coursierBinary=${coursierBinary}`);
|
|
96
131
|
log_1.logger.debug(`jvmClasspath=${jvmClasspath}`);
|
|
97
|
-
await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript });
|
|
132
|
+
await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
|
|
98
133
|
await (0, run_1.runSimulation)({ graalvmHome, jvmClasspath, simulation, bundleFile, resourcesFolder, resultsFolder });
|
|
99
134
|
});
|
|
100
135
|
program
|
|
@@ -108,11 +143,30 @@ program
|
|
|
108
143
|
const gatlingHome = gatlingHomeDirWithDefaults(options);
|
|
109
144
|
const sourcesFolder = options.sourcesFolder;
|
|
110
145
|
const resourcesFolder = options.resourcesFolder;
|
|
111
|
-
const
|
|
146
|
+
const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
|
|
147
|
+
const typescript = typescriptWithDefaults(options, simulations);
|
|
112
148
|
const { graalvmHome, coursierBinary, jvmClasspath } = await (0, dependencies_1.installRecorder)({ gatlingHome });
|
|
113
149
|
log_1.logger.debug(`graalvmHome=${graalvmHome}`);
|
|
114
150
|
log_1.logger.debug(`coursierBinary=${coursierBinary}`);
|
|
115
151
|
log_1.logger.debug(`jvmClasspath=${jvmClasspath}`);
|
|
116
152
|
await (0, run_1.runRecorder)({ graalvmHome, jvmClasspath, sourcesFolder, typescript, resourcesFolder });
|
|
117
153
|
});
|
|
154
|
+
program
|
|
155
|
+
.command("enterprise-package")
|
|
156
|
+
.description("Build Gatling simulations and package them for Gatling Enterprise")
|
|
157
|
+
.addOption(sourcesFolderOption)
|
|
158
|
+
.addOption(resourcesFolderOption)
|
|
159
|
+
.addOption(bundleFileOption)
|
|
160
|
+
.addOption(enterprisePackageFileOption)
|
|
161
|
+
.addOption(typescriptOption)
|
|
162
|
+
.action(async (options) => {
|
|
163
|
+
const sourcesFolder = options.sourcesFolder;
|
|
164
|
+
const resourcesFolder = options.resourcesFolder;
|
|
165
|
+
const bundleFile = validateBundleFile(options);
|
|
166
|
+
const enterprisePackageFile = validateEnterprisePackageFile(options);
|
|
167
|
+
const simulations = await (0, simulations_1.findSimulations)(sourcesFolder);
|
|
168
|
+
const typescript = typescriptWithDefaults(options, simulations);
|
|
169
|
+
await (0, bundle_1.bundle)({ sourcesFolder, bundleFile, typescript, simulations });
|
|
170
|
+
await (0, enterprisePackage_1.enterprisePackage)({ bundleFile, resourcesFolder, enterprisePackageFile, simulations });
|
|
171
|
+
});
|
|
118
172
|
program.parse(process.argv);
|
package/target/run.js
CHANGED
|
@@ -8,7 +8,9 @@ const os_1 = require("./dependencies/os");
|
|
|
8
8
|
const runSimulation = async (options) => {
|
|
9
9
|
log_1.logger.info(`Running a Gatling simulation with options:
|
|
10
10
|
- simulation: ${options.simulation}
|
|
11
|
-
- bundleFile: ${options.bundleFile}
|
|
11
|
+
- bundleFile: ${options.bundleFile}
|
|
12
|
+
- resourcesFolder: ${options.resourcesFolder}
|
|
13
|
+
- resultsFolder: ${options.resultsFolder}`);
|
|
12
14
|
const additionalClasspathElements = [options.resourcesFolder];
|
|
13
15
|
const javaArgs = [
|
|
14
16
|
`-Dgatling.js.bundle.filePath=${options.bundleFile}`,
|
|
@@ -28,7 +30,10 @@ const runSimulation = async (options) => {
|
|
|
28
30
|
};
|
|
29
31
|
exports.runSimulation = runSimulation;
|
|
30
32
|
const runRecorder = async (options) => {
|
|
31
|
-
log_1.logger.info(
|
|
33
|
+
log_1.logger.info(`Running the Gatling Recorder with options:
|
|
34
|
+
- sourcesFolder: ${options.sourcesFolder}
|
|
35
|
+
- resourcesFolder: ${options.resourcesFolder}
|
|
36
|
+
- typescript: ${options.typescript}`);
|
|
32
37
|
const recorderArgs = [
|
|
33
38
|
"--simulations-folder",
|
|
34
39
|
options.sourcesFolder,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findSimulations = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const findSimulations = async (sourcesFolder) => {
|
|
9
|
+
const children = await promises_1.default.readdir(sourcesFolder, { recursive: false });
|
|
10
|
+
const simulations = children
|
|
11
|
+
.filter((path) => path.endsWith(".gatling.js") || path.endsWith(".gatling.ts"))
|
|
12
|
+
.map((path) => ({
|
|
13
|
+
path,
|
|
14
|
+
name: path.slice(0, -11),
|
|
15
|
+
type: path.endsWith(".ts") ? "typescript" : "javascript"
|
|
16
|
+
}));
|
|
17
|
+
const duplicates = simulations.filter((value, index) => simulations.findIndex((other) => other.name === value.name) !== index);
|
|
18
|
+
if (duplicates.length > 0) {
|
|
19
|
+
throw Error(`Found ambiguous simulation name(s) ${duplicates.map((s) => s.name)}: found as both *.gatling.js and *.gatling.ts file(s)`);
|
|
20
|
+
}
|
|
21
|
+
return simulations;
|
|
22
|
+
};
|
|
23
|
+
exports.findSimulations = findSimulations;
|