Skip to content

Commit ed5ecd9

Browse files
authored
test: test server.origin (#17886)
1 parent e012f29 commit ed5ecd9

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

playground/backend-integration/__tests__/backend-integration.spec.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, test } from 'vitest'
1+
import { describe, expect, test, vi } from 'vitest'
22
import {
33
browserErrors,
44
browserLogs,
@@ -8,16 +8,13 @@ import {
88
isServe,
99
listAssets,
1010
page,
11+
ports,
1112
readManifest,
1213
serverLogs,
1314
untilBrowserLogAfter,
1415
untilUpdated,
1516
} from '~utils'
1617

17-
const outerAssetMatch = isBuild
18-
? /\/dev\/assets\/logo-[-\w]{8}\.png/
19-
: /\/dev\/@fs\/.+?\/images\/logo\.png/
20-
2118
test('should have no 404s', () => {
2219
browserLogs.forEach((msg) => {
2320
expect(msg).not.toMatch('404')
@@ -26,9 +23,25 @@ test('should have no 404s', () => {
2623

2724
describe('asset imports from js', () => {
2825
test('file outside root', async () => {
29-
expect(
30-
await page.textContent('.asset-reference.outside-root .asset-url'),
31-
).toMatch(outerAssetMatch)
26+
// assert valid image src https://github.com/microsoft/playwright/issues/6046#issuecomment-1799585719
27+
await vi.waitUntil(() =>
28+
page
29+
.locator('.asset-reference.outside-root .asset-preview')
30+
.evaluate((el: HTMLImageElement) => el.naturalWidth > 0),
31+
)
32+
33+
const text = await page.textContent(
34+
'.asset-reference.outside-root .asset-url',
35+
)
36+
if (isBuild) {
37+
expect(text).toMatch(/\/dev\/assets\/logo-[-\w]{8}\.png/)
38+
} else {
39+
// asset url is prefixed with server.origin
40+
expect(text).toMatch(
41+
`http://localhost:${ports['backend-integration']}/dev/@fs/`,
42+
)
43+
expect(text).toMatch(/\/dev\/@fs\/.+?\/images\/logo\.png/)
44+
}
3245
})
3346
})
3447

playground/backend-integration/vite.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ function BackendIntegrationExample() {
2222
entrypoints.push(['bar.css', path.resolve(__dirname, './dir/foo.css')])
2323

2424
return {
25+
server: {
26+
// same port in playground/test-utils.ts
27+
port: 5009,
28+
strictPort: true,
29+
origin: 'http://localhost:5009',
30+
},
2531
build: {
2632
manifest: true,
2733
outDir,

playground/tailwind/vite.config.ts

-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ export default defineConfig({
2727
// to make tests faster
2828
minify: false,
2929
},
30-
server: {
31-
// This option caused issues with HMR,
32-
// although it should not affect the build
33-
origin: 'http://localhost:8080',
34-
},
3530
plugins: [
3631
{
3732
name: 'delay view',

playground/test-utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const ports = {
4646
'css/postcss-plugins-different-dir': 5006,
4747
'css/dynamic-import': 5007,
4848
'css/lightningcss-proxy': 5008,
49+
'backend-integration': 5009,
4950
}
5051
export const hmrPorts = {
5152
'optimize-missing-deps': 24680,

0 commit comments

Comments
 (0)