Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,4 +1,4 @@
import { describe, expect, test } from 'vitest'
import { describe, expect, test, vi } from 'vitest'
import {
browserErrors,
browserLogs,
Expand All @@ -8,16 +8,13 @@ import {
isServe,
listAssets,
page,
ports,
readManifest,
serverLogs,
untilBrowserLogAfter,
untilUpdated,
} from '~utils'

const outerAssetMatch = isBuild
? /\/dev\/assets\/logo-[-\w]{8}\.png/
: /\/dev\/@fs\/.+?\/images\/logo\.png/

test('should have no 404s', () => {
browserLogs.forEach((msg) => {
expect(msg).not.toMatch('404')
Expand All @@ -26,9 +23,25 @@ test('should have no 404s', () => {

describe('asset imports from js', () => {
test('file outside root', async () => {
expect(
await page.textContent('.asset-reference.outside-root .asset-url'),
).toMatch(outerAssetMatch)
// assert valid image src https://github.com/microsoft/playwright/issues/6046#issuecomment-1799585719
await vi.waitUntil(() =>
page
.locator('.asset-reference.outside-root .asset-preview')
.evaluate((el: HTMLImageElement) => el.naturalWidth > 0),
)

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
6 changes: 6 additions & 0 deletions playground/backend-integration/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ function BackendIntegrationExample() {
entrypoints.push(['bar.css', path.resolve(__dirname, './dir/foo.css')])

return {
server: {
// same port in playground/test-utils.ts
port: 5009,
strictPort: true,
origin: 'http://localhost:5009',
},
build: {
manifest: true,
outDir,
Expand Down
5 changes: 0 additions & 5 deletions playground/tailwind/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export default defineConfig({
// to make tests faster
minify: false,
},
server: {
// This option caused issues with HMR,
// although it should not affect the build
origin: 'http://localhost:8080',
},
Comment on lines -30 to -34
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically this is testing server.origin, but this relies on rather redundant prepend/strip base manipulation, which is going to removed in #17886.

plugins: [
{
name: 'delay view',
Expand Down
1 change: 1 addition & 0 deletions playground/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const ports = {
'css/postcss-plugins-different-dir': 5006,
'css/dynamic-import': 5007,
'css/lightningcss-proxy': 5008,
'backend-integration': 5009,
}
export const hmrPorts = {
'optimize-missing-deps': 24680,
Expand Down