|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { after, before, describe, it } from 'node:test'; |
| 3 | +import * as cheerio from 'cheerio'; |
| 4 | +import { isWindows, loadFixture } from './test-utils.js'; |
| 5 | + |
| 6 | +describe('HMR: slots.render with callback args after style change', () => { |
| 7 | + /** @type {import('./test-utils').Fixture} */ |
| 8 | + let fixture; |
| 9 | + /** @type {import('./test-utils').DevServer} */ |
| 10 | + let devServer; |
| 11 | + |
| 12 | + before(async () => { |
| 13 | + fixture = await loadFixture({ root: './fixtures/hmr-slots-render/' }); |
| 14 | + devServer = await fixture.startDevServer(); |
| 15 | + }); |
| 16 | + |
| 17 | + after(async () => { |
| 18 | + await devServer.stop(); |
| 19 | + fixture.resetAllFiles(); |
| 20 | + }); |
| 21 | + |
| 22 | + function verifyRendering($, label) { |
| 23 | + const items = $('#result .item-wrapper'); |
| 24 | + assert.ok( |
| 25 | + items.length >= 3, |
| 26 | + `[${label}] Expected 3 item-wrappers, got ${items.length}. HTML:\n${$('#result').html()?.substring(0, 500)}`, |
| 27 | + ); |
| 28 | + assert.equal($(items[0]).text(), 'one'); |
| 29 | + assert.equal($(items[1]).text(), 'two'); |
| 30 | + assert.equal($(items[2]).text(), 'three'); |
| 31 | + |
| 32 | + // Verify no escaped HTML source code visible (the bug symptom from #15925) |
| 33 | + const resultText = $('#result').text(); |
| 34 | + assert.ok( |
| 35 | + !resultText.includes('data-astro-cid'), |
| 36 | + `[${label}] Found escaped data-astro-cid in output: ${resultText.substring(0, 300)}`, |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + it( |
| 41 | + 'should render after style change in the slot-render component', |
| 42 | + { skip: isWindows }, |
| 43 | + async () => { |
| 44 | + // Initial fetch - verify correct rendering |
| 45 | + let res = await fixture.fetch('/'); |
| 46 | + assert.equal(res.status, 200); |
| 47 | + verifyRendering(cheerio.load(await res.text()), 'initial'); |
| 48 | + |
| 49 | + // Style-only edit (triggers HMR style-only path) |
| 50 | + await fixture.editFile('/src/components/Each.astro', (c) => |
| 51 | + c.replace('font-size: 0.5rem;', 'font-size: 1rem;'), |
| 52 | + ); |
| 53 | + await new Promise((r) => setTimeout(r, 500)); |
| 54 | + |
| 55 | + // Page refresh after HMR - must still render correctly |
| 56 | + res = await fixture.fetch('/'); |
| 57 | + assert.equal(res.status, 200); |
| 58 | + verifyRendering(cheerio.load(await res.text()), 'after style change'); |
| 59 | + |
| 60 | + // Second style edit + refresh |
| 61 | + await fixture.editFile('/src/components/Each.astro', (c) => |
| 62 | + c.replace('font-size: 1rem;', 'font-size: 2rem;'), |
| 63 | + ); |
| 64 | + await new Promise((r) => setTimeout(r, 500)); |
| 65 | + |
| 66 | + res = await fixture.fetch('/'); |
| 67 | + assert.equal(res.status, 200); |
| 68 | + verifyRendering(cheerio.load(await res.text()), 'after 2nd style change'); |
| 69 | + }, |
| 70 | + ); |
| 71 | +}); |
0 commit comments