Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): allow scenario name exact match without using regex #2709

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions packages/artillery/test/cli/command-run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,49 @@ tap.test('Can specify scenario to run by name', async (t) => {
);
});

tap.test('Can specify scenario to run by name', async (t) => {
const [exitCode, output] = await execute([
'run',
'--scenario-name',
'Test Scenario (4)',
'-o',
`${reportFilePath}`,
'test/scripts/scenario-named/scenario.yml'
]);

t.equal(exitCode, 0, 'CLI should exit with code 0');
t.ok(
output.stdout.includes('Successfully running scenario 4'),
'Should log success'
);
const json = JSON.parse(fs.readFileSync(reportFilePath, 'utf8'));

t.equal(
json.aggregate.counters['vusers.created_by_name.Test Scenario (4)'],
6,
'Should have created 6 vusers for the right scenario'
);
t.type(
json.aggregate.counters['vusers.created_by_name.Test Scenario 1'],
'undefined',
'Should not have created vusers for the wrong scenario'
);
});

tap.test(
'Errors correctly when specifying a non-existing scenario by name',
async (t) => {
const [exitCode, output] = await execute([
'run',
'--scenario-name',
'Test Scenario 4',
'Test Scenario 5',
'test/scripts/scenario-named/scenario.yml'
]);

t.equal(exitCode, 11);
t.ok(
output.stdout.includes(
'Error: Scenario Test Scenario 4 not found in script. Make sure your chosen scenario matches the one in your script exactly.'
'Error: Scenario Test Scenario 5 not found in script. Make sure your chosen scenario matches the one in your script exactly.'
),
'Should log error when scenario not found'
);
Expand Down
5 changes: 4 additions & 1 deletion packages/artillery/test/scripts/scenario-named/scenario.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ scenarios:
- log: "Successfully running scenario 2"
- name: Test Scenario 3
flow:
- log: "Successfully running scenario 3"
- log: "Successfully running scenario 3"
- name: Test Scenario (4)
flow:
- log: "Successfully running scenario 4"
6 changes: 5 additions & 1 deletion packages/core/lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,11 @@ function runScenario(script, metrics, runState, contextVars, options) {
if (options.scenarioName) {
let foundIndex;
const foundScenario = script.scenarios.filter((scenario, index) => {
const hasScenario = new RegExp(options.scenarioName).test(scenario.name);
const hasScenarioByRegex = new RegExp(options.scenarioName).test(
scenario.name
);
const hasScenarioByName = scenario.name === options.scenarioName;
const hasScenario = hasScenarioByName || hasScenarioByRegex;

if (hasScenario) {
foundIndex = index;
Expand Down
Loading