forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jest, jest-puppeteer and jest-image-snapshot for e2e tests
- Loading branch information
Showing
8 changed files
with
529 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const curveBasis = 'basis' | ||
export const curveLinear = 'linear' | ||
export const curveCardinal = 'cardinal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// jest.config.js | ||
module.exports = { | ||
verbose: true, | ||
preset: 'jest-puppeteer' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<html> | ||
<head> | ||
<script src="/e2e.js"></script> | ||
<link | ||
href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<style></style> | ||
</head> | ||
<body> | ||
<script src="./mermaid.js"></script> | ||
<script> | ||
mermaid.initialize({ | ||
startOnLoad: false, | ||
useMaxWidth: true, | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Base64 } from 'js-base64' | ||
|
||
/** | ||
* ##contentLoaded | ||
* Callback function that is called when page is loaded. This functions fetches configuration for mermaid rendering and | ||
* calls init for rendering the mermaid diagrams on the page. | ||
*/ | ||
const contentLoaded = function () { | ||
let pos = document.location.href.indexOf('?graph=') | ||
if (pos > 0) { | ||
pos = pos + 7 | ||
const graphBase64 = document.location.href.substr(pos) | ||
const graphObj = JSON.parse(Base64.decode(graphBase64)) | ||
// const graph = 'hello' | ||
console.log(graphObj.code) | ||
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.init() | ||
} | ||
} | ||
|
||
if (typeof document !== 'undefined') { | ||
/*! | ||
* Wait for document loaded before starting the execution | ||
*/ | ||
window.addEventListener( | ||
'load', | ||
function () { | ||
contentLoaded() | ||
}, | ||
false | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-env jest */ | ||
describe('Google', () => { | ||
beforeAll(async () => { | ||
await page.goto('https://google.com') | ||
}) | ||
|
||
it('should be titled "Google"', async () => { | ||
await expect(page.title()).resolves.toMatch('Google') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const path = require('path') | ||
|
||
const jsRule = { | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader' | ||
} | ||
} | ||
|
||
const amdRule = { | ||
parser: { | ||
amd: false // https://github.com/lodash/lodash/issues/3052 | ||
} | ||
} | ||
const scssRule = { | ||
// load scss to string | ||
test: /\.scss$/, | ||
use: [ | ||
{ loader: 'css-to-string-loader' }, | ||
{ loader: 'css-loader' }, | ||
{ loader: 'sass-loader' } | ||
] | ||
} | ||
|
||
module.exports = { | ||
mode: 'development', | ||
target: 'web', | ||
entry: { | ||
mermaid: './src/mermaid.js', | ||
e2e: './e2e/platform/viewer.js' | ||
}, | ||
node: { | ||
fs: 'empty' // jison generated code requires 'fs' | ||
}, | ||
output: { | ||
path: path.join(__dirname, './dist/'), | ||
filename: '[name].js', | ||
library: 'mermaid', | ||
libraryTarget: 'umd', | ||
libraryExport: 'default' | ||
}, | ||
devServer: { | ||
contentBase: [ | ||
path.join(__dirname, 'e2e', 'platform'), | ||
path.join(__dirname, 'dist') | ||
], | ||
compress: true, | ||
port: 9000 | ||
}, | ||
module: { | ||
rules: [amdRule, jsRule, scssRule] | ||
}, | ||
externals: { | ||
mermaid: 'mermaid' | ||
}, | ||
devtool: 'source-map' | ||
} |
Oops, something went wrong.