Skip to content

Commit c9c9d34

Browse files
committed
lazy: fix various test breakage
1 parent 420aa4f commit c9c9d34

File tree

6 files changed

+36
-45
lines changed

6 files changed

+36
-45
lines changed

src/util/tw-asset-util.js

-11
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ class AssetUtil {
3737

3838
return runtime.wrapAssetRequest(() => runtime.storage.load(assetType, md5, ext));
3939
}
40-
41-
/**
42-
*
43-
* @param {JSZip} zip Zip to search
44-
* @param {Storage.assetType} assetType scratch-storage asset type
45-
* @param {string} md5ext full md5 with file extension
46-
* @returns {boolean}
47-
*/
48-
static md5ExtExists (zip, assetType, md5ext) {
49-
50-
}
5140
}
5241

5342
module.exports = AssetUtil;

src/virtual-machine.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,15 @@ class VirtualMachine extends EventEmitter {
570570
* tw: Serialize the project into a map of files without actually zipping the project.
571571
* The buffers returned are the exact same ones used internally, not copies. Avoid directly
572572
* manipulating them (except project.json, which is created by this function).
573-
* @returns {Record<string, Uint8Array>} Map of file name to the raw data for that file.
573+
* @returns {Promise<Record<string, Uint8Array>>} Map of file name to the raw data for that file.
574574
*/
575-
saveProjectSb3DontZip () {
575+
async saveProjectSb3DontZip () {
576576
const projectJson = this.toJSON();
577577

578578
const files = {
579579
'project.json': new _TextEncoder().encode(projectJson)
580580
};
581-
for (const fileDesc of this.serializeAssets()) {
581+
for (const fileDesc of await this.serializeAssets()) {
582582
files[fileDesc.fileName] = fileDesc.fileContent;
583583
}
584584

test/integration/tw_font_manager.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ test('deleteFont', t => {
409409
t.end();
410410
});
411411

412-
test('fonts are serialized by VM', t => {
412+
test('fonts are serialized by VM', async t => {
413413
const vm = new VirtualMachine();
414414
vm.attachStorage(makeTestStorage());
415415
const {storage, fontManager} = vm.runtime;
@@ -427,15 +427,15 @@ test('fonts are serialized by VM', t => {
427427
const assets = vm.assets;
428428
t.same(assets, [fontAsset], 'font is in vm.assets');
429429

430-
const serializedAssets = vm.serializeAssets();
430+
const serializedAssets = await vm.serializeAssets();
431431
t.same(serializedAssets, [
432432
{
433433
fileName: '94263e4d553bcec128704e354b659526.ttf',
434434
fileContent: new Uint8Array([10, 11, 12])
435435
}
436436
], 'font is in vm.serializeAssets()');
437437

438-
const notZippedProject = vm.saveProjectSb3DontZip();
438+
const notZippedProject = await vm.saveProjectSb3DontZip();
439439
t.equal(
440440
notZippedProject['94263e4d553bcec128704e354b659526.ttf'],
441441
fontAsset.data,

test/integration/tw_save_project_sb3.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test('saveProjectSb3Stream', async t => {
4242
await vm.loadProject(fixture);
4343

4444
let receivedDataEvent = false;
45-
const stream = vm.saveProjectSb3Stream();
45+
const stream = await vm.saveProjectSb3Stream();
4646
stream.on('data', data => {
4747
if (receivedDataEvent) {
4848
return;
@@ -54,7 +54,7 @@ test('saveProjectSb3Stream', async t => {
5454
const buffer = await stream.accumulate();
5555
t.type(buffer, ArrayBuffer);
5656

57-
const stream2 = vm.saveProjectSb3Stream('uint8array');
57+
const stream2 = await vm.saveProjectSb3Stream('uint8array');
5858
const uint8array = await stream2.accumulate();
5959
t.type(uint8array, Uint8Array);
6060

@@ -71,7 +71,7 @@ test('saveProjectSb3DontZip', async t => {
7171
vm.attachStorage(makeTestStorage());
7272
await vm.loadProject(fixture);
7373

74-
const map = vm.saveProjectSb3DontZip();
74+
const map = await vm.saveProjectSb3DontZip();
7575
t.equal(map['project.json'][0], '{'.charCodeAt(0));
7676
t.equal(map['d9c625ae1996b615a146ac2a7dbe74d7.svg'].byteLength, 691);
7777
t.equal(map['cd21514d0531fdffb22204e0ec5ed84a.svg'].byteLength, 202);

test/integration/tw_serialize_asset_order.js

+26-24
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ test('serializeAssets serialization order', t => {
1212
const vm = new VM();
1313
vm.attachStorage(makeTestStorage());
1414
vm.loadProject(fixture).then(() => {
15-
const assets = vm.serializeAssets();
16-
for (let i = 0; i < assets.length; i++) {
17-
// won't deduplicate assets, so expecting 8 costumes, 7 sounds
18-
// 8 costumes, 6 sounds
19-
if (i < 8) {
20-
t.ok(assets[i].fileName.endsWith('.svg'), `file ${i + 1} is costume`);
21-
} else {
22-
t.ok(assets[i].fileName.endsWith('.wav'), `file ${i + 1} is sound`);
15+
vm.serializeAssets().then(assets => {
16+
for (let i = 0; i < assets.length; i++) {
17+
// won't deduplicate assets, so expecting 8 costumes, 7 sounds
18+
// 8 costumes, 6 sounds
19+
if (i < 8) {
20+
t.ok(assets[i].fileName.endsWith('.svg'), `file ${i + 1} is costume`);
21+
} else {
22+
t.ok(assets[i].fileName.endsWith('.wav'), `file ${i + 1} is sound`);
23+
}
2324
}
24-
}
25-
t.end();
25+
t.end();
26+
});
2627
});
2728
});
2829

@@ -79,20 +80,21 @@ test('saveProjectSb3DontZip', t => {
7980
const vm = new VM();
8081
vm.attachStorage(makeTestStorage());
8182
vm.loadProject(fixture).then(() => {
82-
const exported = vm.saveProjectSb3DontZip();
83-
const files = Object.keys(exported);
84-
85-
for (let i = 0; i < files.length; i++) {
86-
// 6 costumes, 6 sounds
87-
if (i === 0) {
88-
t.equal(files[i], 'project.json', 'first file is project.json');
89-
} else if (i < 7) {
90-
t.ok(files[i].endsWith('.svg'), `file ${i + 1} is costume`);
91-
} else {
92-
t.ok(files[i].endsWith('.wav'), `file ${i + 1} is sound`);
83+
vm.saveProjectSb3DontZip().then(exported => {
84+
const files = Object.keys(exported);
85+
86+
for (let i = 0; i < files.length; i++) {
87+
// 6 costumes, 6 sounds
88+
if (i === 0) {
89+
t.equal(files[i], 'project.json', 'first file is project.json');
90+
} else if (i < 7) {
91+
t.ok(files[i].endsWith('.svg'), `file ${i + 1} is costume`);
92+
} else {
93+
t.ok(files[i].endsWith('.wav'), `file ${i + 1} is sound`);
94+
}
9395
}
94-
}
95-
96-
t.end();
96+
97+
t.end();
98+
});
9799
});
98100
});

test/unit/tw_cancellable_mutex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test('cancellation', t => {
8888
t.fail();
8989
}));
9090

91-
// After dispoing, existing operation should be cancelled, queue should be cleared.
91+
// After cancelling, existing operation should be able to see that, and queue should be cleared.
9292
mutex.cancel();
9393
t.equal(isCancelled(), true);
9494

0 commit comments

Comments
 (0)