From 92aac008b81618544052ec3777d12f30690a1dfd Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 11 Oct 2017 15:19:36 +0200 Subject: [PATCH] chore(ci): use latest node for testing This ensures we run against npm v5: * bump wiredeps dependency version * rebuild .wiredeps * internalize test helpers from diagram-js --- .travis.yml | 6 +- .wiredeps | 191 +++++++++++------- test/TestHelper.js | 4 +- test/matchers/BoundsMatchers.js | 166 +++++++++++++++ test/matchers/ConnectionMatchers.js | 124 ++++++++++++ .../features/keyboard/BpmnKeyBindingsSpec.js | 2 +- test/util/KeyEvents.js | 13 ++ 7 files changed, 429 insertions(+), 77 deletions(-) create mode 100644 test/matchers/BoundsMatchers.js create mode 100644 test/matchers/ConnectionMatchers.js create mode 100644 test/util/KeyEvents.js diff --git a/.travis.yml b/.travis.yml index 18b85d90..a5d47327 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js -node_js: '4.0' +node_js: 'node' sudo: false @@ -15,5 +15,5 @@ script: - TEST_BROWSERS=Firefox,PhantomJS npm run all before_install: - - npm install -g grunt-cli wiredeps - - wiredeps --branch=$TRAVIS_BRANCH --tag=$TRAVIS_TAG --verbose + - npm install -g grunt-cli wiredeps@0.2 + - wiredeps --default-branch=master --branch=$TRAVIS_BRANCH --tag=$TRAVIS_TAG --verbose diff --git a/.wiredeps b/.wiredeps index 974eb3bf..a72c0af8 100644 --- a/.wiredeps +++ b/.wiredeps @@ -1,89 +1,138 @@ { "name": "bpmn-js", - "version": "0.13.0", + "version": "0.22.1", + "lockfileVersion": 1, + "requires": true, "dependencies": { - "diagram-js": { - "version": "bpmn-io/diagram-js", - "dependencies": { - "eve": { - "version": "^0.4.2" - }, - "hammerjs": { - "version": "^2.0.1" - }, - "didi": { - "version": "0.1.0" - } - } - }, - "inherits": { - "version": "2.0.1" - }, - "lodash": { - "version": "3.2.0" - }, - "object-refs": { - "version": "0.1.0" - }, - "tiny-svg": { - "version": "bpmn-io/tiny-svg" - }, "bpmn-moddle": { "version": "bpmn-io/bpmn-moddle", - "dependencies": { - "moddle": { - "version": "bpmn-io/moddle" - }, - "moddle-xml": { - "version": "bpmn-io/moddle-xml", - "dependencies": { - "sax": { - "version": "0.6.1" - }, - "tiny-stack": { - "version": "0.1.0" - } - } - } + "requires": { + "lodash": "3.10.1", + "moddle": "1.0.0", + "moddle-xml": "1.0.0" + } + }, + "component-classes": { + "version": "1.2.6", + "requires": { + "component-indexof": "0.0.3" + } + }, + "component-closest": { + "version": "0.1.4", + "requires": { + "component-matches-selector": "0.1.6" + } + }, + "component-delegate": { + "version": "0.2.4", + "requires": { + "component-closest": "0.1.4", + "component-event": "0.1.4" + } + }, + "component-event": { + "version": "0.1.4" + }, + "component-indexof": { + "version": "0.0.3" + }, + "component-matches-selector": { + "version": "0.1.6", + "requires": { + "component-query": "0.0.3" + } + }, + "component-query": { + "version": "0.0.3" + }, + "diagram-js": { + "version": "bpmn-io/diagram-js", + "requires": { + "didi": "0.1.1", + "hammerjs": "2.0.8", + "inherits": "2.0.3", + "lodash": "3.10.1", + "min-dom": "0.2.0", + "object-refs": "0.1.1", + "tiny-svg": "0.1.1" } }, "diagram-js-direct-editing": { - "version": "bpmn-io/diagram-js-direct-editing" + "version": "bpmn-io/diagram-js-direct-editing", + "requires": { + "lodash": "3.10.1", + "min-dom": "0.2.0" + } + }, + "diagram-js-origin": { + "version": "0.15.2", + "requires": { + "tiny-svg": "0.1.1" + } + }, + "didi": { + "version": "0.1.1" + }, + "domify": { + "version": "1.4.0" + }, + "hammerjs": { + "version": "2.0.8" + }, + "hat": { + "version": "0.0.3" }, "ids": { "version": "0.2.0", - "dependencies": { - "hat": { - "version": "0.0.3" - } + "requires": { + "hat": "0.0.3" } }, + "inherits": { + "version": "2.0.3" + }, + "lodash": { + "version": "3.10.1" + }, "min-dom": { "version": "0.2.0", - "dependencies": { - "component-classes": { - "version": "1.2.3" - }, - "component-closest": { - "version": "0.1.4" - }, - - "component-delegate": { - "version": "0.2.3" - }, - "component-event": { - "version": "0.1.4" - }, - "component-matches-selector": { - "version": "0.1.5" - }, - "component-query": { - "version": "0.0.3" - }, - "domify": { - "version": "1.3.1" - } + "requires": { + "component-classes": "1.2.6", + "component-closest": "0.1.4", + "component-delegate": "0.2.4", + "component-event": "0.1.4", + "component-matches-selector": "0.1.6", + "component-query": "0.0.3", + "domify": "1.4.0" } + }, + "moddle": { + "version": "bpmn-io/moddle", + "requires": { + "lodash": "3.10.1" + } + }, + "moddle-xml": { + "version": "bpmn-io/moddle-xml", + "requires": { + "lodash": "3.10.1", + "moddle": "1.0.0", + "sax": "0.6.1", + "tiny-stack": "0.1.0" + } + }, + "object-refs": { + "version": "0.1.1" + }, + "sax": { + "version": "0.6.1" + }, + "tiny-stack": { + "version": "0.1.0" + }, + "tiny-svg": { + "version": "0.1.1" } } -} \ No newline at end of file +} diff --git a/test/TestHelper.js b/test/TestHelper.js index 77e04aca..92841078 100644 --- a/test/TestHelper.js +++ b/test/TestHelper.js @@ -13,6 +13,6 @@ TestHelper.insertCSS('diagram-js-testing.css', // add suite specific matchers global.chai.use(require('chai-match')); -global.chai.use(require('diagram-js/test/matchers/BoundsMatchers')); -global.chai.use(require('diagram-js/test/matchers/ConnectionMatchers')); +global.chai.use(require('./matchers/BoundsMatchers')); +global.chai.use(require('./matchers/ConnectionMatchers')); global.chai.use(require('./matchers/JSONMatcher')); diff --git a/test/matchers/BoundsMatchers.js b/test/matchers/BoundsMatchers.js new file mode 100644 index 00000000..24c6dfd4 --- /dev/null +++ b/test/matchers/BoundsMatchers.js @@ -0,0 +1,166 @@ +'use strict'; + +var pick = require('lodash/object/pick'); + +var BOUNDS_ATTRS = [ 'x', 'y', 'width', 'height' ], + POSITION_ATTRS = [ 'x', 'y' ], + DIMENSION_ATTRS = [ 'width', 'height' ]; + +function getBounds(s) { + + if ('bounds' in s) { + s = s.bounds; + } + + // TLBR object + if ('top' in s) { + return { + x: s.left, + y: s.top, + width: s.right - s.left, + height: s.bottom - s.top + }; + } + + // { x, y, width, height } object + else { + return pick(s, BOUNDS_ATTRS); + } +} + +function getDimensions(s) { + return pick(getBounds(s), DIMENSION_ATTRS); +} + +function getPosition(s) { + return pick(getBounds(s), POSITION_ATTRS); +} + + +module.exports = function(chai, utils) { + + var Assertion = chai.Assertion; + + function inspect(obj) { + return utils.inspect(obj).replace(/\n /g, ''); + } + + + /** + * A simple bounds matcher, that verifies an element + * has the correct { x, y, width, height }. + * + * @example + * + * expect(di.label).to.have.bounds({ x: 100, y: 100, width: 10, height: 20 }); + * expect(shape).to.have.bounds({ top: 100, left: 0, right: 200, bottom: 50 }); + * + * @param {Bounds|TLBR} exp + */ + Assertion.addMethod('bounds', function(exp) { + var obj = this._obj; + + var objectBounds = getBounds(obj), + expectedBounds = getBounds(exp); + + var matches = utils.eql(objectBounds, expectedBounds); + + var objectBoundsStr = inspect(objectBounds), + expectedBoundsStr = inspect(expectedBounds); + + + var theAssert = new Assertion(objectBounds); + + // transfer flags + utils.transferFlags(this, theAssert, false); + + theAssert.assert( + matches, + 'expected <' + (obj.id ? '#' + obj.id : obj) + '> bounds ' + + 'to equal \n ' + expectedBoundsStr + + '\nbut got\n ' + objectBoundsStr, + 'expected <' + (obj.id ? '#' + obj.id : obj) + '> bounds ' + + 'not to equal \n ' + expectedBoundsStr + ); + }); + + /** + * A simple dimensions matcher, that verifies an element + * has the correct { width, height }. + * + * Unwraps `element.bounds` (BPMNDI) if present. + * + * @example + * + * expect(di.label).to.have.dimensions({ width: 10, height: 20 }); + * + * @param {Dimensions} exp + */ + Assertion.addMethod('dimensions', function(exp) { + var obj = this._obj; + + var objectDimensions = getDimensions(obj), + expectedDimensions = getDimensions(exp); + + var matches = utils.eql(objectDimensions, expectedDimensions); + + var objectDimensionsStr = inspect(objectDimensions), + expectedDimensionsStr = inspect(expectedDimensions); + + + var theAssert = new Assertion(objectDimensions); + + // transfer flags + utils.transferFlags(this, theAssert, false); + + theAssert.assert( + matches, + 'expected <' + (obj.id ? '#' + obj.id : obj) + '> dimensions ' + + 'to equal \n ' + expectedDimensionsStr + + '\nbut got\n ' + objectDimensionsStr, + 'expected <' + (obj.id ? '#' + obj.id : obj) + '> dimensions ' + + 'not to equal \n ' + expectedDimensionsStr + ); + }); + + + /** + * A simple position matcher, that verifies an element + * has the correct { x, y }. + * + * Unwraps `element.bounds` (BPMNDI) if present. + * + * @example + * + * expect(taskShape).to.have.position({ x: 100, y: 150 }); + * + * @param {Point} exp + */ + Assertion.addMethod('position', function(exp) { + var obj = this._obj; + + var objectPosition = getPosition(obj), + expectedPosition = getPosition(exp); + + var matches = utils.eql(objectPosition, expectedPosition); + + var objectPositionStr = inspect(objectPosition), + expectedPositionStr = inspect(expectedPosition); + + + var theAssert = new Assertion(objectPosition); + + // transfer flags + utils.transferFlags(this, theAssert, false); + + theAssert.assert( + matches, + 'expected <' + (obj.id ? '#' + obj.id : obj) + '> position ' + + 'to equal \n ' + expectedPositionStr + + '\nbut got\n ' + objectPositionStr, + 'expected <' + (obj.id ? '#' + obj.id : obj) + '> position ' + + 'not to equal \n ' + expectedPositionStr + ); + }); + +}; diff --git a/test/matchers/ConnectionMatchers.js b/test/matchers/ConnectionMatchers.js new file mode 100644 index 00000000..89c8f20c --- /dev/null +++ b/test/matchers/ConnectionMatchers.js @@ -0,0 +1,124 @@ +'use strict'; + +var pick = require('lodash/object/pick'); + +var POSITION_ATTRS = [ 'x', 'y' ]; + +function extractPoints(point) { + return pick(point, POSITION_ATTRS); +} + + +module.exports = function(chai, utils) { + + var Assertion = chai.Assertion; + + function inspect(obj) { + return utils.inspect(obj).replace(/\n /g, ''); + } + + /** + * A simple waypoints matcher, that verifies a connection + * consists of the correct connection points. + * + * Does not take the original docking into account. + * + * @example + * + * expect(connection).to.have.waypoints([ { x: 100, y: 100 }, { x: 0, y: 0 } ]); + * + * @param {Connection|Array} exp + */ + Assertion.addMethod('waypoints', function(exp) { + var obj = this._obj; + + var strippedWaypoints = obj.waypoints.map(extractPoints), + strippedExpectedWaypoints = exp.map(extractPoints); + + var matches = utils.eql(strippedWaypoints, strippedExpectedWaypoints); + + var strippedWaypointsStr = inspect(strippedWaypoints), + strippedExpectedWaypointsStr = inspect(strippedExpectedWaypoints); + + var theAssert = new Assertion(strippedWaypoints); + + // transfer negate status + utils.transferFlags(this, theAssert, false); + + theAssert.assert( + matches, + 'expected <' + obj.id + '#waypoints> ' + + 'to equal \n ' + strippedExpectedWaypointsStr + + '\nbut got\n ' + strippedWaypointsStr, + 'expected <' + obj.id + '#waypoints> ' + + 'not to equal \n ' + strippedExpectedWaypoints + ); + }); + + /** + * A simple waypoints matcher, that verifies a connection + * has the given start docking. + * + * @example + * + * expect(connection).to.have.startDocking({ x: 100, y: 100 }); + * + * @param {Point} exp + */ + Assertion.addMethod('startDocking', function(exp) { + var obj = this._obj; + + var startPoint = obj.waypoints[0], + startDocking = startPoint && startPoint.original; + + var matches = utils.eql(startDocking, exp); + + var startDockingStr = inspect(startDocking), + expectedStartDockingStr = inspect(exp); + + var theAssert = new Assertion(startDocking); + + // transfer negate status + utils.transferFlags(this, theAssert, false); + + theAssert.assert( + matches, + 'expected <' + obj.id + '> to have startDocking ' + + expectedStartDockingStr + ' but got ' + startDockingStr + ); + }); + + /** + * A simple waypoints matcher, that verifies a connection + * has the given start docking. + * + * @example + * + * expect(connection).to.have.endDocking({ x: 100, y: 100 }); + * + * @param {Point} exp + */ + Assertion.addMethod('endDocking', function(exp) { + var obj = this._obj; + + var endPoint = obj.waypoints[obj.waypoints.length - 1], + endDocking = endPoint && endPoint.original; + + var matches = utils.eql(endDocking, exp); + + var endDockingStr = inspect(endDocking), + expectedEndDockingStr = inspect(exp); + + var theAssert = new Assertion(endDocking); + + // transfer negate status + utils.transferFlags(this, theAssert, false); + + theAssert.assert( + matches, + 'expected <' + obj.id + '> to have endDocking ' + + expectedEndDockingStr + ' but got ' + endDockingStr + ); + }); + +}; diff --git a/test/spec/features/keyboard/BpmnKeyBindingsSpec.js b/test/spec/features/keyboard/BpmnKeyBindingsSpec.js index c2e92270..89cd34b4 100644 --- a/test/spec/features/keyboard/BpmnKeyBindingsSpec.js +++ b/test/spec/features/keyboard/BpmnKeyBindingsSpec.js @@ -7,7 +7,7 @@ var coreModule = require('../../../../lib/core'), keyboardModule = require('../../../../lib/features/keyboard'), modelingModule = require('../../../../lib/features/modeling'); -var createKeyEvent = require('diagram-js/test/util/KeyEvents').createKeyEvent; +var createKeyEvent = require('../../../util/KeyEvents').createKeyEvent; /* global bootstrapViewer, inject, sinon */ diff --git a/test/util/KeyEvents.js b/test/util/KeyEvents.js new file mode 100644 index 00000000..7bac39d6 --- /dev/null +++ b/test/util/KeyEvents.js @@ -0,0 +1,13 @@ +'use strict'; + +function createKeyEvent(element, code, ctrlKey) { + var e = document.createEvent('Events') || new document.defaultView.CustomEvent('keyEvent'); + + e.keyCode = code; + e.which = code; + e.ctrlKey = ctrlKey; + + return e; +} + +module.exports.createKeyEvent = createKeyEvent;