mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-17 12:42:17 -05:00
72 lines
No EOL
2.3 KiB
JavaScript
72 lines
No EOL
2.3 KiB
JavaScript
/* eslint-env es6 */
|
|
"use strict";
|
|
|
|
jest.setTimeout(30 * 1000);
|
|
|
|
const { comparisonReport, toMatchExtrinsics, toMatchIntrinsics } = require('./TestTools');
|
|
|
|
const Example = require('../examples/index');
|
|
const MatterBuild = require('../build/matter');
|
|
const Worker = require('jest-worker').default;
|
|
|
|
const testComparison = process.env.COMPARE === 'true';
|
|
const saveComparison = process.env.SAVE === 'true';
|
|
const excludeExamples = [ 'svg', 'terrain' ];
|
|
const examples = Object.keys(Example).filter(key => !excludeExamples.includes(key));
|
|
|
|
const runExamples = async useDev => {
|
|
const worker = new Worker(require.resolve('./ExampleWorker'), {
|
|
enableWorkerThreads: true
|
|
});
|
|
|
|
const result = await Promise.all(examples.map(name => worker.runExample({
|
|
name,
|
|
useDev,
|
|
totalUpdates: 120
|
|
})));
|
|
|
|
await worker.end();
|
|
|
|
return result.reduce((out, capture) => (out[capture.name] = capture, out), {});
|
|
};
|
|
|
|
const capturesDev = runExamples(true);
|
|
const capturesBuild = runExamples(false);
|
|
|
|
afterAll(async () => {
|
|
// Report experimental capture comparison.
|
|
const dev = await capturesDev;
|
|
const build = await capturesBuild;
|
|
console.log(comparisonReport(dev, build, MatterBuild.version, saveComparison));
|
|
});
|
|
|
|
describe(`Integration checks (${examples.length})`, () => {
|
|
test(`Examples run without throwing`, async () => {
|
|
const dev = await capturesDev;
|
|
const build = await capturesBuild;
|
|
expect(Object.keys(dev)).toEqual(examples);
|
|
expect(Object.keys(build)).toEqual(examples);
|
|
});
|
|
});
|
|
|
|
// Experimental regression comparison checks.
|
|
if (testComparison) {
|
|
describe(`Regression checks (${examples.length})`, () => {
|
|
expect.extend(toMatchExtrinsics);
|
|
expect.extend(toMatchIntrinsics);
|
|
|
|
test(`Examples match intrinsic properties with release build`, async () => {
|
|
const dev = await capturesDev;
|
|
const build = await capturesBuild;
|
|
// compare mass, inertia, friction etc.
|
|
expect(dev).toMatchIntrinsics(build);
|
|
});
|
|
|
|
test(`Examples match extrinsic positions and velocities with release build`, async () => {
|
|
const dev = await capturesDev;
|
|
const build = await capturesBuild;
|
|
// compare position, linear and angular velocity
|
|
expect(dev).toMatchExtrinsics(build);
|
|
});
|
|
});
|
|
} |