MCPcopy
hub / github.com/vitejs/vite / testPage

Function testPage

playground/html/__tests__/html.spec.ts:21–93  ·  view source on GitHub ↗
(isNested: boolean)

Source from the content-addressed store, hash-verified

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

Callers 1

html.spec.tsFile · 0.85

Calls 2

testFunction · 0.90
getColorFunction · 0.85

Tested by

no test coverage detected