Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'gherkin' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const fakeTestResultsStream = new FakeTestResultsStream(program.results)
fakeTestResultsStream.on('error', (err: Error) => exit(err))
let formatStream: Transform
switch (program.format) {
case 'ndjson':
formatStream = new ProtobufNdjsonStream()
break
case 'protobuf':
formatStream = new ProtobufBinaryStream(messages.Envelope.encodeDelimited)
break
default:
throw new Error(`Unsupported format: '${program.format}'`)
}
gherkin
.fromPaths(paths, {})
.pipe(fakeTestResultsStream)
.pipe(formatStream)
.pipe(process.stdout)
function exit(err: Error) {
// tslint:disable-next-line:no-console
console.error(err)
process.exit(1)
}
function GherkinLexer(content, gherkinListener) {
// Strip BOM
content = content.replace(/^\ufeff/g, '');
var language = 'en';
var lines = content.split('\n');
var len = lines.length;
for (var i = 0; i < len; i++) {
var line = lines[i];
if(!/^\s*#/.exec(line)) break;
var languageMatch = /^\s*#\s*language:\s*([a-zA-Z-_]+)\s*$/m.exec(line);
language = languageMatch === null ? 'en' : languageMatch[1].toLowerCase();
}
language = language.replace('-', '_');
var Lexer = gherkin.Lexer(language);
var lexer = new Lexer(gherkinListener);
this.scan = function () {
lexer.scan(content);
};
}
var fs = require('fs'),
path = require('path'),
util = require('util'),
vm = require('vm'),
stream = require('stream'),
Lexer = require('gherkin').Lexer('en'),
template = require('../template'),
sandbox = require('./sandbox');
//
// Basic gherkin feature -> mocha bdd test suite
//
// fs.createReadStream(something).pipe(new Parser).pipe(process.stdout);
//
// Basic gherkin to mocha mapping:
//
// - feature -> top-level describe()
// - scenario(s) -> inner describe(), might have one or more
// - step(s) -> it()
//
module.exports = Parser;
function lexFeature (contents, name) {
var tokens;
try {
var formatter = new Formatter();
/* eslint-disable new-cap */
var EnLexer = gherkin.Lexer('en');
/* eslint-enable new-cap */
var enLexer = new EnLexer(formatter);
enLexer.scan(contents);
tokens = formatter.done();
} catch (e) {
throw new LexFeatureError('Lexing "' + name + '" failed.');
}
return tokens;
}
function lex (file) {
try {
var formatter = new Formatter();
/* eslint-disable new-cap */
var EnLexer = gherkin.Lexer('en');
/* eslint-enable new-cap */
var enLexer = new EnLexer(formatter);
enLexer.scan(file.content);
file.tokens = formatter.done();
delete file.content;
} catch (e) {
throw new LexFeatureError('Lexing "' + file.name + '" failed.');
}
}
.then(() => {
let formatter = new FeatureLexerFormatter();
/* eslint-disable new-cap */
let EnLexer = gherkin.Lexer('en');
/* eslint-enable new-cap */
let enLexer = new EnLexer(formatter);
enLexer.scan(this.content);
this.tokens = formatter.done();
})
.catch((error) => {
featureFiles.forEach(function (file) {
try {
var formatter = new Formatter();
/* eslint-disable new-cap */
var EnLexer = gherkin.Lexer('en');
/* eslint-enable new-cap */
var enLexer = new EnLexer(formatter);
enLexer.scan(file.content);
file.tokens = formatter.done();
} catch (e) {
throw new LexFeatureError('Lexing "' + file.name + '" failed.');
}
});
}
const electron = require('electron')
const Convert = require('ansi-to-html')
const convert = new Convert()
const Cucumber = require('cucumber')
// HACK:
// window.Gherkin !== require('gherkin') in browsers, so parsing fails unless:
require('gherkin').Parser = window.Gherkin.Parser
require('gherkin').Compiler = window.Gherkin.Compiler
require('gherkin').DIALECTS = window.Gherkin.DIALECTS
const cli = require('./cli')(electron.remote.process.argv)
function log() {
const args = [].slice.apply(arguments)
const htmlSafeOutput = args[0].toString().replace(//g, '>')
const pre = document.createElement('pre')
pre.innerHTML = convert.toHtml(htmlSafeOutput, { fg: '#000', bg: '#fff' })
document.body.appendChild(pre)
}
const PrettyFormatter = Cucumber.Listener.PrettyFormatter
Cucumber.Listener.PrettyFormatter = function(options) {
options.logToFunction = log
return PrettyFormatter(options)
export function getStepKeywordType({ keyword, language, previousKeywordType }) {
const dialect = Gherkin.dialects()[language]
const type = _.find(['given', 'when', 'then', 'and', 'but'], key =>
_.includes(dialect[key], keyword)
)
switch (type) {
case 'when':
return types.EVENT
case 'then':
return types.OUTCOME
case 'and':
case 'but':
if (previousKeywordType) {
return previousKeywordType
}
// fallthrough
default:
return types.PRECONDITION
for (const key of Object.keys(supportCode)) {
// @ts-ignore
global[key] = supportCode[key]
}
}
await loadSupportCode()
const cucumberStream = new CucumberStream(
supportCode.parameterTypes,
supportCode.stepDefinitions,
supportCode.beforeHooks,
supportCode.afterHooks,
supportCode.newId,
supportCode.clock
)
await pipelinePromise(
gherkin.fromPaths(paths, options),
cucumberStream,
formatStream(program.format),
process.stdout
)
}