-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basics of a Suspense node appearing are validated, but not yet all details as devtools does not display final children yet.
- Loading branch information
Showing
4 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { h, render } = preact; | ||
const { Suspense } = preactCompat; | ||
const { useMemo } = preactHooks; | ||
|
||
function withDelay(ms) { | ||
useMemo(() => { | ||
let done = false; | ||
const promise = new Promise(resolve => setTimeout(resolve, ms)).then(() => { | ||
done = true; | ||
}); | ||
return () => { | ||
if (!done) { | ||
throw promise; | ||
} | ||
}; | ||
}, [])(); | ||
} | ||
|
||
function Block(props) { | ||
const style = "padding: 2rem; background: " + props.background + ";"; | ||
return html` | ||
<div data-testid=${props.id} style=${style}>${props.children}<//> | ||
`; | ||
} | ||
|
||
function Delayed(props) { | ||
withDelay(props.waitMs); | ||
return html` <${Block} id="delayed" background="cadetblue" /> `; | ||
} | ||
|
||
function Shortly() { | ||
const fallback = html` <${Block} id="skeleton" background="grey" /> `; | ||
return html` | ||
<${Block} id="container" background="black"> | ||
<${Suspense} fallback=${fallback}> | ||
<${Delayed} waitMs=${500} /> | ||
<//> | ||
<//> | ||
`; | ||
} | ||
|
||
render(h(Shortly), document.getElementById("app")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { newTestPage, getSize } from "../test-utils"; | ||
import { expect } from "chai"; | ||
import { wait } from "pentf/utils"; | ||
|
||
import type { Page } from "puppeteer"; | ||
|
||
export const description = "Display and highlighting of Suspense in devtools"; | ||
|
||
function getHighlightSize(page: Page): unknown { | ||
return getSize(page, "#preact-devtools-highlighter > div"); | ||
} | ||
|
||
export async function run(config: any): Promise<void> { | ||
const { page, devtools } = await newTestPage(config, "suspense"); | ||
|
||
// TODO: would expect tree-item list to be: | ||
// ["Block", "Shortly", "Suspense", "Delayed", "Block"] | ||
// but is actually: | ||
// ["Block", "Shortly", "Suspense", "m"] | ||
|
||
await devtools.hover('[data-testid="tree-item"][data-name="Suspense"]'); | ||
// Wait for possible flickering to occur | ||
await wait(1000); | ||
const sizeOnPage = await getSize(page, '[data-testid="container"]'); | ||
const sizeOfHighlight = await getHighlightSize(page); | ||
expect(sizeOfHighlight).to.eql(sizeOnPage); | ||
|
||
// TODO: expect size of delayed child to be correctly shown | ||
} |