From 73ad8ff14cdeb5e08bf077bb56dfc78563883c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 18 Aug 2019 18:07:41 +0200 Subject: [PATCH 1/2] add global test registry --- testing/mod.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/testing/mod.ts b/testing/mod.ts index d1ddb9c8ce7b..9eb721d4fd36 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -69,8 +69,19 @@ function print(txt: string, newline: boolean = true): void { Deno.stdout.writeSync(encoder.encode(`${txt}`)); } +declare global { + interface Window { + __DENO_TEST_REGISTRY: TestDefinition[]; + } +} + +let candidates: TestDefinition[] = []; +if (window["__DENO_TEST_REGISTRY"]) { + candidates = window.__DENO_TEST_REGISTRY as TestDefinition[]; +} else { + window["__DENO_TEST_REGISTRY"] = candidates; +} let filterRegExp: RegExp | null; -const candidates: TestDefinition[] = []; let filtered = 0; // Must be called before any test() that needs to be filtered. From 300d14f61793d58f72b1bfc9cd32c42198a0b587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 18 Aug 2019 19:04:55 +0200 Subject: [PATCH 2/2] add JsDoc to __DENO_TEST_REGISTRY --- testing/mod.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/testing/mod.ts b/testing/mod.ts index 9eb721d4fd36..51fa62cea60f 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -71,6 +71,16 @@ function print(txt: string, newline: boolean = true): void { declare global { interface Window { + /** + * A global property to collect all registered test cases. + * + * It is required because user's code can import multiple versions + * of `testing` module. + * + * If test cases aren't registered in a globally shared + * object, then imports from different versions would register test cases + * to registry from it's respective version of `testing` module. + */ __DENO_TEST_REGISTRY: TestDefinition[]; } }