@@ -1620,4 +1620,74 @@ function defineTest(f: Fixture) {
16201620 'test-tree-shake2:lib-client1|lib-server1' ,
16211621 )
16221622 } )
1623+
1624+ test ( 'virtual module with use client' , async ( { page } ) => {
1625+ await page . goto ( f . url ( ) )
1626+ await waitForHydration ( page )
1627+
1628+ // Test that the virtual client component renders and works
1629+ await expect ( page . getByTestId ( 'test-virtual-client' ) ) . toHaveText (
1630+ 'test-virtual-client: not-clicked' ,
1631+ )
1632+ await page . getByTestId ( 'test-virtual-client' ) . click ( )
1633+ await expect ( page . getByTestId ( 'test-virtual-client' ) ) . toHaveText (
1634+ 'test-virtual-client: clicked' ,
1635+ )
1636+ } )
1637+
1638+ test ( 'virtual css module' , async ( { page } ) => {
1639+ await page . goto ( f . url ( ) )
1640+ await waitForHydration ( page )
1641+
1642+ // Server CSS (loaded via <link>)
1643+ // Query-aware: works in both dev and build
1644+ await expect ( page . locator ( '.test-virtual-style-server-query' ) ) . toHaveCSS (
1645+ 'color' ,
1646+ 'rgb(50, 100, 150)' ,
1647+ )
1648+ // Exact-match: fails via <link> in dev (Vite limitation), works in build
1649+ await expect ( page . locator ( '.test-virtual-style-server-exact' ) ) . toHaveCSS (
1650+ 'color' ,
1651+ f . mode === 'dev' ? 'rgb(0, 0, 0)' : 'rgb(200, 100, 50)' ,
1652+ )
1653+
1654+ // Client CSS (loaded via JS import, HMR injects styles)
1655+ // Both patterns work because no ?direct is involved in JS imports
1656+ await expect ( page . locator ( '.test-virtual-style-client-query' ) ) . toHaveCSS (
1657+ 'color' ,
1658+ 'rgb(50, 150, 100)' ,
1659+ )
1660+ await expect ( page . locator ( '.test-virtual-style-client-exact' ) ) . toHaveCSS (
1661+ 'color' ,
1662+ 'rgb(200, 50, 100)' ,
1663+ )
1664+ } )
1665+
1666+ testNoJs ( 'virtual css module @nojs' , async ( { page } ) => {
1667+ await page . goto ( f . url ( ) )
1668+
1669+ // Server CSS (loaded via <link>)
1670+ // Query-aware: works in both dev and build
1671+ await expect ( page . locator ( '.test-virtual-style-server-query' ) ) . toHaveCSS (
1672+ 'color' ,
1673+ 'rgb(50, 100, 150)' ,
1674+ )
1675+ // Exact-match: fails via <link> in dev (Vite limitation)
1676+ await expect ( page . locator ( '.test-virtual-style-server-exact' ) ) . toHaveCSS (
1677+ 'color' ,
1678+ f . mode === 'dev' ? 'rgb(0, 0, 0)' : 'rgb(200, 100, 50)' ,
1679+ )
1680+
1681+ // Client CSS (loaded via <link> in noJS mode)
1682+ // Query-aware: works in both dev and build
1683+ await expect ( page . locator ( '.test-virtual-style-client-query' ) ) . toHaveCSS (
1684+ 'color' ,
1685+ 'rgb(50, 150, 100)' ,
1686+ )
1687+ // Exact-match: fails via <link> in dev (Vite limitation)
1688+ await expect ( page . locator ( '.test-virtual-style-client-exact' ) ) . toHaveCSS (
1689+ 'color' ,
1690+ f . mode === 'dev' ? 'rgb(0, 0, 0)' : 'rgb(200, 50, 100)' ,
1691+ )
1692+ } )
16231693}
0 commit comments