2019-09-28 10:15:54 -04:00
|
|
|
/* eslint-env es6 */
|
2019-09-14 14:31:31 -04:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
jest.setTimeout(30 * 1000);
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
const { comparisonReport, toMatchExtrinsics, toMatchIntrinsics } = require('./TestTools');
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
const Example = require('../examples/index');
|
2019-09-30 18:28:17 -04:00
|
|
|
const MatterBuild = require('../build/matter');
|
2019-11-07 17:34:59 -05:00
|
|
|
const Worker = require('jest-worker').default;
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
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));
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
const runExamples = async useDev => {
|
|
|
|
const worker = new Worker(require.resolve('./ExampleWorker'), {
|
|
|
|
enableWorkerThreads: true
|
|
|
|
});
|
2019-09-30 18:28:17 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
const result = await Promise.all(examples.map(name => worker.runExample({
|
|
|
|
name,
|
|
|
|
useDev,
|
|
|
|
totalUpdates: 120
|
|
|
|
})));
|
2019-09-30 18:28:17 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
await worker.end();
|
2019-09-30 18:28:17 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
return result.reduce((out, capture) => (out[capture.name] = capture, out), {});
|
2019-09-30 18:28:17 -04:00
|
|
|
};
|
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
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));
|
|
|
|
});
|
2019-09-30 18:28:17 -04:00
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
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);
|
2019-09-30 18:28:17 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
// Experimental regression comparison checks.
|
|
|
|
if (testComparison) {
|
|
|
|
describe(`Regression checks (${examples.length})`, () => {
|
2019-09-30 18:28:17 -04:00
|
|
|
expect.extend(toMatchExtrinsics);
|
|
|
|
expect.extend(toMatchIntrinsics);
|
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
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);
|
2019-09-30 18:28:17 -04:00
|
|
|
});
|
|
|
|
|
2019-11-07 17:34:59 -05:00
|
|
|
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);
|
2019-09-30 18:28:17 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|