From cc4751228ed3c247ac9af139a94977f7d2ba8fbe Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 27 Nov 2018 11:37:01 -0500 Subject: [PATCH 1/2] Emit a RUNTIME_STARTED event to track if the vm has been started --- src/engine/runtime.js | 9 +++++++++ src/virtual-machine.js | 3 +++ test/unit/engine_runtime.js | 11 +++++++++++ test/unit/virtual-machine.js | 11 +++++++++++ 4 files changed, 34 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index e16ac5411..7a5b7a3e0 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -597,6 +597,14 @@ class Runtime extends EventEmitter { return 'BLOCKSINFO_UPDATE'; } + /** + * Event name when the runtime tick loop has been started. + * @const {string} + */ + static get RUNTIME_STARTED () { + return 'RUNTIME_STARTED'; + } + /** * How rapidly we try to step threads by default, in ms. */ @@ -2158,6 +2166,7 @@ class Runtime extends EventEmitter { this._steppingInterval = setInterval(() => { this._step(); }, interval); + this.emit(Runtime.RUNTIME_STARTED); } /** diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 6f15c43d1..724950b2f 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -123,6 +123,9 @@ class VirtualMachine extends EventEmitter { this.runtime.on(Runtime.MIC_LISTENING, listening => { this.emit(Runtime.MIC_LISTENING, listening); }); + this.runtime.on(Runtime.RUNTIME_STARTED, () => { + this.emit(Runtime.RUNTIME_STARTED); + }); this.extensionManager = new ExtensionManager(this.runtime); diff --git a/test/unit/engine_runtime.js b/test/unit/engine_runtime.js index 4fd56416b..704da17b2 100644 --- a/test/unit/engine_runtime.js +++ b/test/unit/engine_runtime.js @@ -180,3 +180,14 @@ test('Cloud variable limit allows only 8 cloud variables', t => { t.end(); }); + +test('Starting the runtime emits an event', t => { + let started = false; + const rt = new Runtime(); + rt.addListener('RUNTIME_STARTED', () => { + started = true; + }); + rt.start(); + t.equal(started, true); + t.end(); +}); diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index 371cd96cf..e8bbdc824 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -967,3 +967,14 @@ test('Getting the renderer returns the renderer', t => { t.equal(vm.renderer, renderer); t.end(); }); + +test('Starting the VM emits an event', t => { + let started = false; + const vm = new VirtualMachine(); + vm.addListener('RUNTIME_STARTED', () => { + started = true; + }); + vm.start(); + t.equal(started, true); + t.end(); +}); From 0c38c3cffe4b646c1228cd0e543545875b87191d Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 27 Nov 2018 16:06:56 -0500 Subject: [PATCH 2/2] Force exiting after tests finish --- test/unit/engine_runtime.js | 6 +++++- test/unit/virtual-machine.js | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/unit/engine_runtime.js b/test/unit/engine_runtime.js index 704da17b2..2d5c28978 100644 --- a/test/unit/engine_runtime.js +++ b/test/unit/engine_runtime.js @@ -1,4 +1,4 @@ -const test = require('tap').test; +const tap = require('tap'); const path = require('path'); const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer; const VirtualMachine = require('../../src/virtual-machine'); @@ -6,6 +6,10 @@ const Runtime = require('../../src/engine/runtime'); const MonitorRecord = require('../../src/engine/monitor-record'); const {Map} = require('immutable'); +tap.tearDown(() => process.nextTick(process.exit)); + +const test = tap.test; + test('spec', t => { const r = new Runtime(); diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index e8bbdc824..78036fdcf 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -1,4 +1,4 @@ -const test = require('tap').test; +const tap = require('tap'); const VirtualMachine = require('../../src/virtual-machine'); const Sprite = require('../../src/sprites/sprite'); const Variable = require('../../src/engine/variable'); @@ -8,6 +8,10 @@ const Renderer = require('../fixtures/fake-renderer'); const Runtime = require('../../src/engine/runtime'); const RenderedTarget = require('../../src/sprites/rendered-target'); +tap.tearDown(() => process.nextTick(process.exit)); + +const test = tap.test; + test('deleteSound returns function after deleting or null if nothing was deleted', t => { const vm = new VirtualMachine(); const sprite = new Sprite();