Skip to content

Commit

Permalink
test: test server.origin (#17886)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Aug 20, 2024
1 parent e012f29 commit ed5ecd9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
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',
},
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

0 comments on commit ed5ecd9

Please sign in to comment.