import type { GivenScenarioTest, GwtDefinition, TestFunction } from "../../types"; import { executeStep } from "../executeStep"; import { TestContext } from "../contextProvider"; import { executeWhenThen } from "./_whenThen"; import { executeSimple } from "./_simple"; import { isWhenThenScenarioTest } from "./_isWhenThenScenarioTest"; import type { ConfigureTestFunction } from "../../types/Gwt"; export const isScenarioTest = ( test: GwtDefinition, ): test is GivenScenarioTest => Object.keys(test).every((key) => ["given", "scenario", "expect_error"].includes(key)); export const scenarioTest = ( testFunc: TestFunction, configureTestFunction: ConfigureTestFunction | undefined, name: string, gwt: GivenScenarioTest, ) => testFunc(name, async (...args: any[]) => { TestContext.createContext(); const context = TestContext.context as TContext; if (configureTestFunction) { configureTestFunction(context, ...args); } await executeStep(context, gwt.given); if (isWhenThenScenarioTest(gwt)) { await executeWhenThen(context, gwt); } else { await executeSimple(context, gwt); } TestContext.releaseContext(); });