fix(BaseViewer): always emit saveXML.done
This ensures we emit saveXML.done on error, too.
This commit is contained in:
parent
39f1cbe92c
commit
3567565514
|
@ -358,12 +358,12 @@ BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options) {
|
|||
|
||||
var definitions = this._definitions;
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise(function(resolve) {
|
||||
|
||||
if (!definitions) {
|
||||
var err = new Error('no definitions loaded');
|
||||
|
||||
return reject(err);
|
||||
return resolve({
|
||||
error: new Error('no definitions loaded')
|
||||
});
|
||||
}
|
||||
|
||||
// allow to fiddle around with definitions
|
||||
|
@ -375,25 +375,27 @@ BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options) {
|
|||
|
||||
var xml = result.xml;
|
||||
|
||||
try {
|
||||
xml = self._emit('saveXML.serialized', {
|
||||
error: null,
|
||||
xml: xml
|
||||
}) || xml;
|
||||
xml = self._emit('saveXML.serialized', {
|
||||
xml: xml
|
||||
}) || xml;
|
||||
|
||||
self._emit('saveXML.done', {
|
||||
error: null,
|
||||
xml: xml
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('error in saveXML life-cycle listener', e);
|
||||
}
|
||||
|
||||
return resolve({ xml: xml });
|
||||
}).catch(function(err) {
|
||||
|
||||
return reject(err);
|
||||
return resolve({
|
||||
xml: xml
|
||||
});
|
||||
});
|
||||
}).catch(function(error) {
|
||||
return { error: error };
|
||||
}).then(function(result) {
|
||||
|
||||
self._emit('saveXML.done', result);
|
||||
|
||||
var error = result.error;
|
||||
|
||||
if (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
return result;
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1242,12 +1242,66 @@ describe('Viewer', function() {
|
|||
// then
|
||||
expect(events).to.eql([
|
||||
[ 'saveXML.start', [ 'definitions' ] ],
|
||||
[ 'saveXML.serialized', ['error', 'xml' ] ],
|
||||
[ 'saveXML.done', ['error', 'xml' ] ]
|
||||
[ 'saveXML.serialized', [ 'xml' ] ],
|
||||
[ 'saveXML.done', [ 'xml' ] ]
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should emit <saveXML.done> on error', function() {
|
||||
|
||||
var xml = require('../fixtures/bpmn/simple.bpmn');
|
||||
|
||||
var viewer;
|
||||
var events = [];
|
||||
|
||||
return createViewer(container, Viewer, xml).then(function(result) {
|
||||
|
||||
var err = result.error;
|
||||
viewer = result.viewer;
|
||||
|
||||
expect(err).not.to.exist;
|
||||
|
||||
// when
|
||||
viewer.on('saveXML.start', 250, function() {
|
||||
throw new Error('failing pre-save listener');
|
||||
});
|
||||
|
||||
viewer.on([
|
||||
'saveXML.start',
|
||||
'saveXML.serialized',
|
||||
'saveXML.done'
|
||||
], function(e) {
|
||||
|
||||
// log event type + event arguments
|
||||
events.push([
|
||||
e.type,
|
||||
Object.keys(e).filter(function(key) {
|
||||
return key !== 'type';
|
||||
})
|
||||
]);
|
||||
});
|
||||
|
||||
return viewer.importXML(xml);
|
||||
}).then(function(result) {
|
||||
|
||||
// when
|
||||
return viewer.saveXML();
|
||||
}).catch(function(error) {
|
||||
events.push([ 'error' ]);
|
||||
}).finally(function() {
|
||||
|
||||
// then
|
||||
expect(events).to.eql([
|
||||
[ 'saveXML.start', [ 'definitions' ] ],
|
||||
[ 'saveXML.done', [ 'error' ] ],
|
||||
[ 'error' ]
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
@ -2170,8 +2224,8 @@ describe('Viewer', function() {
|
|||
// then
|
||||
expect(events).to.eql([
|
||||
[ 'saveXML.start', [ 'definitions' ] ],
|
||||
[ 'saveXML.serialized', ['error', 'xml' ] ],
|
||||
[ 'saveXML.done', ['error', 'xml' ] ]
|
||||
[ 'saveXML.serialized', [ 'xml' ] ],
|
||||
[ 'saveXML.done', [ 'xml' ] ]
|
||||
]);
|
||||
|
||||
done();
|
||||
|
|
Loading…
Reference in New Issue