diff --git a/src/util/tw-asset-util.js b/src/util/tw-asset-util.js index bd6f09a6867..e12816611d7 100644 --- a/src/util/tw-asset-util.js +++ b/src/util/tw-asset-util.js @@ -37,17 +37,6 @@ class AssetUtil { return runtime.wrapAssetRequest(() => runtime.storage.load(assetType, md5, ext)); } - - /** - * - * @param {JSZip} zip Zip to search - * @param {Storage.assetType} assetType scratch-storage asset type - * @param {string} md5ext full md5 with file extension - * @returns {boolean} - */ - static md5ExtExists (zip, assetType, md5ext) { - - } } module.exports = AssetUtil; diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 8cb6f90ab38..08885475715 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -570,15 +570,15 @@ class VirtualMachine extends EventEmitter { * tw: Serialize the project into a map of files without actually zipping the project. * The buffers returned are the exact same ones used internally, not copies. Avoid directly * manipulating them (except project.json, which is created by this function). - * @returns {Record} Map of file name to the raw data for that file. + * @returns {Promise>} Map of file name to the raw data for that file. */ - saveProjectSb3DontZip () { + async saveProjectSb3DontZip () { const projectJson = this.toJSON(); const files = { 'project.json': new _TextEncoder().encode(projectJson) }; - for (const fileDesc of this.serializeAssets()) { + for (const fileDesc of await this.serializeAssets()) { files[fileDesc.fileName] = fileDesc.fileContent; } diff --git a/test/integration/tw_font_manager.js b/test/integration/tw_font_manager.js index 452fabc687a..3b9f440a142 100644 --- a/test/integration/tw_font_manager.js +++ b/test/integration/tw_font_manager.js @@ -409,7 +409,7 @@ test('deleteFont', t => { t.end(); }); -test('fonts are serialized by VM', t => { +test('fonts are serialized by VM', async t => { const vm = new VirtualMachine(); vm.attachStorage(makeTestStorage()); const {storage, fontManager} = vm.runtime; @@ -427,7 +427,7 @@ test('fonts are serialized by VM', t => { const assets = vm.assets; t.same(assets, [fontAsset], 'font is in vm.assets'); - const serializedAssets = vm.serializeAssets(); + const serializedAssets = await vm.serializeAssets(); t.same(serializedAssets, [ { fileName: '94263e4d553bcec128704e354b659526.ttf', @@ -435,7 +435,7 @@ test('fonts are serialized by VM', t => { } ], 'font is in vm.serializeAssets()'); - const notZippedProject = vm.saveProjectSb3DontZip(); + const notZippedProject = await vm.saveProjectSb3DontZip(); t.equal( notZippedProject['94263e4d553bcec128704e354b659526.ttf'], fontAsset.data, diff --git a/test/integration/tw_save_project_sb3.js b/test/integration/tw_save_project_sb3.js index 60306e334d7..437bdb7c1d6 100644 --- a/test/integration/tw_save_project_sb3.js +++ b/test/integration/tw_save_project_sb3.js @@ -42,7 +42,7 @@ test('saveProjectSb3Stream', async t => { await vm.loadProject(fixture); let receivedDataEvent = false; - const stream = vm.saveProjectSb3Stream(); + const stream = await vm.saveProjectSb3Stream(); stream.on('data', data => { if (receivedDataEvent) { return; @@ -54,7 +54,7 @@ test('saveProjectSb3Stream', async t => { const buffer = await stream.accumulate(); t.type(buffer, ArrayBuffer); - const stream2 = vm.saveProjectSb3Stream('uint8array'); + const stream2 = await vm.saveProjectSb3Stream('uint8array'); const uint8array = await stream2.accumulate(); t.type(uint8array, Uint8Array); @@ -71,7 +71,7 @@ test('saveProjectSb3DontZip', async t => { vm.attachStorage(makeTestStorage()); await vm.loadProject(fixture); - const map = vm.saveProjectSb3DontZip(); + const map = await vm.saveProjectSb3DontZip(); t.equal(map['project.json'][0], '{'.charCodeAt(0)); t.equal(map['d9c625ae1996b615a146ac2a7dbe74d7.svg'].byteLength, 691); t.equal(map['cd21514d0531fdffb22204e0ec5ed84a.svg'].byteLength, 202); diff --git a/test/integration/tw_serialize_asset_order.js b/test/integration/tw_serialize_asset_order.js index 8d296ac2a85..586a65f4397 100644 --- a/test/integration/tw_serialize_asset_order.js +++ b/test/integration/tw_serialize_asset_order.js @@ -12,17 +12,18 @@ test('serializeAssets serialization order', t => { const vm = new VM(); vm.attachStorage(makeTestStorage()); vm.loadProject(fixture).then(() => { - const assets = vm.serializeAssets(); - for (let i = 0; i < assets.length; i++) { - // won't deduplicate assets, so expecting 8 costumes, 7 sounds - // 8 costumes, 6 sounds - if (i < 8) { - t.ok(assets[i].fileName.endsWith('.svg'), `file ${i + 1} is costume`); - } else { - t.ok(assets[i].fileName.endsWith('.wav'), `file ${i + 1} is sound`); + vm.serializeAssets().then(assets => { + for (let i = 0; i < assets.length; i++) { + // won't deduplicate assets, so expecting 8 costumes, 7 sounds + // 8 costumes, 6 sounds + if (i < 8) { + t.ok(assets[i].fileName.endsWith('.svg'), `file ${i + 1} is costume`); + } else { + t.ok(assets[i].fileName.endsWith('.wav'), `file ${i + 1} is sound`); + } } - } - t.end(); + t.end(); + }); }); }); @@ -79,20 +80,21 @@ test('saveProjectSb3DontZip', t => { const vm = new VM(); vm.attachStorage(makeTestStorage()); vm.loadProject(fixture).then(() => { - const exported = vm.saveProjectSb3DontZip(); - const files = Object.keys(exported); - - for (let i = 0; i < files.length; i++) { - // 6 costumes, 6 sounds - if (i === 0) { - t.equal(files[i], 'project.json', 'first file is project.json'); - } else if (i < 7) { - t.ok(files[i].endsWith('.svg'), `file ${i + 1} is costume`); - } else { - t.ok(files[i].endsWith('.wav'), `file ${i + 1} is sound`); + vm.saveProjectSb3DontZip().then(exported => { + const files = Object.keys(exported); + + for (let i = 0; i < files.length; i++) { + // 6 costumes, 6 sounds + if (i === 0) { + t.equal(files[i], 'project.json', 'first file is project.json'); + } else if (i < 7) { + t.ok(files[i].endsWith('.svg'), `file ${i + 1} is costume`); + } else { + t.ok(files[i].endsWith('.wav'), `file ${i + 1} is sound`); + } } - } - - t.end(); + + t.end(); + }); }); }); diff --git a/test/unit/tw_cancellable_mutex.js b/test/unit/tw_cancellable_mutex.js index 682ca325db5..3f3639666cd 100644 --- a/test/unit/tw_cancellable_mutex.js +++ b/test/unit/tw_cancellable_mutex.js @@ -88,7 +88,7 @@ test('cancellation', t => { t.fail(); })); - // After dispoing, existing operation should be cancelled, queue should be cleared. + // After cancelling, existing operation should be able to see that, and queue should be cleared. mutex.cancel(); t.equal(isCancelled(), true);