(isNested: boolean)
| 19 | } |
| 20 | |
| 21 | function testPage(isNested: boolean) { |
| 22 | test(class="st">'pre transform', async () => { |
| 23 | expect(await page.$(class="st">'head meta[name=viewport]')).toBeTruthy() |
| 24 | }) |
| 25 | |
| 26 | test(class="st">'string transform', async () => { |
| 27 | expect(await page.textContent(class="st">'h1')).toBe( |
| 28 | isNested ? class="st">'Nested' : class="st">'Transformed', |
| 29 | ) |
| 30 | }) |
| 31 | |
| 32 | test(class="st">'tags transform', async () => { |
| 33 | const el = await page.$(class="st">'head meta[name=description]') |
| 34 | expect(await el.getAttribute(class="st">'content')).toBe(class="st">'a vite app') |
| 35 | |
| 36 | const kw = await page.$(class="st">'head meta[name=keywords]') |
| 37 | expect(await kw.getAttribute(class="st">'content')).toBe(class="st">'es modules') |
| 38 | }) |
| 39 | |
| 40 | test(class="st">'combined transform', async () => { |
| 41 | expect(await page.title()).toBe(class="st">'Test HTML transforms') |
| 42 | class="cm">// the p should be injected to body |
| 43 | expect(await page.textContent(class="st">'body p.inject')).toBe(class="st">'This is injected') |
| 44 | }) |
| 45 | |
| 46 | test(class="st">'server only transform', async () => { |
| 47 | if (!isBuild) { |
| 48 | expect(await page.textContent(class="st">'body p.server')).toMatch( |
| 49 | class="st">'injected only during dev', |
| 50 | ) |
| 51 | } else { |
| 52 | expect(await page.innerHTML(class="st">'body')).not.toMatch(class="st">'p class="server"') |
| 53 | } |
| 54 | }) |
| 55 | |
| 56 | test(class="st">'build only transform', async () => { |
| 57 | if (isBuild) { |
| 58 | expect(await page.textContent(class="st">'body p.build')).toMatch( |
| 59 | class="st">'injected only during build', |
| 60 | ) |
| 61 | } else { |
| 62 | expect(await page.innerHTML(class="st">'body')).not.toMatch(class="st">'p class="build"') |
| 63 | } |
| 64 | }) |
| 65 | |
| 66 | test(class="st">'conditional transform', async () => { |
| 67 | if (isNested) { |
| 68 | expect(await page.textContent(class="st">'body p.conditional')).toMatch( |
| 69 | class="st">'injected only for /nested/', |
| 70 | ) |
| 71 | } else { |
| 72 | expect(await page.innerHTML(class="st">'body')).not.toMatch(class="st">'p class="conditional"') |
| 73 | } |
| 74 | }) |
| 75 | |
| 76 | test(class="st">'body prepend/append transform', async () => { |
| 77 | expect(await page.innerHTML(class="st">'body')).toMatch( |
| 78 | /prepended to body(.*)appended to body/s, |
no test coverage detected