1- import { describe , expect , test } from 'vitest'
1+ import { describe , expect , test , vi } from 'vitest'
22import {
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- ? / \/ d e v \/ a s s e t s \/ l o g o - [ - \w ] { 8 } \. p n g /
19- : / \/ d e v \/ @ f s \/ .+ ?\/ i m a g e s \/ l o g o \. p n g /
20-
2118test ( 'should have no 404s' , ( ) => {
2219 browserLogs . forEach ( ( msg ) => {
2320 expect ( msg ) . not . toMatch ( '404' )
@@ -26,9 +23,25 @@ test('should have no 404s', () => {
2623
2724describe ( '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 ( / \/ d e v \/ a s s e t s \/ l o g o - [ - \w ] { 8 } \. p n g / )
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 ( / \/ d e v \/ @ f s \/ .+ ?\/ i m a g e s \/ l o g o \. p n g / )
44+ }
3245 } )
3346} )
3447
0 commit comments