Skip to content

Commit

Permalink
test: remove random factor in simulation tests
Browse files Browse the repository at this point in the history
It would otherwise be possible to make the execution order non-determininistic.
  • Loading branch information
nikku authored and barmac committed Dec 1, 2023
1 parent 1af8135 commit 20fabdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 10 additions & 6 deletions lib/animation/Animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 15 additions & 1 deletion test/spec/SimulationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ModelerModule from 'lib/modeler';
import SimulationSupportModule from 'lib/simulation-support';

import {
bootstrapModeler,
bootstrapModeler as _bootstrapModeler,
inject,
getBpmnJS,
withBpmnJs
Expand All @@ -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() {

Expand Down

0 comments on commit 20fabdf

Please sign in to comment.