Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
feat: clearer errors on processing errors (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno authored Sep 10, 2021
1 parent 174146f commit b888aa6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Cucumber Forge admins
* @cerner/cucumber-forge-report-generator-contributors
* @cerner/cucumber-forge-report-generator-contributors jkuester tobitenno
148 changes: 77 additions & 71 deletions src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,79 +108,85 @@ const getFeatureFromFile = (featureFilename) => {
feature.language = getFeatureFileLanguage(featureFilename, fileLines);
const translations = i18n.getFixedT(feature.language);

fileLines.forEach((nextLine) => {
const line = nextLine.trim();
const newPhase = getNewPhase(translations, line);
if (currentPhase === 'DOC_STRING_STARTED') {
if (newPhase === 'DOC_STRING_STARTED') {
// Reached the end of the doc string
currentPhase = null;
} else {
fileLines.forEach((nextLine, index) => {
try {
const line = nextLine.trim();
const newPhase = getNewPhase(translations, line);
if (currentPhase === 'DOC_STRING_STARTED') {
if (newPhase === 'DOC_STRING_STARTED') {
// Reached the end of the doc string
currentPhase = null;
} else {
const step = scenario.steps[scenario.steps.length - 1];
// Use untrimmed nextLine to preserve whitespace
step.docString += step.docString ? `\n${nextLine}` : nextLine;
}
} else if (newPhase) {
currentPhase = newPhase;
switch (newPhase) {
case 'FEATURE_STARTED':
feature.name = line;
break;
case 'BACKGROUND_STARTED':
scenario = createScenario(line, tags);
feature.background = scenario;
tags = [];
break;
case 'SCENARIO_STARTED':
case 'SCENARIO_OUTLINE_STARTED':
scenario = createScenario(line, tags);
feature.scenarios.push(scenario);
tags = [];
break;
case 'EXAMPLES_STARTED':
scenario.examples = createExamples(line);
break;
default:
}
} else if (line.startsWith('@')) {
tags = line.split(' ');
if (!currentPhase) {
// Feature tags
feature.tags = tags;
}
} else if (line.startsWith('#')) {
// Gherkin comments start with '#' and are required to take an entire line.
// We want to skip any comment lines.
} else if (line.startsWith('|')) {
const step = scenario.steps[scenario.steps.length - 1];
// Use untrimmed nextLine to preserve whitespace
step.docString += step.docString ? `\n${nextLine}` : nextLine;
}
} else if (newPhase) {
currentPhase = newPhase;
switch (newPhase) {
case 'FEATURE_STARTED':
feature.name = line;
break;
case 'BACKGROUND_STARTED':
scenario = createScenario(line, tags);
feature.background = scenario;
tags = [];
break;
case 'SCENARIO_STARTED':
case 'SCENARIO_OUTLINE_STARTED':
scenario = createScenario(line, tags);
feature.scenarios.push(scenario);
tags = [];
break;
case 'EXAMPLES_STARTED':
scenario.examples = createExamples(line);
break;
default:
}
} else if (line.startsWith('@')) {
tags = line.split(' ');
if (!currentPhase) {
// Feature tags
feature.tags = tags;
}
} else if (line.startsWith('#')) {
// Gherkin comments start with '#' and are required to take an entire line.
// We want to skip any comment lines.
} else if (line.startsWith('|')) {
const step = scenario.steps[scenario.steps.length - 1];
const lines = line
.split('|')
.filter((entry) => entry).map((entry) => entry.trim());
switch (currentPhase) {
case 'EXAMPLES_STARTED':
scenario.examples.table.push(lines);
break;
default:
step.table.push(lines);
}
} else if (stepStarting(translations, line)) {
if (scenario) {
scenario.steps.push(createStep(line));
}
} else if (line.length > 0) {
// Nothing new is starting. Must be part of a description
switch (currentPhase) {
case 'FEATURE_STARTED':
feature.description += feature.description ? `\n${line}` : line;
break;
case 'BACKGROUND_STARTED':
feature.background.description += feature.background.description ? `\n${line}` : line;
break;
default:
if (scenario) {
scenario.description += scenario.description ? `\n${line}` : line;
}
const lines = line
.split('|')
.filter((entry) => entry).map((entry) => entry.trim());
switch (currentPhase) {
case 'EXAMPLES_STARTED':
scenario.examples.table.push(lines);
break;
default:
step.table.push(lines);
}
} else if (stepStarting(translations, line)) {
if (scenario) {
scenario.steps.push(createStep(line));
}
} else if (line.length > 0) {
// Nothing new is starting. Must be part of a description
switch (currentPhase) {
case 'FEATURE_STARTED':
feature.description += feature.description ? `\n${line}` : line;
break;
case 'BACKGROUND_STARTED':
feature.background.description += feature.background.description ? `\n${line}` : line;
break;
default:
if (scenario) {
scenario.description += scenario.description ? `\n${line}` : line;
}
}
}
} catch (e) {
if (featureFilename) e.featurefile = featureFilename;
if (typeof index !== 'undefined') e.featureline = index + 1;
throw e;
}
});
return feature;
Expand Down

0 comments on commit b888aa6

Please sign in to comment.