forked from element-plus/element-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.spec.puppeteer.tsx
More file actions
70 lines (60 loc) · 1.92 KB
/
demo.spec.puppeteer.tsx
File metadata and controls
70 lines (60 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import path from 'path'
import { createApp } from 'vue'
import { renderToString } from '@vue/server-renderer'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import puppeteer from 'puppeteer'
import glob from 'fast-glob'
import ElementPlus, { ID_INJECTION_KEY } from '../dist/element-plus'
import type { Browser } from 'puppeteer'
const projectRoot = process.cwd()
const testRoot = path.resolve(projectRoot, 'ssr-testing')
const demoRoot = path.resolve(testRoot, 'cases')
describe('Cypress Button', () => {
let browser: Browser
beforeAll(async () => {
browser = await puppeteer.launch()
})
afterAll(() => {
browser.close()
})
describe('when initialized', () => {
const demoPaths = glob
.sync(`${demoRoot}/*.vue`)
.map((demo) => demo.slice(demoRoot.length + 1))
it.each(demoPaths)(`render %s correctly`, async (demoPath) => {
const page = await browser.newPage()
await page.goto(`file://${projectRoot}/ssr-testing/index.html`)
await page.addStyleTag({
path: path.join(
projectRoot,
'dist',
'element-plus',
'dist',
'index.css'
),
})
const { default: Demo } = await import(path.join(demoRoot, demoPath))
const app = createApp(<Demo />)
.use(ElementPlus)
.provide(ID_INJECTION_KEY, {
prefix: 100,
current: 0,
})
const html = await renderToString(app)
await page.evaluate((innerHTML) => {
document.querySelector('#root')!.innerHTML = innerHTML
}, html)
// SSR testing don't need screenshots.
// const screenshotPath = demoPath
// .split('/')
// .join('-')
// .replace(/\.vue$/, '.png')
// await page.screenshot({
// path: path.join(testRoot, 'screenshots', screenshotPath),
// fullPage: true,
// })
await page.close()
expect(true).toBe(true)
})
})
})