Skip to content

Commit

Permalink
lazy: fix various test breakage
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jan 2, 2025
1 parent 420aa4f commit c9c9d34
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 45 deletions.
11 changes: 0 additions & 11 deletions src/util/tw-asset-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Uint8Array>} Map of file name to the raw data for that file.
* @returns {Promise<Record<string, Uint8Array>>} 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;
}

Expand Down
6 changes: 3 additions & 3 deletions test/integration/tw_font_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -427,15 +427,15 @@ 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',
fileContent: new Uint8Array([10, 11, 12])
}
], 'font is in vm.serializeAssets()');

const notZippedProject = vm.saveProjectSb3DontZip();
const notZippedProject = await vm.saveProjectSb3DontZip();
t.equal(
notZippedProject['94263e4d553bcec128704e354b659526.ttf'],
fontAsset.data,
Expand Down
6 changes: 3 additions & 3 deletions test/integration/tw_save_project_sb3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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);
Expand Down
50 changes: 26 additions & 24 deletions test/integration/tw_serialize_asset_order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

Expand Down Expand Up @@ -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();
});
});
});
2 changes: 1 addition & 1 deletion test/unit/tw_cancellable_mutex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c9c9d34

Please sign in to comment.