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

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

Closed
chaofan-nirvana opened this issue Sep 30, 2022 · 2 comments

Comments

@chaofan-nirvana
Copy link
Contributor

chaofan-nirvana commented Sep 30, 2022

🤔 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.

@chaofan-nirvana
Copy link
Contributor Author

PR: #2091

@mpkorstanje
Copy link
Contributor

Fixed by #2091

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants