Skip to content

Commit

Permalink
Merge branch 'master' into extended-rule-support
Browse files Browse the repository at this point in the history
  • Loading branch information
makmu committed Mar 20, 2021
2 parents b626c9b + 1a9ef75 commit cb7c122
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 78 deletions.
162 changes: 98 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
"typescript": "^3.3.3"
},
"dependencies": {
"@cucumber/gherkin": "^17.0.0",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.7",
"@types/node": "^11.9.4",
"@types/uuid": "^8.3.0",
"callsites": "^3.0.0",
"gherkin": "^9.0.0",
"glob": "^7.1.6",
"jest": "^26.1.0",
"uuid": "^8.2.0"
"jest": "^26.1.0"
},
"jest": {
"transform": {
Expand Down
12 changes: 10 additions & 2 deletions src/feature-definition-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ const defineScenario = (

testFunction(scenarioTitle, () => {
return scenarioFromStepDefinitions.steps.reduce((promiseChain, nextStep, index) => {
const stepArgument = parsedScenario.steps[index].stepArgument;
const parsedStep = parsedScenario.steps[index];
const stepArgument = parsedStep.stepArgument;
const matches = matchSteps(
parsedScenario.steps[index].stepText,
scenarioFromStepDefinitions.steps[index].stepMatcher
Expand All @@ -139,7 +140,14 @@ const defineScenario = (

const args = [ ...matchArgs, stepArgument ];

return promiseChain.then(() => nextStep.stepFunction(...args));
return promiseChain.then(() => {
return Promise.resolve()
.then(() => nextStep.stepFunction(...args))
.catch((error) => {
error.message = `jest-cucumber: ${parsedStep.stepText} (line ${parsedStep.lineNumber})\n\n${error.message}`;
throw error;
});
});
}, Promise.resolve());
}, timeout);
};
Expand Down
28 changes: 20 additions & 8 deletions src/parsed-feature-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import { readFileSync } from 'fs';
import { sync as globSync } from 'glob';
import { dirname, resolve } from 'path';
import callsites from 'callsites';
import Parser from 'gherkin/dist/src/Parser';
import { default as Gherkins } from 'gherkin';
import AstBuilder from 'gherkin/dist/src/AstBuilder';
import { Parser, AstBuilder, Dialect, dialects } from '@cucumber/gherkin';
import { v4 as uuidv4 } from 'uuid';

import { getJestCucumberConfiguration } from './configuration';
import { ParsedFeature, ParsedScenario, ParsedStep, ParsedScenarioOutline, Options, ScenarioGroup} from './models';
import Dialect from 'gherkin/dist/src/Dialect';

const parseDataTableRow = (astDataTableRow: any) => {
return astDataTableRow.cells.map((col: any) => col.value) as string[];
Expand Down Expand Up @@ -285,7 +282,7 @@ const collapseRules = (astFeature: any) => {
}

const translateKeywords = (astFeature: any) => {
const languageDialect = Gherkins.dialects()[astFeature.language];
const languageDialect = dialects[astFeature.language];
const translationMap = createTranslationMap(languageDialect);

astFeature.language = 'en';
Expand Down Expand Up @@ -313,8 +310,8 @@ const translateKeywords = (astFeature: any) => {
};

const createTranslationMap = (translateDialect: Dialect) => {
const englishDialect = Gherkins.dialects().en;
const translationMap: {[word: string]: string} = {};
const englishDialect = dialects.en;
const translationMap: { [word: string]: string } = {};

const props: Array<keyof Dialect> = [
'and',
Expand All @@ -334,10 +331,25 @@ const createTranslationMap = (translateDialect: Dialect) => {
const dialectWords = translateDialect[prop];
const translationWords = englishDialect[prop];
let index = 0;
let defaultWordIndex: number | null = null;

for (const dialectWord of dialectWords) {
// skip "* " word
if (dialectWord.indexOf('*') !== 0) {
translationMap[dialectWord] = translationWords[index];
if (translationWords[index] !== undefined) {
translationMap[dialectWord] = translationWords[index];
if (defaultWordIndex === null) {
// set default when non is set yet
defaultWordIndex = index;
}
} else {
// index has undefined value, translate to default word
if (defaultWordIndex !== null) {
translationMap[dialectWord] = translationWords[defaultWordIndex];
} else {
throw new Error('No translation found for ' + dialectWord);
}
}
}

index++;
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"outDir": "dist",
"strict": true,
"rootDir": ".",
"lib": ["esnext"]
"lib": ["esnext"],
"resolveJsonModule": true
},
"exclude": [
"node_modules",
Expand Down

0 comments on commit cb7c122

Please sign in to comment.