MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / loadGherkinStepsAsync

Function loadGherkinStepsAsync

lib/container.js:777–830  ·  view source on GitHub ↗
(paths)

Source from the content-addressed store, hash-verified

775}
776
777async function loadGherkinStepsAsync(paths) {
778 // Import BDD module to access step file tracking functions and step DSL
779 const bddModule = await import('./mocha/bdd.js')
780
781 global.Before = fn => event.dispatcher.on(event.test.started, fn)
782 global.After = fn => event.dispatcher.on(event.test.finished, fn)
783 global.Fail = fn => event.dispatcher.on(event.test.failed, fn)
784
785 // Scope-inject Given/When/Then/And while loading step files so they work
786 // with noGlobals: true. When noGlobals: false, globals.js has already set
787 // them as permanent globals — skip to avoid deleting them at the end.
788 const injectStepDsl = !!store.noGlobals
789 if (injectStepDsl) {
790 global.Given = bddModule.Given
791 global.When = bddModule.When
792 global.Then = bddModule.Then
793 global.And = bddModule.And
794 global.DefineParameterType = bddModule.defineParameterType
795 }
796
797 // If gherkin.steps is string, then this will iterate through that folder and send all step def js files to loadSupportObject
798 // If gherkin.steps is Array, it will go the old way
799 // This is done so that we need not enter all Step Definition files under config.gherkin.steps
800 if (Array.isArray(paths)) {
801 for (const path of paths) {
802 // Set context for step definition file location tracking
803 bddModule.setCurrentStepFile(path)
804 await loadSupportObject(path, `Step Definition from ${path}`)
805 bddModule.clearCurrentStepFile()
806 }
807 } else {
808 const folderPath = paths.startsWith('.') ? normalizeAndJoin(store.codeceptDir, paths) : ''
809 if (folderPath !== '') {
810 const files = globSync(folderPath)
811 for (const file of files) {
812 // Set context for step definition file location tracking
813 bddModule.setCurrentStepFile(file)
814 await loadSupportObject(file, `Step Definition from ${file}`)
815 bddModule.clearCurrentStepFile()
816 }
817 }
818 }
819
820 delete global.Before
821 delete global.After
822 delete global.Fail
823 if (injectStepDsl) {
824 delete global.Given
825 delete global.When
826 delete global.Then
827 delete global.And
828 delete global.DefineParameterType
829 }
830}
831
832function loadGherkinSteps(paths) {
833 global.Before = fn => event.dispatcher.on(event.test.started, fn)

Callers 1

createMethod · 0.85

Calls 2

loadSupportObjectFunction · 0.85
normalizeAndJoinFunction · 0.85

Tested by

no test coverage detected