MCPcopy
hub / github.com/codeceptjs/CodeceptJS / gherkinParser

Function gherkinParser

lib/mocha/gherkin.js:23–164  ·  view source on GitHub ↗
(text, file)

Source from the content-addressed store, hash-verified

21parser.stopAtFirstError = false
22
23const gherkinParser = (text, file) => {
24 const ast = parser.parse(text)
25 let currentLanguage
26
27 if (ast.feature) {
28 // Ensure translations are loaded before trying to access them
29 currentLanguage = getTranslation(ast.feature.language)
30 }
31
32 if (!ast.feature) {
33 throw new Error(`No 'Features' available in Gherkin '${file}' provided!`)
34 }
35 const suite = new Suite(ast.feature.name, new Context())
36 enhanceMochaSuite(suite)
37 const tags = ast.feature.tags.map(t => t.name)
38 suite.title = `${suite.title} ${tags.join(' ')}`.trim()
39 suite.tags = tags || []
40 suite.comment = ast.feature.description
41 suite.feature = ast.feature
42 suite.file = file
43 suite.timeout(0)
44
45 suite.beforeEach('codeceptjs.before', function (done) {
46 // In Mocha, 'this' is the hook Context; currentTest is the running scenario
47 setup(this)(done)
48 })
49 suite.afterEach('codeceptjs.after', function (done) {
50 teardown(this)(done)
51 })
52 suite.beforeAll('codeceptjs.beforeSuite', suiteSetup(suite))
53 suite.afterAll('codeceptjs.afterSuite', suiteTeardown(suite))
54
55 const runSteps = async steps => {
56 for (const step of steps) {
57 const metaStep = new MetaStep(null, step.text)
58 metaStep.actor = step.keyword.trim()
59 let helperStep
60 const setMetaStep = step => {
61 helperStep = step
62 if (step.metaStep) {
63 if (step.metaStep === metaStep) {
64 return
65 }
66 setMetaStep(step.metaStep)
67 return
68 }
69 step.metaStep = metaStep
70 }
71 const fn = matchStep(step.text)
72
73 if (step.dataTable) {
74 fn.params.push({
75 ...step.dataTable,
76 parse: () => new DataTableArgument(step.dataTable),
77 })
78 metaStep.comment = `\n${transformTable(step.dataTable)}`
79 }
80

Callers 1

createMethod · 0.85

Calls 15

enhanceMochaSuiteFunction · 0.90
setupFunction · 0.90
teardownFunction · 0.90
suiteSetupFunction · 0.90
suiteTeardownFunction · 0.90
injectedFunction · 0.90
createTestFunction · 0.90
getTranslationFunction · 0.85
runStepsFunction · 0.85
transformFunction · 0.85
addExampleInTableFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected