Skip to content

Commit

Permalink
feat: allow use of suite context & args inside loop
Browse files Browse the repository at this point in the history
  • Loading branch information
matmar10 committed Nov 10, 2021
1 parent 06ecad6 commit c305b40
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,22 @@ export default class Suite extends EventEmitter {
let loopItems;
let LoopItemsBuilderError = customError('LoopItemsBuilderError');

let _context = { suite: this.userContext, runSpec: this.runDependencySpec, _sctx: this };

try {
if (loopData.type === 'static') {
loopItems = loopData.static;
} else if (loopData.type === 'dynamic') {
if (loopData.dynamic.run_type === 'inline') {
let inlineFunction = loopData.dynamic.inline.function;
let inlineResult = await runInlineFunction(inlineFunction);
let inlineResult = await runInlineFunction(inlineFunction, _context, loopData.dynamic.inline.args || []);
loopItems = inlineResult;
} else if (loopData.dynamic.run_type === 'module') {
let modulePath = this.resolveFile(loopData.dynamic.module.module_path);
const module = assertFileValidity(modulePath, 'Loop data module');
const customModule = loadModule(module);

let moduleResult = await runModuleFunction(customModule, loopData.dynamic.module.function_name);
let moduleResult = await runModuleFunction(customModule, loopData.dynamic.module.function_name, _context, loopData.dynamic.module.args || []);
loopItems = moduleResult;
} else {
throw new InvalidYAMLSuiteSchemaError(`Loop dynamic run_type should be either inline or module`);
Expand Down

0 comments on commit c305b40

Please sign in to comment.