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

Define local types for @embroider/core, since we have no guarantees of the consuming test environment #1799

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 deletions packages/core/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export function warn(message: string, ...params: any[]) {
}
}

/**
* This type is normally from QUnit as a global.
* But dependents on `@embroider/core` may not be testing with QUnit,
* so we can't rely on the global availability of the NestedHooks interface.
*
* Here, we define only what we use in a way that is compatible with QUnit's types.
*/
interface NestedHooks {
before: (callback: () => void | Promise<void>) => void;
after: (callback: () => void | Promise<void>) => void;
}

// for use in our test suites
let hardFailMode = 0;
export function throwOnWarnings(hooks?: NestedHooks) {
Expand All @@ -47,9 +59,12 @@ export function throwOnWarnings(hooks?: NestedHooks) {
hardFailMode--;
});
} else {
// Jest mode
beforeAll(() => hardFailMode++);
afterAll(() => hardFailMode--);
/**
* Like with QUnit's NestedHooks, we can't be certain that our
* consuming environment will provide types for beforeAll and afterAll
*/
(globalThis as any).beforeAll(() => hardFailMode++);
(globalThis as any).afterAll(() => hardFailMode--);
}
}

Expand Down
Loading