|
10 | 10 |
|
11 | 11 | import { Datex } from "datex-core-legacy";
|
12 | 12 | import { AssertionError, Disjunction, Endpoint, Logger, LOG_LEVEL, logger } from "datex-core-legacy/datex_all.ts";
|
13 |
| -import { handleDecoratorArgs, METADATA } from "./legacy_decorators.ts"; |
14 |
| -import type { context_kind, context_meta_getter, context_meta_setter, context_name } from "./legacy_decorators.ts"; |
15 | 13 | import { TestGroupOptions } from "../core/test_case.ts";
|
16 |
| -import { handleClassDecoratorWithOptionalArgs } from "datex-core-legacy/mod.ts"; |
17 |
| -import { Decorators } from "datex-core-legacy/js_adapter/js_class_adapter.ts"; |
| 14 | +import { handleClassDecoratorWithOptionalArgs, handleClassMethodDecoratorWithArgs } from "datex-core-legacy/mod.ts"; |
| 15 | +import { Decorators, METADATA } from "datex-core-legacy/js_adapter/js_class_adapter.ts"; |
18 | 16 |
|
19 | 17 | export * from "./assertions.ts";
|
20 | 18 |
|
@@ -122,23 +120,16 @@ async function registerTests(group_name:string, value:Function){
|
122 | 120 | }
|
123 | 121 |
|
124 | 122 |
|
125 |
| - |
126 |
| - |
127 |
| - |
128 | 123 | export const TEST_GROUP_DATA = Symbol("test_group_data");
|
129 | 124 | export const TEST_CASE_DATA = Symbol("test_case");
|
130 | 125 | export const TIMEOUT = Symbol("timeout");
|
131 | 126 | export const DEFAULT_TIMEOUT = 60; // 60s
|
132 | 127 |
|
133 |
| -type decorator_target = {[key: string]: any} & Partial<Record<keyof Array<any>, never>>; |
134 |
| - |
135 |
| - |
136 |
| -// @Test (legacy decorators support) |
137 | 128 | export function Test(name:string): (value: Function, context: ClassDecoratorContext|ClassMethodDecoratorContext) => void
|
138 | 129 | export function Test(options: TestGroupOptions): (value: Function, context: ClassDecoratorContext) => void
|
139 | 130 | export function Test(name:string, options: TestGroupOptions): (value: Function, context: ClassDecoratorContext) => void
|
140 | 131 |
|
141 |
| -export function Test(test_parameters:(unknown|unknown[])[]): (value: Function, context: ClassMethodDecoratorContext) => void |
| 132 | +export function Test<F extends (...args: any) => any>(test_parameters:(Parameters<F>|(Parameters<F>['length'] extends 1 ? Parameters<F>[0] : never))[]): (value: F, context: ClassMethodDecoratorContext) => void |
142 | 133 | export function Test(name:string, test_parameters:(unknown|unknown[])[]): (value: Function, context: ClassMethodDecoratorContext) => void
|
143 | 134 | // export function Test(name:string, test_parameters:(unknown|unknown[])[], options:TestGroupOptions):any
|
144 | 135 |
|
@@ -195,25 +186,16 @@ function _Test(value:any, context:ClassDecoratorContext|ClassMethodDecoratorCont
|
195 | 186 | }
|
196 | 187 |
|
197 | 188 |
|
198 |
| -// @Timeout (legacy decorators support) - DEFAULT Timeout is 60s, MAX depends on test manager timeout, currently 10min |
199 |
| -export function Timeout(seconds:number):any |
200 |
| -export function Timeout(target: Function):any |
201 |
| -export function Timeout(target: Function, options:any):any |
202 |
| -export function Timeout(...args:any[]) {return handleDecoratorArgs(args, <any>_Timeout)} |
203 |
| - |
204 |
| -function _Timeout(value:any, name:context_name, kind:context_kind, _is_static:boolean, _is_private:boolean, setMetadata:context_meta_setter, getMetadata:context_meta_getter, params:[number]) { |
205 |
| - |
206 |
| - if (kind == 'method') { |
207 |
| - if (!params || typeof params[0] != "number") throw new Error("The @Timeout requires a timeout value (in seconds) as a parameter"); |
208 |
| - |
209 |
| - const test_name = name; |
210 |
| - setMetadata(TIMEOUT, params[0]); |
211 |
| - } |
212 |
| - |
213 |
| - else { |
214 |
| - throw new Error("The @Timeout decorator can only be used on test case methods"); |
215 |
| - } |
216 |
| - |
| 189 | +/** |
| 190 | + * Set a custom timeout for a test case (default is 60s, max depends on test manager timeout, currently 10min) |
| 191 | + * @param seconds timeout in seconds |
| 192 | + * @returns |
| 193 | + */ |
| 194 | +export function Timeout(seconds: number) { |
| 195 | + return handleClassMethodDecoratorWithArgs([seconds], ([seconds], value, context) => { |
| 196 | + if (typeof seconds !== "number") throw new Error("The @Timeout decorator requires a timeout value (in seconds) as a parameter"); |
| 197 | + Decorators.setMetadata(context, TIMEOUT, seconds); |
| 198 | + }) |
217 | 199 | }
|
218 | 200 |
|
219 | 201 | // interface TestManager in main process - ignored if isSameProcess == true
|
|
0 commit comments