How to use the gherkin.Parser function in gherkin

To help you get started, we’ve selected a few gherkin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Codeception / CodeceptJS / lib / command / gherkin / snippets.js View on Github external
const getConfig = require('../utils').getConfig;
const getTestRoot = require('../utils').getTestRoot;
const Codecept = require('../../codecept');
const container = require('../../container');
const output = require('../../output');
const { matchStep } = require('../../interfaces/bdd');
const { Parser } = require('gherkin');
const glob = require('glob');
const fsPath = require('path');
const fs = require('fs');
const escapeStringRegexp = require('escape-string-regexp');

const parser = new Parser();
parser.stopAtFirstError = false;


module.exports = function (genPath, options) {
  const configFile = options.config || genPath;
  const testsPath = getTestRoot(configFile);
  const config = getConfig(configFile);
  if (!config) return;

  const codecept = new Codecept(config, {});
  codecept.init(testsPath);

  if (!config.gherkin) {
    output.error('Gherkin is not enabled in config. Run `codecept gherkin:init` to enable it');
    process.exit(1);
  }
github vsiakka / gherkin-lint / src / linter.js View on Github external
var fs = require('fs');
var _ = require('lodash');
var Gherkin = require('gherkin');
var parser = new Gherkin.Parser();
var rules = require('./rules.js');

function lint(files, configuration) {
  var output = [];

  files.forEach(fileName => {
    var fileContent = fs.readFileSync(fileName, 'utf-8');
    var file = {
      name: fileName,
      lines: fileContent.split(/\r\n|\r|\n/)
    };

    var errors = [];
    try {
      var feature = parser.parse(fileContent).feature || {};
      errors = rules.runAllEnabledRules(feature, file, configuration);
github simondean / parallel-cucumber-js / lib / parallel_cucumber / runtime.js View on Github external
self._getFeatureFileObjects = function (featureFilePath) {
    var parser = new Gherkin.Parser();
    var gherkinDocument = parser.parse(FS.readFileSync(featureFilePath, 'utf8'));
    var featureFileObjects = [];

    var featureTags = self._collectTags(gherkinDocument.feature.tags);
    if (gherkinDocument.feature.children.length > 0) {
      gherkinDocument.feature.children.forEach(function (child) {
        var scenarioTags = [];
        if (child.type !== 'Background') {
          scenarioTags = self._collectTags(child.tags);
        }
        if (child.examples === undefined || child.examples.length === 0) {
          featureFileObjects.push({
            path: featureFilePath + ':' + child.location.line,
            tags: featureTags.concat(scenarioTags)
          });
        }
github TheBrainFamily / cypress-cucumber-preprocessor / cypress-tags.js View on Github external
paths.forEach(featurePath => {
  const spec = `${fs.readFileSync(featurePath)}`;
  const parsedFeature = new Parser().parse(spec);

  const featureTags = parsedFeature.feature.tags;
  const featureShouldRun = shouldProceedCurrentStep(featureTags, envTags);
  const taggedScenarioShouldRun = parsedFeature.feature.children.some(
    section =>
      section.tags &&
      section.tags.length &&
      shouldProceedCurrentStep(section.tags.concat(featureTags), envTags)
  );
  debug(
    `Feature: ${featurePath}, featureShouldRun: ${featureShouldRun}, taggedScenarioShouldRun: ${taggedScenarioShouldRun}`
  );
  if (featureShouldRun || taggedScenarioShouldRun) {
    featuresToRun.push(featurePath);
  }
});
github cucumber-attic / microcuke / lib / cucumber / config.js View on Github external
module.exports = function Config() {
  var parser = new Gherkin.Parser();
  var compiler = new Gherkin.Compiler();

  this.buildTestCases = function (glue, gherkinLoader) {
    var pickles = [];

    gherkinLoader.loadGherkinFiles().forEach(function (gherkinFile) {
      var feature = parser.parse(gherkinFile.read());
      pickles = pickles.concat(compiler.compile(feature));
    });
    return pickles.map(function (pickle) {
      return glue.createTestCase(pickle);
    });
  }
};
github gherking / gherking / lib / index.js View on Github external
API.load = pathToFile => {
    const parser = new Parser();
    const document = parser.parse(fs.readFileSync(pathToFile, 'utf8'));
    return assembler.objectToAST(document);
};
github Codeception / CodeceptJS / lib / interfaces / gherkin.js View on Github external
const { Parser } = require('gherkin');
const { Context, Suite, Test } = require('mocha');

const { matchStep } = require('./bdd');
const { isAsyncFunction } = require('../utils');
const event = require('../event');
const scenario = require('../scenario');
const Step = require('../step');

const parser = new Parser();
parser.stopAtFirstError = false;

module.exports = (text) => {
  const ast = parser.parse(text);

  const suite = new Suite(ast.feature.name, new Context());
  const tags = ast.feature.tags.map(t => t.name);
  suite.title = `${suite.title} ${tags.join(' ')}`.trim();
  suite.tags = tags || [];
  suite.comment = ast.feature.description;
  suite.feature = ast.feature;
  suite.timeout(0);

  suite.beforeEach('codeceptjs.before', () => scenario.setup(suite));
  suite.afterEach('codeceptjs.after', () => scenario.teardown(suite));
  suite.beforeAll('codeceptjs.beforeSuite', () => scenario.suiteSetup(suite));
github cucumber / cucumber-js / spec / cucumber / ast / feature_spec.js View on Github external
beforeEach(function() {
          var source =
            'Feature: Foo\n' +
            '  Scenario: Bar\n' +
            '    My scenario description\n' +
            '\n' +
            '    Then b\n';
          var gherkinDocument = new Gherkin.Parser().parse(source);
          feature = Cucumber.Ast.Feature(gherkinDocument.feature, []);
        });
github TheBrainFamily / cypress-cucumber-preprocessor / lib / featuresLoader.js View on Github external
.map(feature =>
      Object.assign({}, feature, {
        name: new Parser().parse(feature.spec.toString()).feature.name
      })
    );