Thanks to visit codestin.com
Credit goes to github.com

Skip to content

The logic of the javascript compiling a rule with scenariooutline of gherkin document is diff from ruby's #2090

@chaofan-nirvana

Description

@chaofan-nirvana

🤔 What's the problem you've observed?

I found an issue when I got pickles generated by javascript. The tags of a rule were missing when it had a scenario outline.

The first param of the function compileScenarioOutline should be tags, not featureTags.

However, I found the logic of the ruby's was ok.

Javascript: src/pickles/compile.ts:#L66

function compileRule(
  featureTags: readonly messages.Tag[],
  featureBackgroundSteps: readonly messages.Step[],
  rule: messages.Rule,
  language: string,
  pickles: messages.Pickle[],
  uri: string,
  newId: messages.IdGenerator.NewId
) {
  let ruleBackgroundSteps = [].concat(featureBackgroundSteps)

  const tags = [].concat(featureTags).concat(rule.tags)

  rule.children.forEach((stepsContainer) => {
    if (stepsContainer.background) {
      ruleBackgroundSteps = ruleBackgroundSteps.concat(stepsContainer.background.steps)
    } else if (stepsContainer.scenario.examples.length === 0) {
      compileScenario(
        tags,
        ruleBackgroundSteps,
        stepsContainer.scenario,
        language,
        pickles,
        uri,
        newId
      )
    } else {
      compileScenarioOutline(
        featureTags,
        ruleBackgroundSteps,
        stepsContainer.scenario,
        language,
        pickles,
        uri,
        newId
      )
    }
  })
}

Ruby: lib/gherkin/pickles/compiler.rb:#L42

      def compile_rule(pickles, language, feature_tags, feature_background_steps, rule, source)
        tags = [].concat(feature_tags).concat(rule.tags)

        rule_background_steps = feature_background_steps.dup
        rule.children.each do |child|
          if child.background
            rule_background_steps.concat(child.background.steps)
          else
            scenario = child.scenario
            if scenario.examples.empty?
              compile_scenario(tags, rule_background_steps, scenario, language, pickles, source)
            else
              compile_scenario_outline(tags, rule_background_steps, scenario, language, pickles, source)
            end
          end
        end
      end

✨ Do you have a proposal for making it better?

javascript side should be

      compileScenarioOutline(
        tags,
        ...
     )

This text was originally generated from a template, then edited by hand. You can modify the template here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions