diff --git a/examples/events.js b/examples/events.js index 8904d277..bd7e0a95 100644 --- a/examples/events.js +++ b/examples/events.js @@ -37,7 +37,7 @@ Example.events = function() { // an example of using composite events on the world Events.on(world, 'afterAdd', function(event) { - console.log('added to world:', event.object); + // do something with event.object }); // an example of using beforeUpdate event on an engine diff --git a/test/ExampleWorker.js b/test/ExampleWorker.js index 27d8924a..0f75998b 100644 --- a/test/ExampleWorker.js +++ b/test/ExampleWorker.js @@ -9,7 +9,7 @@ const stubBrowserFeatures = M => { M.Render.run = M.Render.lookAt = noop; M.Runner.create = M.Runner.run = noop; M.MouseConstraint.create = M.Mouse.create = noop; - M.Common.log = M.Common.info = M.Common.warn = noop; + M.Common.info = M.Common.warn = M.Common.log; return M; }; @@ -24,16 +24,19 @@ const { engineCapture } = require('./TestTools'); const MatterDev = stubBrowserFeatures(require('../src/module/main')); const MatterBuild = stubBrowserFeatures(require('../build/matter')); const Example = require('../examples/index'); -const decomp = require('poly-decomp'); const runExample = options => { const Matter = options.useDev ? MatterDev : MatterBuild; const consoleOriginal = global.console; + const logs = []; - global.console = { log: () => {} }; global.document = global.window = { addEventListener: () => {} }; - global.decomp = decomp; global.Matter = Matter; + global.console = { + log: (...args) => { + logs.push(args.join(' ')); + } + }; reset(Matter); @@ -79,13 +82,13 @@ const runExample = options => { global.console = consoleOriginal; global.window = undefined; global.document = undefined; - global.decomp = undefined; global.Matter = undefined; return { name: options.name, duration: totalDuration, overlap: overlapTotal / (overlapCount || 1), + logs, ...engineCapture(engine) }; }; diff --git a/test/Examples.spec.js b/test/Examples.spec.js index 3bf3a647..5a0d8393 100644 --- a/test/Examples.spec.js +++ b/test/Examples.spec.js @@ -3,7 +3,12 @@ jest.setTimeout(30 * 1000); -const { comparisonReport, toMatchExtrinsics, toMatchIntrinsics } = require('./TestTools'); +const { + comparisonReport, + logReport, + toMatchExtrinsics, + toMatchIntrinsics +} = require('./TestTools'); const Example = require('../examples/index'); const MatterBuild = require('../build/matter'); @@ -47,7 +52,11 @@ afterAll(async () => { // Report experimental capture comparison. const dev = await capturesDev; const build = await capturesBuild; - console.log(comparisonReport(dev, build, MatterBuild.version, saveComparison)); + + console.log( + logReport(dev) + '\n' + + comparisonReport(dev, build, MatterBuild.version, saveComparison) + ); }); describe(`Integration checks (${examples.length})`, () => { diff --git a/test/TestTools.js b/test/TestTools.js index ba3d3fb3..3ef9578b 100644 --- a/test/TestTools.js +++ b/test/TestTools.js @@ -202,6 +202,25 @@ const equals = (a, b) => { return true; }; +const logReport = captures => { + let report = ''; + + for (const capture of Object.values(captures)) { + if (!capture.logs.length) { + continue; + } + + report += ` ${capture.name}\n`; + + for (const log of capture.logs) { + report += ` ${log}\n`; + } + } + + return report ? `Output logs on last run\n\n${report}` + : 'Output logs on last run\n\n None\n'; +}; + const comparisonReport = (capturesDev, capturesBuild, buildVersion, save) => { const similaritys = captureSimilarityExtrinsic(capturesDev, capturesBuild); const similarityEntries = Object.entries(similaritys); @@ -284,6 +303,6 @@ const comparisonReport = (capturesDev, capturesBuild, buildVersion, save) => { }; module.exports = { - engineCapture, comparisonReport, + engineCapture, comparisonReport, logReport, toMatchExtrinsics, toMatchIntrinsics }; \ No newline at end of file