forked from gherkin-lint/gherkin-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from xgbuils/gherkin-6-prepare
preparing pickle-lint for supporting gherkin@6
- Loading branch information
Showing
8 changed files
with
398 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
}); | ||
}); | ||
}, | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.