Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: test server.origin #17886

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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.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
Collaborator 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


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
8 changes: 8 additions & 0 deletions playground/backend-integration/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ 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,
// TODO: should this be automatically inferred from dev server address?
// (see "boolean or string" discussions in https://github.com/vitejs/vite/pull/4337)
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
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
Collaborator 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