From 979ed66594ed52f8c2656a6748d2d6037f8f98d9 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 5 Nov 2018 13:01:00 -0500 Subject: [PATCH] Add a unit test to ensure extensions are loaded on shareBlocksToTarget --- test/unit/virtual-machine.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index b93ccc351..371cd96cf 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -910,6 +910,35 @@ test('shareBlocksToTarget chooses a fresh name for a new global variable checkin }); }); +test('shareBlocksToTarget loads extensions that have not yet been loaded', t => { + const vm = new VirtualMachine(); + const runtime = vm.runtime; + const spr1 = new Sprite(null, runtime); + const stage = spr1.createClone(); + runtime.targets = [stage]; + + const fakeBlocks = [ + {opcode: 'loaded_fakeblock'}, + {opcode: 'notloaded_fakeblock'} + ]; + + // Stub the extension manager + const loadedIds = []; + vm.extensionManager = { + isExtensionLoaded: id => id === 'loaded', + loadExtensionURL: id => new Promise(resolve => { + loadedIds.push(id); + resolve(); + }) + }; + + vm.shareBlocksToTarget(fakeBlocks, stage.id).then(() => { + // Verify that only the not-loaded extension gets loaded + t.deepEqual(loadedIds, ['notloaded']); + t.end(); + }); +}); + test('Setting turbo mode emits events', t => { let turboMode = null;