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AC,GAAG;YAAS,cAAuB;iBAAvB,UAAuB,EAAvB,qBAAuB,EAAvB,IAAuB;gBAAvB,yBAAuB;;YAC9C,IAAM,cAAc,GAAG,cAAc;gBACnC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;gBACnC,CAAC,CAAC,SAAS,CAAC;YACd,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC;gBAC1C,OAAC,QAAkC,CAAC,KAAK,CAAC,YAAqB,EAAE,IAAI,CAAC;YAAtE,CAAsE,CACvE,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC","sourcesContent":["/**\n * This is the TDD interface for registering suites. Typically it will be\n * accessed using [[lib/executors/Executor.Executor.getInterface]], like:\n *\n * ```js\n * const { suite, test } = intern.getInterface('tdd');\n * ```\n *\n * It may also be imported as a module, like\n *\n * ```js\n * import { suite, test } from 'intern/lib/interfaces/tdd';\n * ```\n *\n * Suites are registered using callback functions, and tests can be registered\n * within the suite callbacks.\n *\n * ```js\n * suite('foo', () => {\n * before(() => { ... });\n * afterEach(() => { ... });\n * test('bar', () => { ... });\n * test('baz', () => { ... });\n * });\n */ /** */\nimport { global } from '@theintern/common';\nimport Suite, {\n SuiteProperties,\n SuiteLifecycleFunction,\n TestLifecycleFunction\n} from '../Suite';\nimport Test, { TestProperties } from '../Test';\nimport { Executor } from '../executors/Executor';\n\nexport interface TddInterface extends TddLifecycleInterface {\n suite(name: string, factory: TddSuiteFactory): void;\n test(name: string, test: TestProperties['test']): void;\n}\n\nexport interface TddLifecycleInterface {\n before(fn: SuiteProperties['before']): void;\n after(fn: SuiteProperties['after']): void;\n beforeEach(fn: SuiteProperties['beforeEach']): void;\n afterEach(fn: SuiteProperties['afterEach']): void;\n}\n\nexport type TddSuiteFactory = (suite: Suite) => void;\n\nexport function suite(name: string, factory: TddSuiteFactory) {\n return _suite(global.intern, name, factory);\n}\n\nexport function test(name: string, test: TestProperties['test']) {\n if (!currentSuite) {\n throw new Error('A test must be declared within a suite');\n }\n currentSuite.add(new Test({ name, test }));\n}\n\nexport function before(fn: SuiteProperties['before']) {\n if (!currentSuite) {\n throw new Error('A suite lifecycle method must be declared within a suite');\n }\n aspect(currentSuite, 'before', fn!);\n}\n\nexport function after(fn: SuiteProperties['after']) {\n if (!currentSuite) {\n throw new Error('A suite lifecycle method must be declared within a suite');\n }\n aspect(currentSuite, 'after', fn!);\n}\n\nexport function beforeEach(fn: SuiteProperties['beforeEach']) {\n if (!currentSuite) {\n throw new Error('A suite lifecycle method must be declared within a suite');\n }\n aspect(currentSuite, 'beforeEach', fn!);\n}\n\nexport function afterEach(fn: SuiteProperties['afterEach']) {\n if (!currentSuite) {\n throw new Error('A suite lifecycle method must be declared within a suite');\n }\n aspect(currentSuite, 'afterEach', fn!);\n}\n\nexport function getInterface(executor: Executor): TddInterface {\n return {\n suite(name: string, factory: TddSuiteFactory) {\n return _suite(executor, name, factory);\n },\n\n test,\n before,\n after,\n beforeEach,\n afterEach\n };\n}\n\nlet currentSuite: Suite | null;\n\nfunction registerSuite(name: string, factory: TddSuiteFactory) {\n const parent = currentSuite!;\n\n currentSuite = new Suite({ name, parent });\n parent.add(currentSuite);\n\n factory(currentSuite);\n\n currentSuite = parent;\n}\n\nfunction _suite(executor: Executor, name: string, factory: TddSuiteFactory) {\n if (!currentSuite) {\n executor.addSuite(parent => {\n currentSuite = parent;\n registerSuite(name, factory);\n currentSuite = null;\n });\n } else {\n registerSuite(name, factory);\n }\n}\n\nfunction aspect(\n suite: Suite,\n method: 'before' | 'after' | 'beforeEach' | 'afterEach',\n callback: SuiteLifecycleFunction | TestLifecycleFunction\n) {\n const originalMethod = suite[method] as (\n this: Suite,\n firstArg: Suite | Test\n ) => void;\n suite[method] = function(...args: [Suite | Test]) {\n const originalReturn = originalMethod\n ? originalMethod.apply(suite, args)\n : undefined;\n return Promise.resolve(originalReturn).then(() =>\n (callback as typeof originalMethod).apply(currentSuite as Suite, args)\n );\n };\n}\n"]} |