mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-11 09:36:07 +00:00
fix(Viewer): freakin fix SVG export performance
From /.*<svg[^>]*>|<\/svg>.*$/g to /^.*<svg[^>]*>|<\/svg>.*$/g, spot the difference.
This commit is contained in:
parent
f5a6e3d768
commit
4f6d57accf
@ -12,7 +12,7 @@ function getSvgContents(diagram) {
|
||||
var outerNode = diagram.get('canvas').getContainer();
|
||||
|
||||
var svg = outerNode.innerHTML;
|
||||
return svg.replace(/.*<svg[^>]*>|<\/svg>.*$/g, '')
|
||||
return svg.replace(/^.*<svg[^>]*>|<\/svg>.*$/g, '')
|
||||
.replace('<desc>Created with Snap</desc>', '')
|
||||
.replace(/<g class="viewport"( transform="[^"]*")?/, '<g');
|
||||
}
|
||||
|
@ -192,6 +192,29 @@ describe('viewer', function() {
|
||||
|
||||
describe('export', function() {
|
||||
|
||||
function currentTime() {
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
function isValid(svg) {
|
||||
var expectedStart = '<?xml version="1.0" encoding="utf-8"?>';
|
||||
var expectedEnd = '</svg>';
|
||||
|
||||
expect(svg.indexOf(expectedStart)).toEqual(0);
|
||||
expect(svg.indexOf(expectedEnd)).toEqual(svg.length - expectedEnd.length);
|
||||
|
||||
// ensure correct rendering of SVG contents
|
||||
expect(svg.indexOf('undefined')).toBe(-1);
|
||||
|
||||
// expect header to be written only once
|
||||
expect(svg.indexOf('<svg width="100%" height="100%">')).toBe(-1);
|
||||
expect(svg.indexOf('<g class="viewport"')).toBe(-1);
|
||||
|
||||
// FIXME(nre): make matcher
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
it('should export svg', function(done) {
|
||||
|
||||
// given
|
||||
@ -210,19 +233,40 @@ describe('viewer', function() {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
var expectedStart = '<?xml version="1.0" encoding="utf-8"?>';
|
||||
var expectedEnd = '</svg>';
|
||||
// then
|
||||
expect(isValid(svg)).toBe(true);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should export complex svg', function(done) {
|
||||
|
||||
// given
|
||||
var xml = fs.readFileSync('test/fixtures/bpmn/complex.bpmn', 'utf8');
|
||||
|
||||
createViewer(xml, function(err, viewer) {
|
||||
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
var time = currentTime();
|
||||
|
||||
// when
|
||||
viewer.saveSVG(function(err, svg) {
|
||||
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// then
|
||||
expect(svg.indexOf(expectedStart)).toEqual(0);
|
||||
expect(svg.indexOf(expectedEnd)).toEqual(svg.length - expectedEnd.length);
|
||||
expect(isValid(svg)).toBe(true);
|
||||
|
||||
// ensure correct rendering of SVG contents
|
||||
expect(svg.indexOf('undefined')).toBe(-1);
|
||||
|
||||
// expect header to be written only once
|
||||
expect(svg.indexOf('<svg width="100%" height="100%">')).toBe(-1);
|
||||
expect(svg.indexOf('<g class="viewport"')).toBe(-1);
|
||||
// no svg export should take more than 500ms
|
||||
expect(currentTime() - time).toBeLessThan(500);
|
||||
|
||||
done();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user