import path from 'path'; import getMocks from './getMocks'; import parseGherkinSuites from './parseGherkinSuites'; declare global { const cwd: string; const featurePath: string; const moduleFileExtensions: string[]; const restoreMocks: boolean; const supportCodeLibraryBuilder: any; } const act = typeof window === 'undefined' ? async (fn) => await fn() : require('react-test-renderer').act; // if projectConfig.restoreMocks, get all the __mock__ based mocks and remove them if (restoreMocks) { getMocks(cwd).forEach((file) => { jest.unmock(file); }); } // parse the feature file with given cucumber steps / hooks // generating a jasmine-like structure const spec = parseGherkinSuites(cwd, featurePath, moduleFileExtensions, supportCodeLibraryBuilder.options); let world; const fileName = path.basename(featurePath, path.extname(featurePath)); beforeAll(async () => { world = new supportCodeLibraryBuilder.options.World({}); for (let i = 0; i < spec.beforeAll.length; i++) { await act(async () => { await spec.beforeAll[i].code.apply(world, [spec, fileName]); }); } }); afterAll(async () => { for (let i = 0; i < spec.afterAll.length; i++) { await act(async () => { await spec.afterAll[i].code.apply(world, [spec, fileName]); }); } world = null; }); spec.suites.forEach((suite) => { describe(`${spec.document.keyword}: ${spec.document.name} - ${suite.name}`, () => { beforeAll(async () => { for (let i = 0; i < spec.beforeEach.length; i++) { await act(async () => { await spec.beforeEach[i].code.apply(world, [{spec, suite: suite}, fileName]); }); } }); afterAll(async () => { for (let i = 0; i < spec.afterEach.length; i++) { await act(async () => { await spec.afterEach[i].code.apply(world, [{spec, suite: suite}, fileName]); }); } }); for (let i = 0; i < suite.steps.given.length; i++) { it(`${suite.steps.given[i].keyword}${suite.steps.given[i].text}`, async () => { // await act(async () => { await suite.steps.given[i].code.apply(world, suite.steps.given[i].stepArgs); // }); }); } for (let i = 0; i < suite.steps.when.length; i++) { it(`${suite.steps.when[i].keyword}${suite.steps.when[i].text}`, async () => { // await act(async () => { await suite.steps.when[i].code.apply(world, suite.steps.when[i].stepArgs); // }); }); } for (let i = 0; i < suite.steps.then.length; i++) { it(`${suite.steps.then[i].keyword}${suite.steps.then[i].text}`, async () => { // await act(async () => { await suite.steps.then[i].code.apply(world, suite.steps.then[i].stepArgs); // }); }); } }); });