2019-09-28 10:15:54 -04:00
|
|
|
/* eslint-env es6 */
|
2019-09-14 14:31:31 -04:00
|
|
|
"use strict";
|
|
|
|
|
2021-12-26 16:57:51 -05:00
|
|
|
jest.setTimeout(2 * 60 * 1000);
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2021-11-21 12:00:53 -05:00
|
|
|
const fs = require('fs');
|
|
|
|
|
2021-11-28 16:25:11 -05:00
|
|
|
const {
|
|
|
|
requireUncached,
|
2021-01-28 19:09:27 -05:00
|
|
|
comparisonReport,
|
|
|
|
logReport,
|
|
|
|
toMatchExtrinsics,
|
2023-08-13 08:10:09 -04:00
|
|
|
toMatchIntrinsics,
|
|
|
|
getArg
|
2021-01-28 19:09:27 -05:00
|
|
|
} = require('./TestTools');
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2021-11-28 16:25:11 -05:00
|
|
|
const Example = requireUncached('../examples/index');
|
|
|
|
const MatterBuild = requireUncached('../build/matter');
|
|
|
|
const { versionSatisfies } = requireUncached('../src/core/Plugin');
|
2019-11-07 17:34:59 -05:00
|
|
|
const Worker = require('jest-worker').default;
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2023-08-13 08:10:09 -04:00
|
|
|
const testComparison = getArg('compare', null) === 'true';
|
|
|
|
const saveComparison = getArg('save', null) === 'true';
|
|
|
|
const specificExamples = getArg('examples', null, (val) => val.split(','));
|
|
|
|
const repeats = getArg('repeats', 1, parseFloat);
|
|
|
|
const updates = getArg('updates', 150, parseFloat);
|
2021-12-15 04:58:31 -05:00
|
|
|
|
2020-03-09 16:56:06 -04:00
|
|
|
const excludeExamples = ['svg', 'terrain'];
|
|
|
|
const excludeJitter = ['stack', 'circleStack', 'restitution', 'staticFriction', 'friction', 'newtonsCradle', 'catapult'];
|
2020-12-30 18:03:38 -05:00
|
|
|
|
2021-12-15 04:58:31 -05:00
|
|
|
const examples = (specificExamples || Object.keys(Example)).filter(key => {
|
2020-12-30 18:03:38 -05:00
|
|
|
const excluded = excludeExamples.includes(key);
|
|
|
|
const buildVersion = MatterBuild.version;
|
|
|
|
const exampleFor = Example[key].for;
|
|
|
|
const supported = versionSatisfies(buildVersion, exampleFor);
|
|
|
|
return !excluded && supported;
|
|
|
|
});
|
2019-09-14 14:31:31 -04:00
|
|
|
|
2021-11-28 16:25:11 -05:00
|
|
|
const captureExamples = async useDev => {
|
2021-12-01 18:34:41 -05:00
|
|
|
const multiThreadWorker = new Worker(require.resolve('./ExampleWorker'), {
|
|
|
|
enableWorkerThreads: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const overlapRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
|
|
|
|
name,
|
|
|
|
useDev,
|
2022-08-06 04:49:30 -04:00
|
|
|
updates: 2,
|
2023-08-13 08:10:09 -04:00
|
|
|
repeats: 1,
|
2021-12-01 18:34:41 -05:00
|
|
|
stableSort: true,
|
|
|
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
|
|
|
})));
|
|
|
|
|
|
|
|
const behaviourRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
|
|
|
|
name,
|
|
|
|
useDev,
|
|
|
|
updates: 2,
|
2023-08-13 08:10:09 -04:00
|
|
|
repeats: 1,
|
2021-12-01 18:34:41 -05:00
|
|
|
stableSort: true,
|
|
|
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
|
|
|
})));
|
|
|
|
|
|
|
|
const similarityRuns = await Promise.all(examples.map(name => multiThreadWorker.runExample({
|
|
|
|
name,
|
|
|
|
useDev,
|
|
|
|
updates: 2,
|
2023-08-13 08:10:09 -04:00
|
|
|
repeats: 1,
|
2021-12-01 18:34:41 -05:00
|
|
|
stableSort: false,
|
|
|
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
|
|
|
})));
|
|
|
|
|
|
|
|
await multiThreadWorker.end();
|
|
|
|
|
|
|
|
const singleThreadWorker = new Worker(require.resolve('./ExampleWorker'), {
|
2021-11-19 15:30:12 -05:00
|
|
|
enableWorkerThreads: true,
|
|
|
|
numWorkers: 1
|
2019-11-07 17:34:59 -05:00
|
|
|
});
|
2019-09-30 18:28:17 -04:00
|
|
|
|
2021-12-01 18:34:41 -05:00
|
|
|
const completeRuns = await Promise.all(examples.map(name => singleThreadWorker.runExample({
|
2019-11-07 17:34:59 -05:00
|
|
|
name,
|
|
|
|
useDev,
|
2023-08-13 08:10:09 -04:00
|
|
|
updates: updates,
|
|
|
|
repeats: repeats,
|
2021-12-01 18:34:41 -05:00
|
|
|
stableSort: false,
|
2020-03-09 16:56:06 -04:00
|
|
|
jitter: excludeJitter.includes(name) ? 0 : 1e-10
|
2019-11-07 17:34:59 -05:00
|
|
|
})));
|
2019-09-30 18:28:17 -04:00
|
|
|
|
2021-12-01 18:34:41 -05:00
|
|
|
await singleThreadWorker.end();
|
|
|
|
|
|
|
|
const capture = {};
|
|
|
|
|
|
|
|
for (const completeRun of completeRuns) {
|
|
|
|
const behaviourRun = behaviourRuns.find(({ name }) => name === completeRun.name);
|
|
|
|
const similarityRun = similarityRuns.find(({ name }) => name === completeRun.name);
|
|
|
|
const overlapRun = overlapRuns.find(({ name }) => name === completeRun.name);
|
|
|
|
|
|
|
|
capture[overlapRun.name] = {
|
|
|
|
...completeRun,
|
|
|
|
behaviourExtrinsic: behaviourRun.extrinsic,
|
|
|
|
similarityExtrinsic: similarityRun.extrinsic,
|
|
|
|
overlap: overlapRun.overlap
|
|
|
|
};
|
|
|
|
}
|
2019-09-30 18:28:17 -04:00
|
|
|
|
2021-12-01 18:34:41 -05:00
|
|
|
return capture;
|
2019-09-30 18:28:17 -04:00
|
|
|
};
|
|
|
|
|
2021-11-28 16:25:11 -05:00
|
|
|
const capturesDev = captureExamples(true);
|
|
|
|
const capturesBuild = captureExamples(false);
|
2019-11-07 17:34:59 -05:00
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
// Report experimental capture comparison.
|
|
|
|
const dev = await capturesDev;
|
|
|
|
const build = await capturesBuild;
|
2021-01-28 19:09:27 -05:00
|
|
|
|
2021-11-21 12:00:53 -05:00
|
|
|
const buildSize = fs.statSync('./build/matter.min.js').size;
|
|
|
|
const devSize = fs.statSync('./build/matter.dev.min.js').size;
|
|
|
|
|
2021-01-28 19:09:27 -05:00
|
|
|
console.log(
|
2021-11-21 12:00:53 -05:00
|
|
|
'Examples ran against previous release and current build\n\n'
|
2021-01-31 12:34:38 -05:00
|
|
|
+ logReport(build, `release`) + '\n'
|
|
|
|
+ logReport(dev, `current`) + '\n'
|
2021-11-21 12:00:53 -05:00
|
|
|
+ comparisonReport(dev, build, devSize, buildSize, MatterBuild.version, saveComparison)
|
2021-01-28 19:09:27 -05:00
|
|
|
);
|
2019-11-07 17:34:59 -05:00
|
|
|
});
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|