Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add global test registry #568

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion testing/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,29 @@ function print(txt: string, newline: boolean = true): void {
Deno.stdout.writeSync(encoder.encode(`${txt}`));
}

declare global {
interface Window {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to declare this before hand?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it TS complains that __DENO_TEST_REGISTRY doesn't exist on Window:

error TS2339: Property '__DENO_TEST_REGISTRY' does not exist on type 'Window'.

► file:///Users/biwanczuk/dev/deno_std/testing/mod.ts:90:23

90   candidates = window.__DENO_TEST_REGISTRY as TestDefinition[];

I can add @ts-ignore but this solution is more idiomatic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok sounds good.

/**
* 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[];
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
}
}

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.
Expand Down