From 20fabdffca84385372b1e23efa6c15b922e42812 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Thu, 30 Nov 2023 17:33:59 +0100 Subject: [PATCH] test: remove random factor in simulation tests It would otherwise be possible to make the execution order non-determininistic. --- lib/animation/Animation.js | 16 ++++++++++------ test/spec/SimulationSpec.js | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/animation/Animation.js b/lib/animation/Animation.js index dc57b403..cf7d2db1 100644 --- a/lib/animation/Animation.js +++ b/lib/animation/Animation.js @@ -62,11 +62,13 @@ const EASE_IN_OUT = function(pos) { const TOKEN_SIZE = 20; -export default function Animation(canvas, eventBus, scopeFilter) { +export default function Animation(config, canvas, eventBus, scopeFilter) { this._eventBus = eventBus; this._scopeFilter = scopeFilter; this._canvas = canvas; + this._randomize = config && config.randomize !== false; + this._animations = new Set(); this._speed = 1; @@ -127,7 +129,7 @@ Animation.prototype.createAnimation = function(connection, scope, done = noop) { const tokenGfx = this._createTokenGfx(group, scope); - const animation = new TokenAnimation(tokenGfx, connection.waypoints, () => { + const animation = new TokenAnimation(tokenGfx, connection.waypoints, this._randomize, () => { this._animations.delete(animation); done(); @@ -237,16 +239,18 @@ Animation.prototype._getGroup = function(scope) { }; Animation.$inject = [ + 'config.animation', 'canvas', 'eventBus', 'scopeFilter' ]; -function TokenAnimation(gfx, waypoints, done) { +function TokenAnimation(gfx, waypoints, randomize, done) { this.gfx = gfx; this.waypoints = waypoints; this.done = done; + this.randomize = randomize; this._paused = true; this._t = 0; @@ -362,7 +366,7 @@ TokenAnimation.prototype.create = function() { return d; }, []).flat().join(' '); - const totalDuration = getAnimationDuration(totalLength); + const totalDuration = getAnimationDuration(totalLength, this._randomize); this._parts = parts.reduce((parts, part, index) => { const duration = totalDuration / totalLength * part.length; @@ -404,8 +408,8 @@ TokenAnimation.prototype.setSpeed = function(speed) { this._speed = speed; }; -function getAnimationDuration(length) { - return Math.log(length) * randomBetween(250, 300); +function getAnimationDuration(length, randomize = false) { + return Math.log(length) * (randomize ? randomBetween(250, 300) : 250); } function randomBetween(min, max) { diff --git a/test/spec/SimulationSpec.js b/test/spec/SimulationSpec.js index 85473d92..4eebd663 100644 --- a/test/spec/SimulationSpec.js +++ b/test/spec/SimulationSpec.js @@ -3,7 +3,7 @@ import ModelerModule from 'lib/modeler'; import SimulationSupportModule from 'lib/simulation-support'; import { - bootstrapModeler, + bootstrapModeler as _bootstrapModeler, inject, getBpmnJS, withBpmnJs @@ -21,6 +21,20 @@ const TestModule = { ] }; +function bootstrapModeler(diagram, config) { + const { + animation = {}, + ...restConfig + } = config; + + return _bootstrapModeler(diagram, { + ...restConfig, + animation: { + randomize: false, + ...animation + } + }); +} describe('simulation', function() {