Skip to content

Commit ff75c31

Browse files
Merge pull request scratchfoundation#260 from scratchfoundation/fix/uepr-258-intermittent-scratch-vm-test-failures
Fix/uepr 258 intermittent scratch vm test failures
2 parents 34259ae + 065ce6c commit ff75c31

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

packages/scratch-vm/test/integration/monitors_sb2_to_sb3.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,25 @@ const makeTestStorage = require('../fixtures/make-test-storage');
44
const readFileToBuffer = require('../fixtures/readProjectFile').readFileToBuffer;
55
const VirtualMachine = require('../../src/index');
66

7-
let vm;
7+
const projectUri = path.resolve(__dirname, '../fixtures/monitors.sb2');
8+
const project = readFileToBuffer(projectUri);
89

9-
tap.beforeEach(() => {
10-
const projectUri = path.resolve(__dirname, '../fixtures/monitors.sb2');
11-
const project = readFileToBuffer(projectUri);
12-
13-
vm = new VirtualMachine();
14-
vm.attachStorage(makeTestStorage());
15-
16-
// TODO figure out why running threads doesn't work in this test
17-
// vm.start();
18-
vm.clear();
19-
vm.setCompatibilityMode(false);
20-
vm.setTurboMode(false);
21-
22-
return vm.loadProject(project);
23-
});
2410
const test = tap.test;
2511

2612
test('saving and loading sb2 project with monitors preserves sliderMin and sliderMax', t => {
13+
const vm = new VirtualMachine();
14+
vm.attachStorage(makeTestStorage());
2715

2816
vm.on('playgroundData', e /* eslint-disable-line no-unused-vars */ => {
29-
// TODO related to above TODO, comment these back in when we figure out
30-
// why running threads doesn't work with this test
31-
32-
// const threads = JSON.parse(e.threads);
17+
const threads = JSON.parse(e.threads);
3318
// All monitors should create threads that finish during the step and
3419
// are revoved from runtime.threads.
35-
// t.equal(threads.length, 0);
20+
t.equal(threads.length, 0);
3621

3722
// we care that the last step updated the right number of monitors
3823
// we don't care whether the last step ran other threads or not
39-
// const lastStepUpdatedMonitorThreads = vm.runtime._lastStepDoneThreads.filter(thread => thread.updateMonitor);
40-
// t.equal(lastStepUpdatedMonitorThreads.length, 8);
24+
const lastStepUpdatedMonitorThreads = vm.runtime._lastStepDoneThreads.filter(thread => thread.updateMonitor);
25+
t.equal(lastStepUpdatedMonitorThreads.length, 8);
4126

4227
// There should be one additional hidden monitor that is in the monitorState but
4328
// does not start a thread.
@@ -139,13 +124,18 @@ test('saving and loading sb2 project with monitors preserves sliderMin and slide
139124
t.equal(monitorRecord.spriteName, null);
140125
t.equal(monitorRecord.targetId, null);
141126

127+
vm.quit();
142128
t.end();
143129
});
144130

145131
// Start VM, load project, and run
146132
t.doesNotThrow(() => {
147-
const sb3ProjectJson = vm.toJSON();
148-
return vm.loadProject(sb3ProjectJson).then(() => {
133+
vm.start();
134+
vm.clear();
135+
vm.setCompatibilityMode(false);
136+
vm.setTurboMode(false);
137+
return vm.loadProject(project).then(() => {
138+
vm.greenFlag();
149139
setTimeout(() => {
150140
vm.getPlaygroundData();
151141
vm.stopAll();

0 commit comments

Comments
 (0)