Skip to content

Commit

Permalink
fix runner for tests, limit precision of refs
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Aug 4, 2015
1 parent a6b82c1 commit 352bfd6
Show file tree
Hide file tree
Showing 80 changed files with 142,135 additions and 142,117 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ matter-doc-theme
build/matter-dev.js
build/matter-dev.min.js
demo/js/lib/matter-dev.js
tests/browser/diffs
test/browser/diffs
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.idea
node_modules
npm-debug.log
doc
matter-doc-theme
build/matter-dev.js
build/matter-dev.min.js
demo/js/lib/matter-dev.js
demo/js/lib/matter-dev.js
test/browser/diffs
12 changes: 8 additions & 4 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
_mouseConstraint,
_sceneEvents = [],
_useInspector = window.location.hash.indexOf('-inspect') !== -1,
_isMobile = /(ipad|iphone|ipod|android)/gi.test(navigator.userAgent);
_isMobile = /(ipad|iphone|ipod|android)/gi.test(navigator.userAgent),
_isAutomatedTest = window._phantom ? true : false;

// initialise the demo

Expand All @@ -57,6 +58,12 @@
_mouseConstraint = MouseConstraint.create(_engine);
World.add(_engine.world, _mouseConstraint);

// engine reference for external use
Matter.Demo._engine = _engine;

// skip runner when performing automated tests
if (_isAutomatedTest) return;

// run the engine
Engine.run(_engine);

Expand Down Expand Up @@ -1609,9 +1616,6 @@
var demoSelect = document.getElementById('demo-select'),
demoReset = document.getElementById('demo-reset');

// engine reference for external use
Matter.Demo._engine = _engine;

// create a Matter.Gui
if (!_isMobile && Gui) {
_gui = Gui.create(_engine);
Expand Down
21 changes: 14 additions & 7 deletions test/browser/TestDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var test = function(status) {

var worldStart = page.evaluate(function(demo) {
var engine = Matter.Demo._engine;
Matter.Runner.stop(engine);
if (!(demo in Matter.Demo)) {
throw '\'' + demo + '\' is not defined in Matter.Demo';
}
Expand All @@ -78,19 +77,19 @@ var test = function(status) {

if (worldStartDiff.length !== 0) {
if (diff) {
fs.write(worldStartDiffPath, JSON.stringify(worldStartDiff, null, 2), 'w');
fs.write(worldStartDiffPath, JSON.stringify(worldStartDiff, precisionLimiter, 2), 'w');
}

if (forceUpdate) {
hasCreated = true;
fs.write(worldStartPath, resurrect.stringify(worldStart, null, 2), 'w');
fs.write(worldStartPath, resurrect.stringify(worldStart, precisionLimiter, 2), 'w');
} else {
hasChanged = true;
}
}
} else {
hasCreated = true;
fs.write(worldStartPath, resurrect.stringify(worldStart, null, 2), 'w');
fs.write(worldStartPath, resurrect.stringify(worldStart, precisionLimiter, 2), 'w');
}

if (fs.exists(worldEndPath)) {
Expand All @@ -99,19 +98,19 @@ var test = function(status) {

if (worldEndDiff.length !== 0) {
if (diff) {
fs.write(worldEndDiffPath, JSON.stringify(worldEndDiff, null, 2), 'w');
fs.write(worldEndDiffPath, JSON.stringify(worldEndDiff, precisionLimiter, 2), 'w');
}

if (forceUpdate) {
hasCreated = true;
fs.write(worldEndPath, resurrect.stringify(worldEnd, null, 2), 'w');
fs.write(worldEndPath, resurrect.stringify(worldEnd, precisionLimiter, 2), 'w');
} else {
hasChanged = true;
}
}
} else {
hasCreated = true;
fs.write(worldEndPath, resurrect.stringify(worldEnd, null, 2), 'w');
fs.write(worldEndPath, resurrect.stringify(worldEnd, precisionLimiter, 2), 'w');
}

if (hasChanged) {
Expand Down Expand Up @@ -145,6 +144,14 @@ var test = function(status) {
phantom.exit(!isOk);
};

var precisionLimiter = function(key, value) {
// limit precision of floats
if (typeof value === 'number') {
return parseFloat(value.toFixed(5));
}
return value;
};

function arg(name) {
var index = system.args.indexOf(name);
if (index >= 0) {
Expand Down
12 changes: 6 additions & 6 deletions test/browser/refs/airFriction/airFriction-0.json
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@
"frictionStatic": 0.5,
"id": 4,
"inertia": 8640,
"inverseInertia": 0.00011574074074074075,
"inverseMass": 0.2777777777777778,
"inverseInertia": 0.00012,
"inverseMass": 0.27778,
"isSleeping": false,
"isStatic": false,
"label": "Rectangle Body",
Expand Down Expand Up @@ -1034,8 +1034,8 @@
"frictionStatic": 0.5,
"id": 5,
"inertia": 8640,
"inverseInertia": 0.00011574074074074075,
"inverseMass": 0.2777777777777778,
"inverseInertia": 0.00012,
"inverseMass": 0.27778,
"isSleeping": false,
"isStatic": false,
"label": "Rectangle Body",
Expand Down Expand Up @@ -1214,8 +1214,8 @@
"frictionStatic": 0.5,
"id": 6,
"inertia": 8640,
"inverseInertia": 0.00011574074074074075,
"inverseMass": 0.2777777777777778,
"inverseInertia": 0.00012,
"inverseMass": 0.27778,
"isSleeping": false,
"isStatic": false,
"label": "Rectangle Body",
Expand Down
Loading

0 comments on commit 352bfd6

Please sign in to comment.