Skip to content

Commit 675fc43

Browse files
test: less fragile.
1 parent 006385a commit 675fc43

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

playwright/app.spec.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ const waitForInitialRender = async (page: Page) => {
1111
await expect(page.locator('#cdn-loading')).toHaveAttribute('hidden', '')
1212
}
1313

14+
const expectPreviewHasRenderedContent = async (page: Page) => {
15+
const previewHost = page.locator('#preview-host')
16+
await expect(previewHost.locator('pre')).toHaveCount(0)
17+
await expect
18+
.poll(() => previewHost.evaluate(node => node.childElementCount))
19+
.toBeGreaterThan(0)
20+
}
21+
1422
const setComponentEditorSource = async (page: Page, source: string) => {
1523
const editorContent = page.locator('.component-panel .cm-content').first()
1624
await editorContent.fill(source)
@@ -26,10 +34,7 @@ test('renders default playground preview', async ({ page }) => {
2634

2735
await page.getByLabel('ShadowRoot (open)').uncheck()
2836
await expect(page.locator('#status')).toHaveText('Rendered')
29-
30-
const previewItems = page.locator('#preview-host li')
31-
await expect(previewItems).toHaveCount(3)
32-
await expect(previewItems.first()).toContainText('apple')
37+
await expectPreviewHasRenderedContent(page)
3338
})
3439

3540
test('supports layout and theme toggles', async ({ page }) => {
@@ -56,10 +61,7 @@ test('renders in react mode with css modules', async ({ page }) => {
5661
await page.locator('#render-mode').selectOption('react')
5762
await page.locator('#style-mode').selectOption('module')
5863
await expect(page.locator('#status')).toHaveText('Rendered')
59-
60-
const previewItems = page.locator('#preview-host li')
61-
await expect(previewItems).toHaveCount(3)
62-
await expect(previewItems.first()).toContainText('apple')
64+
await expectPreviewHasRenderedContent(page)
6365
})
6466

6567
test('transpiles TypeScript annotations in component source', async ({ page }) => {
@@ -156,10 +158,7 @@ test('renders with less style mode', async ({ page }) => {
156158
await expect(page.locator('#style-warning')).toContainText(
157159
'Less is compiled in-browser via @knighted/css/browser.',
158160
)
159-
160-
const previewItems = page.locator('#preview-host li')
161-
await expect(previewItems).toHaveCount(3)
162-
await expect(previewItems.first()).toContainText('apple')
161+
await expectPreviewHasRenderedContent(page)
163162
})
164163

165164
test('renders with sass style mode', async ({ page }) => {
@@ -171,10 +170,7 @@ test('renders with sass style mode', async ({ page }) => {
171170
await expect(page.locator('#style-warning')).toContainText(
172171
'Sass is compiled in-browser via @knighted/css/browser.',
173172
)
174-
175-
const previewItems = page.locator('#preview-host li')
176-
await expect(previewItems).toHaveCount(3)
177-
await expect(previewItems.first()).toContainText('apple')
173+
await expectPreviewHasRenderedContent(page)
178174
})
179175

180176
test('style compilation errors populate styles diagnostics scope', async ({ page }) => {

0 commit comments

Comments
 (0)