Skip to content

Commit

Permalink
feat: support Markdown in multiple dialects. Can be set on a per feat…
Browse files Browse the repository at this point in the history
…ure basis.
  • Loading branch information
temyers committed Oct 21, 2022
1 parent 3cd5a9c commit 29f03ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 3 additions & 5 deletions specs/step-definitions/markdown-support-en-pirate.steps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { loadFeature, defineFeature, DefineStepFunction } from '../../src';

const feature = loadFeature('./specs/features/markdown-support.en-pirate.feature.md');
const feature = loadFeature('./specs/features/markdown-support.en-pirate.feature.md',{
dialect: 'en-pirate'
});

// FIXME - code generation is not working....
// FIXME - tests are not captured...
// Root Cause - https://github.com/cucumber/common/blob/b43e36f5e0123023a71e5be859aef73209e2e796/gherkin/javascript/src/GherkinInMarkdownTokenMatcher.ts#L84
// Language has to be set as a global option
defineFeature(feature, (test) => {
test('Simple addition', ({ when, then }) => {
var result = 0
Expand Down
2 changes: 2 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type Options = {
tagFilter?: string;
errors?: ErrorOptions | boolean;
scenarioNameTemplate?: (vars: ScenarioNameTemplateVars) => string;
// see: https://cucumber.io/docs/gherkin/languages/
dialect?: string;
};

export type ScenarioNameTemplateVars = {
Expand Down
11 changes: 6 additions & 5 deletions src/parsed-feature-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export const loadFeature = (featureFilePath: string, options?: Options) => {
try {
const featureText: string = readFileSync(absoluteFeatureFilePath, 'utf8');

const tokenMatcher = identifyGherkinDialect(featureFilePath)
const tokenMatcher = identifyGherkinDialect(featureFilePath, options)
return parseFeature(featureText,tokenMatcher, options)

} catch (err) {
Expand All @@ -384,12 +384,13 @@ export const loadFeature = (featureFilePath: string, options?: Options) => {
}
};

const identifyGherkinDialect = (featureFilePath: string): ITokenMatcher<any> => {
const identifyGherkinDialect = (featureFilePath: string, options?: Options): ITokenMatcher<any> => {

const dialect = options?.dialect || undefined
if(featureFilePath.endsWith(".md")){
// FIXME - set the dialect here to support multiple languages
return new GherkinInMarkdownTokenMatcher('en');
return new GherkinInMarkdownTokenMatcher(dialect);
}else {
return new GherkinClassicTokenMatcher();
return new GherkinClassicTokenMatcher(dialect);
}
}

Expand Down

0 comments on commit 29f03ab

Please sign in to comment.