mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
fix: Fix resolving of k6 executable (no-changelog) (#10511)
Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
parent
873056a92e
commit
00412563b6
|
@ -1,4 +1,4 @@
|
|||
import { $ } from 'zx';
|
||||
import { $, which } from 'zx';
|
||||
import { Scenario } from '@/types/scenario';
|
||||
|
||||
/**
|
||||
|
@ -14,15 +14,31 @@ export class K6Executor {
|
|||
// For 1 min with 5 virtual users
|
||||
const stage = '1m:5';
|
||||
|
||||
const k6ExecutablePath = await this.resolveK6ExecutablePath();
|
||||
|
||||
const processPromise = $({
|
||||
cwd: scenario.scenarioDirPath,
|
||||
env: {
|
||||
API_BASE_URL: this.n8nApiBaseUrl,
|
||||
},
|
||||
})`${this.k6ExecutablePath} run --quiet --stage ${stage} ${scenario.scriptPath}`;
|
||||
})`${k6ExecutablePath} run --quiet --stage ${stage} ${scenario.scriptPath}`;
|
||||
|
||||
for await (const chunk of processPromise.stdout) {
|
||||
console.log(chunk.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Resolved path to the k6 executable
|
||||
*/
|
||||
private async resolveK6ExecutablePath(): Promise<string> {
|
||||
const k6ExecutablePath = await which(this.k6ExecutablePath, { nothrow: true });
|
||||
if (!k6ExecutablePath) {
|
||||
throw new Error(
|
||||
'Could not find k6 executable based on your `PATH`. Please ensure k6 is available in your system and add it to your `PATH` or specify the path to the k6 executable using the `K6_PATH` environment variable.',
|
||||
);
|
||||
}
|
||||
|
||||
return k6ExecutablePath;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue