chore(tests): use jasmine-test-container-support for test execution

This allows us to have tests nice and easily rendered within test-local
containers, including captions, status highlighting and links.
This commit is contained in:
Nico Rehwaldt 2014-06-18 11:45:30 +02:00
parent 84510cc45d
commit dc3fca67b1
11 changed files with 131 additions and 325 deletions

View File

@ -40,6 +40,7 @@
"grunt-jsdoc": "~0.5.1",
"grunt-karma": "~0.8.0",
"grunt-release": "~0.7.0",
"jasmine-test-container-support": "0.0.1",
"jsondiffpatch": "^0.1.7",
"karma": "^0.12.12",
"karma-bro": "~0.2.0",

View File

@ -3,6 +3,10 @@
var _ = require('lodash');
var BpmnJS = require('../../');
// enhance jasmine with test container API
require('jasmine-test-container-support').extend(jasmine);
var OPTIONS, BPMN_JS;
function options(opts) {
@ -40,11 +44,13 @@ function bootstrapBpmnJS(diagram, options, locals) {
return function(done) {
var testContainer = jasmine.getEnv().getTestContainer();
var _diagram = diagram,
_options = options,
_locals = locals;
if (!_locals && _.isFunction(_options)) {
if (_locals === undefined && _.isFunction(_options)) {
_locals = _options;
_options = null;
}
@ -57,15 +63,23 @@ function bootstrapBpmnJS(diagram, options, locals) {
_locals = _locals();
}
_options = _.extend({}, OPTIONS || {}, _options || {});
_options = _.extend({ container: testContainer }, OPTIONS || {}, _options || {});
var mockModule = {};
if (_locals) {
var mockModule = {};
_.forEach(_locals, function(v, k) {
mockModule[k] = ['value', v];
});
_.forEach(_locals, function(v, k) {
mockModule[k] = ['value', v];
});
_options.modules = _.unique([].concat(_options.modules || [], [ mockModule ]));
_options.modules = [].concat(_options.modules || [], [ mockModule ]);
}
_options.modules = _.unique(_options.modules);
if (_options.modules.length == 0) {
_options.modules = undefined;
}
BPMN_JS = new BpmnJS(_options);

View File

@ -1,19 +1,25 @@
'use strict';
var Matchers = require('../Matchers'),
TestHelper = require('../TestHelper');
/* global bootstrapBpmnJS, inject */
var fs = require('fs');
var Modeler = require('../../../lib/Modeler');
var Matchers = require('../Matchers');
describe('Modeler', function() {
describe('modeler', function() {
beforeEach(Matchers.add);
var container;
beforeEach(function() {
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
container = jasmine.getEnv().getTestContainer();
});
@ -25,6 +31,7 @@ describe('Modeler', function() {
});
}
it('should import simple process', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
createModeler(xml, done);
@ -41,7 +48,7 @@ describe('Modeler', function() {
var xml = 'invalid stuff';
var renderer = new Modeler(container);
var renderer = new Modeler({ container: container });
renderer.importXML(xml, function(err) {
@ -56,8 +63,6 @@ describe('Modeler', function() {
it('should be available via di as <bpmnjs>', function(done) {
debugger;
var xml = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');
createModeler(xml, function(err, modeler) {

View File

@ -1,23 +1,28 @@
'use strict';
var Matchers = require('../Matchers'),
TestHelper = require('../TestHelper');
/* global bootstrapBpmnJS, inject */
var fs = require('fs');
var Viewer = require('../../../lib/Viewer');
var Matchers = require('../Matchers');
describe('Viewer', function() {
describe('viewer', function() {
beforeEach(Matchers.add);
var container;
beforeEach(function() {
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
container = jasmine.getEnv().getTestContainer();
});
function createViewer(xml, done) {
var renderer = new Viewer({ container: container });

View File

@ -1,249 +1,130 @@
'use strict';
var Matchers = require('../../Matchers'),
TestHelper = require('../../TestHelper');
/* global bootstrapBpmnJS, inject */
var fs = require('fs');
var Viewer = require('../../../../lib/Viewer');
var Matchers = require('../../Matchers');
describe('draw/BpmnRenderer', function() {
describe('draw - bpmn renderer', function() {
beforeEach(Matchers.add);
var container;
beforeEach(function() {
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
});
it('should render activity markers', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/activity-markers.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render activity markers (combination)', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/activity-markers-combination.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render conditional flows', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/conditional-flow.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render conditional default flows', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/conditional-flow-default.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render NO conditional flow (gateway)', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/conditional-flow-gateways.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render conditional flow (typed task)', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/conditional-flow-typed-task.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render data objects', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/data-objects.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render events', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/events.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render events (interrupting)', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/events-interrupting.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render event subprocesses (collapsed)', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/event-subprocesses-collapsed.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render event subprocesses (expanded)', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/event-subprocesses-expanded.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render gateways', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/gateways.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render group', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/group.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render message marker', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/message-marker.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render pools', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/pools.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render pool collection marker', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/pools-with-collection-marker.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render task types', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/task-types.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render text annotations', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/draw/text-annotation.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('should render flow markers', function(done) {
var xml = fs.readFileSync(__dirname + '/../../../fixtures/bpmn/flow-markers.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
});

View File

@ -9,7 +9,7 @@ var fs = require('fs');
var Events = require('diagram-js/lib/core/EventBus');
describe('environment/Mocking', function() {
describe('environment - mocking', function() {
var diagramXML = fs.readFileSync('test/fixtures/bpmn/simple.bpmn', 'utf8');

View File

@ -1,15 +1,15 @@
'use strict';
var TestHelper = require('../../../TestHelper');
var Matchers = require('../../../Matchers'),
TestHelper = require('../../../TestHelper');
/* global bootstrapBpmnJS, inject */
var fs = require('fs');
var $ = require('jquery');
var Matchers = require('../../../Matchers');
var labelEditingModule = require('../../../../../lib/features/label-editing');
@ -17,24 +17,16 @@ var labelEditingModule = require('../../../../../lib/features/label-editing');
var LabelUtil = require('../../../../../lib/features/label-editing/LabelUtil');
describe('features/label-editing', function() {
describe('features - label-editing', function() {
beforeEach(Matchers.add);
var container;
beforeEach(function() {
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
});
var diagramXML = fs.readFileSync('test/fixtures/bpmn/features/label-editing/labels.bpmn', 'utf-8');
var testModules = [ labelEditingModule ];
beforeEach(bootstrapBpmnJS(diagramXML, { container: container, modules: testModules }));
beforeEach(bootstrapBpmnJS(diagramXML, { modules: testModules }));
describe('basics', function() {

View File

@ -1,5 +1,11 @@
'use strict';
var Matchers = require('../../Matchers'),
TestHelper = require('../../TestHelper');
/* global bootstrapBpmnJS, inject */
var fs = require('fs');
var Diagram = require('diagram-js/lib/Diagram'),
@ -8,10 +14,7 @@ var Diagram = require('diagram-js/lib/Diagram'),
Viewer = require('../../../../lib/Viewer');
var Matchers = require('../../Matchers');
describe('import/Importer', function() {
describe('import - importer', function() {
var bpmnModel = BpmnModel.instance();
@ -19,14 +22,13 @@ describe('import/Importer', function() {
return BpmnModel.fromXML(xml, 'bpmn:Definitions', opts, callback);
}
var container;
beforeEach(Matchers.add);
var container;
beforeEach(function() {
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
container = jasmine.getEnv().getTestContainer();
});

View File

@ -1,94 +1,54 @@
'use strict';
var Matchers = require('../../../Matchers'),
TestHelper = require('../../../TestHelper');
/* global bootstrapBpmnJS, inject */
var fs = require('fs');
var Viewer = require('../../../../../lib/Viewer');
var Matchers = require('../../../Matchers');
describe('import - collapsed container', function() {
beforeEach(Matchers.add);
var loadedXml;
var container, renderer;
function ensureLoaded(xml, done) {
if (xml !== loadedXml) {
// create container
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
if (err) {
done(err);
} else {
loadedXml = xml;
done();
}
});
} else {
done();
}
}
describe('in process', function() {
var diagramXML = fs.readFileSync('test/fixtures/bpmn/import/collapsed.bpmn', 'utf8');
beforeEach(function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/collapsed.bpmn', 'utf8');
ensureLoaded(xml, done);
});
beforeEach(bootstrapBpmnJS(diagramXML));
it('should import collapsed subProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import collapsed subProcess', inject(function(elementRegistry) {
var collapsedShape = elementRegistry.getById('SubProcess_1');
var childShape = elementRegistry.getById('IntermediateCatchEvent_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
}));
it('should import collapsed transaction', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import collapsed transaction', inject(function(elementRegistry) {
var collapsedShape = elementRegistry.getById('Transaction_1');
var childShape = elementRegistry.getById('UserTask_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
}));
it('should import collapsed adhocSubProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import collapsed adhocSubProcess', inject(function(elementRegistry) {
var collapsedShape = elementRegistry.getById('AdHocSubProcess_1');
var childShape = elementRegistry.getById('StartEvent_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
}));
it('should import collapsed with nested elements', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import collapsed with nested elements', inject(function(elementRegistry) {
var collapsedShape = elementRegistry.getById('SubProcess_4');
var childShape = elementRegistry.getById('SubProcess_5');
var nestedChildShape = elementRegistry.getById('Task_3');
@ -96,89 +56,70 @@ describe('import - collapsed container', function() {
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
expect(nestedChildShape.hidden).toBe(true);
});
}));
it('should import collapsed with nested elements', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import collapsed with nested elements', inject(function(elementRegistry) {
var hiddenEventShape = elementRegistry.getById('StartEvent_2');
expect(hiddenEventShape.label.hidden).toBe(true);
var hiddenDataShape = elementRegistry.getById('DataObjectReference_1');
expect(hiddenDataShape.label.hidden).toBe(true);
});
}));
it('should import expanded subProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import expanded subProcess', inject(function(elementRegistry) {
var expandedShape = elementRegistry.getById('SubProcess_3');
var childShape = elementRegistry.getById('Task_2');
expect(expandedShape.collapsed).toBe(false);
expect(childShape.hidden).toBe(false);
});
}));
});
describe('in collaboration', function() {
beforeEach(function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/collapsed-collaboration.bpmn', 'utf8');
ensureLoaded(xml, done);
});
var diagramXML = fs.readFileSync('test/fixtures/bpmn/import/collapsed-collaboration.bpmn', 'utf8');
beforeEach(bootstrapBpmnJS(diagramXML));
it('should import collapsed subProcess in pool', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import collapsed subProcess in pool', inject(function(elementRegistry) {
var expandedShape = elementRegistry.getById('SubProcess_1');
var childShape = elementRegistry.getById('Task_1');
expect(expandedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
}));
it('should import expanded subProcess in pool', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import expanded subProcess in pool', inject(function(elementRegistry) {
var expandedShape = elementRegistry.getById('SubProcess_2');
var childShape = elementRegistry.getById('StartEvent_1');
expect(expandedShape.collapsed).toBe(false);
expect(childShape.hidden).toBe(false);
});
}));
it('should import collapsed subProcess in lane', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import collapsed subProcess in lane', inject(function(elementRegistry) {
var expandedShape = elementRegistry.getById('SubProcess_4');
var childShape = elementRegistry.getById('Task_2');
expect(expandedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
}));
it('should import expanded subProcess in lane', function() {
var elementRegistry = renderer.get('elementRegistry');
it('should import expanded subProcess in lane', inject(function(elementRegistry) {
var expandedShape = elementRegistry.getById('SubProcess_3');
var childShape = elementRegistry.getById('StartEvent_2');
expect(expandedShape.collapsed).toBe(false);
expect(childShape.hidden).toBe(false);
});
}));
});
});

View File

@ -1,59 +1,36 @@
'use strict';
var Matchers = require('../../../Matchers'),
TestHelper = require('../../../TestHelper');
/* global bootstrapBpmnJS, inject */
var fs = require('fs');
var Viewer = require('../../../../../lib/Viewer');
var Matchers = require('../../../Matchers');
describe('import - labels', function() {
beforeEach(Matchers.add);
var container;
beforeEach(function() {
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
});
describe('should import embedded labels', function() {
it('on flow nodes', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/labels/embedded.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('on pools and lanes', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/labels/collaboration.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('on message flows', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/labels/collaboration-message-flows.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
});
@ -62,26 +39,14 @@ describe('import - labels', function() {
describe('should import external labels', function() {
it('with di', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/labels/external.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
it('without di', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/labels/external-no-di.bpmn', 'utf8');
var renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
done(err);
});
bootstrapBpmnJS(xml)(done);
});
});

View File

@ -1,6 +1,6 @@
var BpmnModel = require('bpmn-moddle');
describe('Model - browser support', function() {
describe('model - browser support', function() {
function read(xml, callback, done) {