mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
31 lines
700 B
JavaScript
31 lines
700 B
JavaScript
/* eslint-env jest */
|
|
import { Base64 } from 'js-base64'
|
|
|
|
export const mermaidUrl = (graphStr, options, api) => {
|
|
const obj = {
|
|
code: graphStr,
|
|
mermaid: options
|
|
}
|
|
const objStr = JSON.stringify(obj)
|
|
let url = 'http://localhost:9000/e2e.html?graph=' + Base64.encodeURI(objStr)
|
|
if (api) {
|
|
url = 'http://localhost:9000/xss.html?graph=' + graphStr
|
|
}
|
|
|
|
return url
|
|
}
|
|
|
|
export const imgSnapshotTest = async (page, graphStr, options, api) => {
|
|
return new Promise(async resolve => {
|
|
const url = mermaidUrl(graphStr, options, api)
|
|
|
|
await page.goto(url)
|
|
|
|
const image = await page.screenshot()
|
|
|
|
expect(image).toMatchImageSnapshot()
|
|
resolve()
|
|
})
|
|
// page.close()
|
|
}
|