Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(PowerSearch): load the module graphs before the timed waits that do not test the load (#9866)

Christopher Chedeau75cc95196365
diff --git a/packages/core/src/PowerSearch/PowerSearch.ssr.test.tsx b/packages/core/src/PowerSearch/PowerSearch.ssr.test.tsx
index 411cfe341c..66d1d72e0e 100644
--- a/packages/core/src/PowerSearch/PowerSearch.ssr.test.tsx
+++ b/packages/core/src/PowerSearch/PowerSearch.ssr.test.tsx
@@ -18,6 +18,12 @@ import {hydrateRoot} from 'react-dom/client';
import {renderToString} from 'react-dom/server';
import type {PowerSearchConfig, PowerSearchFilter} from './types';
+// The first import of PowerSearch transforms its whole module graph, which
+// takes seconds on an idle machine. This import does that work while the file
+// loads, outside the time limit of each test. Each test still evaluates a
+// fresh graph.
+await import('./PowerSearch');
+
const config: PowerSearchConfig = {
name: 'Issues',
fields: [
diff --git a/packages/core/src/hooks/useAnnounceRenderedText.adopters.test.tsx b/packages/core/src/hooks/useAnnounceRenderedText.adopters.test.tsx
index 3216e7a016..7b9caf3288 100644
--- a/packages/core/src/hooks/useAnnounceRenderedText.adopters.test.tsx
+++ b/packages/core/src/hooks/useAnnounceRenderedText.adopters.test.tsx
@@ -14,9 +14,9 @@
* still announced its own content would be holding an Effect, observer, timer
* or listener of its own for it, which INV10 rules out. The registry check at
* the end keeps this list in step with every file that imports the module, so
- * a new adopter cannot skip the test. The sheet case loads Tokenizer's
- * on-demand sheet module before it opens the sheet, so its wait covers the
- * open, not the module's load.
+ * a new adopter cannot skip the test. The file loads each on-demand sheet
+ * module before any test runs, so a sheet case's waits cover the open, not
+ * the module's load.
*/
import fs from 'node:fs';
@@ -69,6 +69,11 @@ const {Tokenizer} = await import('../Tokenizer/Tokenizer');
const {PowerSearch} = await import('../PowerSearch/PowerSearch');
const {createStaticSource} = await import('../Typeahead/createStaticSource');
const {InfoTip} = await import('../InfoTip/InfoTip');
+// Tokenizer and PowerSearch load their sheets on demand. This file loads
+// both sheet modules before any test runs, so the sheet cases' waits and
+// time limits cover the open, not the module's load.
+await import('../Tokenizer/TokenizerBottomSheet');
+await import('../PowerSearch/PowerSearchBottomSheet');
const source = createStaticSource([{id: 'apple', label: 'Apple'}]);
@@ -180,13 +185,6 @@ const ADOPTERS: Record<string, () => Promise<void>> = {
'Tokenizer/TokenizerBottomSheet.tsx': async () => {
// The sheet's own content is a caller's `emptySearchText` element; the
// default EmptyState announces itself.
- //
- // Tokenizer loads the sheet on demand (Tokenizer.tsx's
- // loadTokenizerBottomSheet). Loading the module is not what this case
- // checks, so it waits for it first, and the one-second wait for the
- // sheet's search field below covers only the open: on a busy machine the
- // module's load alone outlasts it.
- await import('../Tokenizer/TokenizerBottomSheet');
render(
<Tokenizer
label="Tags"