From 73212d80397cf6a60115ef8f0a469c85a731b7bb Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:09:41 -0500 Subject: [PATCH 1/2] Define local types for @embroider/core, since we have no guarantees of the consuming test environment --- packages/core/src/messages.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/core/src/messages.ts b/packages/core/src/messages.ts index 4b5368551..899346cf2 100644 --- a/packages/core/src/messages.ts +++ b/packages/core/src/messages.ts @@ -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; + after: (callback: () => void | Promise) => void; +} + // for use in our test suites let hardFailMode = 0; export function throwOnWarnings(hooks?: NestedHooks) { @@ -48,8 +60,14 @@ export function throwOnWarnings(hooks?: NestedHooks) { }); } else { // Jest mode - beforeAll(() => hardFailMode++); - afterAll(() => hardFailMode--); + if ('beforeAll' in globalThis && 'afterAll' in globalThis) { + /** + * 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--); + } } } From b52f7412c1df6e0850031dd693e073a4dbf558c0 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Tue, 13 Feb 2024 11:40:00 -0500 Subject: [PATCH 2/2] remove guard --- packages/core/src/messages.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/core/src/messages.ts b/packages/core/src/messages.ts index 899346cf2..866a7a4de 100644 --- a/packages/core/src/messages.ts +++ b/packages/core/src/messages.ts @@ -59,15 +59,12 @@ export function throwOnWarnings(hooks?: NestedHooks) { hardFailMode--; }); } else { - // Jest mode - if ('beforeAll' in globalThis && 'afterAll' in globalThis) { - /** - * 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--); - } + /** + * 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--); } }