From b61c6a8f765a70ec5cd295c6b063ec8216c7450b Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Wed, 14 Mar 2018 16:07:05 -0700 Subject: [PATCH 1/3] Don't render say/think bubbles during tests This change makes say & think commands work during headless tests. --- src/blocks/scratch3_looks.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index 6b9059c09..d2dbb7a9e 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -153,13 +153,16 @@ class Scratch3LooksBlocks { * @private */ _renderBubble (target) { + if (!this.runtime.renderer) return; + const bubbleState = this._getBubbleState(target); const {drawableVisible, type, text, onSpriteRight} = bubbleState; // Remove the bubble if target is not visible, or text is being set to blank // without being initialized. See comment below about blank text optimization. if (!target.visible || (text === '' && !bubbleState.skinId)) { - return this._onTargetWillExit(target); + this._onTargetWillExit(target); + return; } if (bubbleState.skinId) { From b5d7602f4f5b1037efc26a07f418c849c5cb6730 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Wed, 14 Mar 2018 16:08:53 -0700 Subject: [PATCH 2/3] Add test for say/think and wait This test currently fails due to a bug in the sequencer's `stepThread` method. The bug affects real projects, too, but was not caught by any test prior to this one. --- test/fixtures/saythink-and-wait.sb2 | Bin 0 -> 6588 bytes test/integration/saythink-and-wait.js | 37 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/fixtures/saythink-and-wait.sb2 create mode 100644 test/integration/saythink-and-wait.js diff --git a/test/fixtures/saythink-and-wait.sb2 b/test/fixtures/saythink-and-wait.sb2 new file mode 100644 index 0000000000000000000000000000000000000000..d9be202c4281dd3afa75c4c0d5c62b55056cc41d GIT binary patch literal 6588 zcmWIWW@h1HU|`^2Xsu25F=W0rO_Pa%VF?QZ0}oKNpeR2pHMvADt2jTeHaIqav4KF1 zUp?#d=Ng+76&3UMezQ~h>K*=aUFel|Q=QKB3Cg#Zh==}spU&gCV_CS;5(DGiXV$e} z-^>{J=R5Bdk7tZKw{LJVDoI$?v)0>$FLvKNUN-g={ihS`(xXDxOthZWd{FzwqPQ3< zs~YCGc)yy!GZu?4YcA)|>69oqqVm|LJ=1BijeKa)*7xc;oLBixR;^eY@aaZ~HaBlk z;6+L>zaJRaB@Y=1)dbb?Kj1JrTU7RwBEA{?!mAQr;i!9jf9$U!$?SNa#igVpryuB$VAN{T^Ix%PZ$4?EblSH^L49-QtIv2^cNvlH7l zyb z4TK;PBUug-DA>bgWXM4h1bUi)_s$l?@oIb2uhmQW1U-!g)X;LBN1Rf`x~Pjj_4G@qhvd6B1$ot3*+SA;bVR z4@niK5ZqRTDomk?3>aca?uF^Z5JK@4L=}b*Of!;OF@!LJBS8R*5Iq9&M+)P7bC!;k zng90!Ma3~V31rhN0wTy<{a7d~{FWo^( zhT)#gc{Yrek?2*#&`YbMW#niXiL+e;u3l+VH;ydB*$Nn%)aVH_GI25Bp40$Zf&`GKI0C$3I { + const vm = new VirtualMachine(); + vm.attachStorage(makeTestStorage()); + + // Start VM, load project, and run + t.doesNotThrow(() => { + vm.start(); + vm.clear(); + vm.setCompatibilityMode(false); + vm.setTurboMode(false); + vm.loadProject(project).then(() => { + vm.greenFlag(); + + // After two seconds, stop the project. + // The test will fail if the project throws. + setTimeout(() => { + vm.stopAll(); + t.end(); + process.nextTick(process.exit); + }, 2000); + }); + }); +}); From 4210c6dd4c7726af12ab8c3ca6785c620f4723ce Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Wed, 14 Mar 2018 16:17:29 -0700 Subject: [PATCH 3/3] Fix stack check in `stepThread` The previous logic seemed to be expecting `peekStack` to return 0 when the stack was empty, but its return type is `?string` and it returns `undefined` when the stack is empty. The `!== 0` check would never pass, then, leading to problems with (for example) the "say/think and wait" blocks. --- src/engine/sequencer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/sequencer.js b/src/engine/sequencer.js index 2db6054b7..ce65163d4 100644 --- a/src/engine/sequencer.js +++ b/src/engine/sequencer.js @@ -175,7 +175,7 @@ class Sequencer { thread.popStack(); } // Save the current block ID to notice if we did control flow. - while ((currentBlockId = thread.peekStack()) !== 0) { + while ((currentBlockId = thread.peekStack())) { let isWarpMode = thread.peekStackFrame().warpMode; if (isWarpMode && !thread.warpTimer) { // Initialize warp-mode timer if it hasn't been already.