Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@ test('should have no 404s', () => {

describe('asset imports from js', () => {
test('file outside root', async () => {
await vi.waitFor(async () => {
const text = await page.textContent(
'.asset-reference.outside-root .asset-url',
)
if (isBuild) {
expect(text).toMatch(/\/dev\/assets\/logo-[-\w]{8}\.png/)
} else {
// asset url is prefixed with server.origin
expect(text).toMatch(
`http://localhost:${ports['backend-integration']}/dev/@fs/`,
)
expect(text).toMatch(/\/dev\/@fs\/.+?\/images\/logo\.png/)
}
// assert valid image src https://github.com/microsoft/playwright/issues/6046#issuecomment-1799585719
await vi.waitFor(() =>
page
.locator('.asset-reference.outside-root .asset-preview')
.evaluate((el: HTMLImageElement) => el.naturalWidth > 0),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use expect so that it throws if the image is not shown yet? Not familiar with waitFor, but I thought it would retry only when it throws

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. I meant to use waitUntil https://vitest.dev/api/vi.html#vi-waituntil


expect(
await page
.locator('.asset-reference.outside-root .asset-preview')
.evaluate((el: HTMLImageElement) => el.naturalWidth > 0),
).toBe(true)
})
const text = await page.textContent(
'.asset-reference.outside-root .asset-url',
)
if (isBuild) {
expect(text).toMatch(/\/dev\/assets\/logo-[-\w]{8}\.png/)
} else {
// asset url is prefixed with server.origin
expect(text).toMatch(
`http://localhost:${ports['backend-integration']}/dev/@fs/`,
)
expect(text).toMatch(/\/dev\/@fs\/.+?\/images\/logo\.png/)
}
})
})

Expand Down