mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-14 21:09:50 +02:00
fix: Cypress test for Suppress Error
This commit is contained in:
@@ -128,20 +128,24 @@ describe('Configuration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('suppressErrorRendering', () => {
|
describe('suppressErrorRendering', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.on('uncaught:exception', (err, runnable) => {
|
||||||
|
return !err.message.includes('Parse error on line');
|
||||||
|
});
|
||||||
|
cy.viewport(1440, 1024);
|
||||||
|
});
|
||||||
|
|
||||||
it('should not render error diagram if suppressErrorRendering is set', () => {
|
it('should not render error diagram if suppressErrorRendering is set', () => {
|
||||||
const url = 'http://localhost:9000/suppressError.html?suppressErrorRendering=true';
|
const url = 'http://localhost:9000/suppressError.html?suppressErrorRendering=true';
|
||||||
cy.viewport(1440, 1024);
|
|
||||||
cy.visit(url);
|
cy.visit(url);
|
||||||
cy.window().should('have.property', 'rendered', true);
|
cy.window().should('have.property', 'rendered', true);
|
||||||
cy.get('#test')
|
cy.get('#test')
|
||||||
.find('svg')
|
.find('svg')
|
||||||
.should(($svg) => {
|
.should(($svg) => {
|
||||||
expect($svg).to.have.length(2); // all failing diagrams should not appear!
|
// all failing diagrams should not appear!
|
||||||
$svg.each((_index, svg) => {
|
expect($svg).to.have.length(2);
|
||||||
expect(cy.$$(svg)).to.be.visible();
|
// none of the diagrams should be error diagrams
|
||||||
// none of the diagrams should be error diagrams
|
expect($svg).to.not.contain('Syntax error');
|
||||||
expect($svg).to.not.contain('Syntax error');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
cy.matchImageSnapshot(
|
cy.matchImageSnapshot(
|
||||||
'configuration.spec-should-not-render-error-diagram-if-suppressErrorRendering-is-set'
|
'configuration.spec-should-not-render-error-diagram-if-suppressErrorRendering-is-set'
|
||||||
@@ -150,10 +154,16 @@ describe('Configuration', () => {
|
|||||||
|
|
||||||
it('should render error diagram if suppressErrorRendering is not set', () => {
|
it('should render error diagram if suppressErrorRendering is not set', () => {
|
||||||
const url = 'http://localhost:9000/suppressError.html';
|
const url = 'http://localhost:9000/suppressError.html';
|
||||||
cy.viewport(1440, 1024);
|
|
||||||
cy.visit(url);
|
cy.visit(url);
|
||||||
cy.window().should('have.property', 'rendered', true);
|
cy.window().should('have.property', 'rendered', true);
|
||||||
cy.get('#test');
|
cy.get('#test')
|
||||||
|
.find('svg')
|
||||||
|
.should(($svg) => {
|
||||||
|
// all five diagrams should be rendered
|
||||||
|
expect($svg).to.have.length(5);
|
||||||
|
// some of the diagrams should be error diagrams
|
||||||
|
expect($svg).to.contain('Syntax error');
|
||||||
|
});
|
||||||
cy.matchImageSnapshot(
|
cy.matchImageSnapshot(
|
||||||
'configuration.spec-should-render-error-diagram-if-suppressErrorRendering-is-not-set'
|
'configuration.spec-should-render-error-diagram-if-suppressErrorRendering-is-not-set'
|
||||||
);
|
);
|
||||||
|
@@ -47,9 +47,12 @@
|
|||||||
const shouldSuppress =
|
const shouldSuppress =
|
||||||
new URLSearchParams(window.location.search).get('suppressErrorRendering') === 'true';
|
new URLSearchParams(window.location.search).get('suppressErrorRendering') === 'true';
|
||||||
mermaid.initialize({ startOnLoad: false, suppressErrorRendering: shouldSuppress });
|
mermaid.initialize({ startOnLoad: false, suppressErrorRendering: shouldSuppress });
|
||||||
await mermaid.run();
|
try {
|
||||||
if (window.Cypress) {
|
await mermaid.run();
|
||||||
window.rendered = true;
|
} catch {
|
||||||
|
if (window.Cypress) {
|
||||||
|
window.rendered = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user