Skip to content

Commit 4f27ffc

Browse files
authored
fix(bom): resolve payload paths in separate config (#3653)
1 parent f1f0fda commit 4f27ffc

File tree

1 file changed

+33
-28
lines changed
  • packages/artillery/lib/platform/aws-ecs/legacy

1 file changed

+33
-28
lines changed

packages/artillery/lib/platform/aws-ecs/legacy/bom.js

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,26 @@ function getCustomEngines(context, next) {
235235
}
236236

237237
function getCustomJsDependencies(context, next) {
238-
if (
239-
context.opts.scriptData.config?.processor
240-
) {
238+
if (context.opts.scriptData.config?.processor) {
239+
// When using a separate config file, resolve paths relative to the scenario file
240+
// Otherwise, resolve relative to the config file
241+
const baseDir = context.opts.scenarioPath
242+
? path.dirname(context.opts.scenarioPath)
243+
: path.dirname(context.opts.absoluteScriptPath);
244+
241245
//
242246
// Path to the main processor file:
243247
//
244248
const procPath = path.resolve(
245-
path.dirname(context.opts.absoluteScriptPath),
249+
baseDir,
246250
context.opts.scriptData.config.processor
247251
);
248252
context.localFilePaths.push(procPath);
249253

250254
// Get the tree of requires from the main processor file:
251255
const tree = depTree.toList({
252256
filename: procPath,
253-
directory: path.dirname(context.opts.absoluteScriptPath),
257+
directory: baseDir,
254258
filter: (path) => path.indexOf('node_modules') === -1 // optional
255259
});
256260

@@ -317,23 +321,19 @@ function getVariableDataFiles(context, next) {
317321
function resolvePayloadPaths(obj) {
318322
const result = [];
319323
if (obj.payload) {
324+
// When using a separate config file, resolve paths relative to the scenario file
325+
// Otherwise, resolve relative to the config file
326+
const baseDir = context.opts.scenarioPath
327+
? path.dirname(context.opts.scenarioPath)
328+
: path.dirname(context.opts.absoluteScriptPath);
329+
320330
if (_.isArray(obj.payload)) {
321331
obj.payload.forEach((payloadSpec) => {
322-
result.push(
323-
path.resolve(
324-
path.dirname(context.opts.absoluteScriptPath),
325-
payloadSpec.path
326-
)
327-
);
332+
result.push(path.resolve(baseDir, payloadSpec.path));
328333
});
329334
} else if (_.isObject(obj.payload)) {
330335
// isObject returns true for arrays, so this branch must come second
331-
result.push(
332-
path.resolve(
333-
path.dirname(context.opts.absoluteScriptPath),
334-
obj.payload.path
335-
)
336-
);
336+
result.push(path.resolve(baseDir, obj.payload.path));
337337
}
338338
}
339339
return result;
@@ -357,16 +357,20 @@ function getVariableDataFiles(context, next) {
357357
}
358358

359359
function getFileUploadPluginFiles(context, next) {
360-
if (
361-
context.opts.scriptData.config?.plugins?.['http-file-uploads']
362-
) {
360+
if (context.opts.scriptData.config?.plugins?.['http-file-uploads']) {
363361
// Append filePaths array if it's there:
364362

365363
if (context.opts.scriptData.config.plugins['http-file-uploads'].filePaths) {
364+
// When using a separate config file, resolve paths relative to the scenario file
365+
// Otherwise, resolve relative to the config file
366+
const baseDir = context.opts.scenarioPath
367+
? path.dirname(context.opts.scenarioPath)
368+
: path.dirname(context.opts.absoluteScriptPath);
369+
366370
const absPaths = context.opts.scriptData.config.plugins[
367371
'http-file-uploads'
368372
].filePaths.map((p) => {
369-
return path.resolve(path.dirname(context.opts.absoluteScriptPath), p);
373+
return path.resolve(baseDir, p);
370374
});
371375
context.localFilePaths = context.localFilePaths.concat(absPaths);
372376
}
@@ -377,14 +381,15 @@ function getFileUploadPluginFiles(context, next) {
377381
}
378382

379383
function getExtraFiles(context, next) {
380-
if (
381-
context.opts.scriptData.config?.includeFiles
382-
) {
384+
if (context.opts.scriptData.config?.includeFiles) {
385+
// When using a separate config file, resolve paths relative to the scenario file
386+
// Otherwise, resolve relative to the config file
387+
const baseDir = context.opts.scenarioPath
388+
? path.dirname(context.opts.scenarioPath)
389+
: path.dirname(context.opts.absoluteScriptPath);
390+
383391
const absPaths = _.map(context.opts.scriptData.config.includeFiles, (p) => {
384-
const includePath = path.resolve(
385-
path.dirname(context.opts.absoluteScriptPath),
386-
p
387-
);
392+
const includePath = path.resolve(baseDir, p);
388393
debug('includeFile:', includePath);
389394
return includePath;
390395
});

0 commit comments

Comments
 (0)