Adding image snapshots for graphs

This commit is contained in:
Knut Sveidqvist 2019-05-31 14:20:43 +02:00
parent 7242a98adb
commit 357e738983
9 changed files with 1147 additions and 60 deletions

View File

@ -1,5 +1,12 @@
module.exports = {
'presets': [
'@babel/preset-env'
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
]
}

13
e2e/helpers/util.js Normal file
View File

@ -0,0 +1,13 @@
import { Base64 } from 'js-base64'
const mermaidUrl = (graphStr, options) => {
const obj = {
code: graphStr,
mermaid: options
}
const objStr = JSON.stringify(obj)
// console.log(Base64)
return 'http://localhost:9000/e2e.html?graph=' + Base64.encodeURI(objStr)
}
export default mermaidUrl

View File

@ -1,5 +0,0 @@
// jest.config.js
module.exports = {
verbose: true,
preset: 'jest-puppeteer'
}

11
e2e/jest.config.js Normal file
View File

@ -0,0 +1,11 @@
// jest.config.js
module.exports = {
// verbose: true,
transform: {
'^.+\\.jsx?$': '../transformer.js'
},
preset: 'jest-puppeteer',
'globalSetup': 'jest-environment-puppeteer/setup',
'globalTeardown': 'jest-environment-puppeteer/teardown',
'testEnvironment': 'jest-environment-puppeteer'
}

View File

@ -12,23 +12,13 @@ const contentLoaded = function () {
const graphBase64 = document.location.href.substr(pos)
const graphObj = JSON.parse(Base64.decode(graphBase64))
// const graph = 'hello'
console.log(graphObj.code)
console.log(graphObj)
const div = document.createElement('div')
div.id = 'block'
div.className = 'mermaid'
div.innerHTML = graphObj.code
document.getElementsByTagName('body')[0].appendChild(div)
global.mermaid.initialize({
theme: 'neutral',
themeCSS: '.node rect { fill: red; }',
htmlLabels: false,
// logLevel: 3,
// flowchart: { curve: 'linear' },
// gantt: { axisFormat: '%m/%d/%Y' },
// sequence: { actorMargin: 50 },
// sequenceDiagram: { actorMargin: 300 } // deprecated
startOnLoad: false
})
global.mermaid.initialize(graphObj.mermaid)
global.mermaid.init()
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,10 +1,23 @@
/* eslint-env jest */
describe('Google', () => {
beforeAll(async () => {
await page.goto('https://google.com')
})
import mermaidUrl from '../helpers/util.js'
const { toMatchImageSnapshot } = require('jest-image-snapshot')
it('should be titled "Google"', async () => {
await expect(page.title()).resolves.toMatch('Google')
expect.extend({ toMatchImageSnapshot })
describe('Google', () => {
it('should apa', async () => {
const url = mermaidUrl(`graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`, {})
await page.goto(url)
const image = await page.screenshot()
expect(image).toMatchImageSnapshot()
})
})

View File

@ -17,7 +17,7 @@
"build:watch": "yarn build --watch",
"release": "yarn build -p --config webpack.config.prod.babel.js",
"lint": "standard",
"e2e": "yarn lint && jest e2e",
"e2e": "yarn lint && jest e2e --config e2e/jest.config.js",
"test": "yarn lint && jest src",
"test:watch": "jest --watch src",
"jison": "node -r @babel/register node_modules/.bin/gulp jison",
@ -65,14 +65,17 @@
"husky": "^1.2.1",
"identity-obj-proxy": "^3.0.0",
"jest": "^23.6.0",
"jest-environment-puppeteer": "^4.2.0",
"jest-image-snapshot": "^2.8.2",
"jest-puppeteer": "^4.2.0",
"jison": "^0.4.18",
"node-sass": "^4.11.0",
"puppeteer": "^1.17.0",
"sass-loader": "^7.1.0",
"standard": "^12.0.1",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.4.1",
"webpack-node-externals": "^1.7.2",
"yarn-upgrade-all": "^0.5.0"
},

1123
yarn.lock

File diff suppressed because it is too large Load Diff