Skip to content

Commit

Permalink
Merge pull request #48 from xgbuils/gherkin-6-prepare
Browse files Browse the repository at this point in the history
preparing pickle-lint for supporting gherkin@6
  • Loading branch information
xgbuils authored May 31, 2019
2 parents c20eea1 + 59f4fc4 commit 416698c
Show file tree
Hide file tree
Showing 8 changed files with 398 additions and 62 deletions.
113 changes: 113 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
"eslint-config-google": "^0.13.0",
"mocha": "6.1.4",
"npm-check": "^5.9.0",
"nyc": "^14.1.1"
"nyc": "^14.1.1",
"sinon": "^7.3.2"
},
"bin": {
"pickle-lint": "src/main.js"
Expand Down
24 changes: 11 additions & 13 deletions src/linter/no-configurable-linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ class NoConfigurableLinter {
}

lint(file) {
try {
return this.parser.parse(file)
.then(({feature, languageKeywords}) => [{
feature,
languageKeywords,
file,
}]);
} catch (e) {
if (e.errors) {
return Promise.reject(processFatalErrors(e.errors));
}
return Promise.reject(e);
}
return this.parser.parse(file)
.then(({feature, languageKeywords}) => [{
feature,
languageKeywords,
file,
}], (e) => {
if (e.errors) {
return Promise.reject(processFatalErrors(e.errors));
}
return Promise.reject(e);
});
}
}

Expand Down
67 changes: 56 additions & 11 deletions src/parser-adapter/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
module.exports = (Gherkin) => {
const {Parser, DIALECTS} = Gherkin;
const parser = new Parser();
return {
parse({content}) {
const {feature = {}} = parser.parse(content);
return Promise.resolve({
languageKeywords: DIALECTS[feature.language],
feature,
});
},
};
if (Gherkin.Parser) {
const {Parser, DIALECTS} = Gherkin;
const parser = new Parser();
return {
parse({content}) {
try {
const {feature = {}} = parser.parse(content);
return Promise.resolve({
languageKeywords: DIALECTS[feature.language],
feature,
});
} catch (error) {
return Promise.reject(error);
}
},
};
} else {
const {fromPaths} = Gherkin;
return {
parse({path}) {
const stream = fromPaths([path], {
includeSource: false,
includePickles: false,
});

return new Promise((resolve, reject) => {
const gherkinDocuments = [];
const errors = [];
stream.on('error', (error) => {
reject(error);
});
stream.on('data', ({gherkinDocument, attachment}) => {
if (attachment) {
errors.push(attachment);
} else {
gherkinDocuments.push(gherkinDocument);
}
});
stream.on('end', () => {
if (errors.length > 0) {
reject(errors);
} else if (gherkinDocuments.length > 1) {
reject(new Error(
'Unexpected error: fromPaths function returns multiple gherkin documents'
));
} else if (gherkinDocuments.length === 1) {
const [gherkinDocument] = gherkinDocuments;
resolve(gherkinDocument);
} else {
reject(new Error('Unexpected error: zero gherkin documents'));
}
});
});
},
};
}
};
4 changes: 2 additions & 2 deletions test/linter/no-configurable-linter/no-configurable-linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('No Configurable File Linter', function() {
};
const wrongParser = {
parse() {
throw e;
return Promise.reject(e);
},
};
const wrongLinter = new NoConfigurableLinter(wrongParser);
Expand All @@ -258,7 +258,7 @@ describe('No Configurable File Linter', function() {
const error = 'error';
const wrongParser = {
parse() {
throw error;
return Promise.reject(error);
},
};
const wrongLinter = new NoConfigurableLinter(wrongParser);
Expand Down
3 changes: 0 additions & 3 deletions test/parser-adapter/Example.feature

This file was deleted.

1 change: 0 additions & 1 deletion test/parser-adapter/Other.feature

This file was deleted.

Loading

0 comments on commit 416698c

Please sign in to comment.