Skip to content

Commit

Permalink
Add test for serialization order
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jul 26, 2023
1 parent 9e0549b commit 5d18963
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Binary file added test/fixtures/tw-serialize-asset-order.sb3
Binary file not shown.
56 changes: 56 additions & 0 deletions test/integration/tw_serialize_asset_order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const fs = require('fs');
const path = require('path');
const {test} = require('tap');
const JSZip = require('jszip');
const VM = require('../../src/virtual-machine');
const makeTestStorage = require('../fixtures/make-test-storage');

const fixture = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'tw-serialize-asset-order.sb3'));

test('saveProjectSb3 serialization order', t => {
t.plan(13);
const vm = new VM();
vm.attachStorage(makeTestStorage());
vm.loadProject(fixture).then(() => {
vm.saveProjectSb3('arraybuffer').then(serialized => {
JSZip.loadAsync(serialized).then(zip => {
const files = Object.keys(zip.files);
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();
});
});
});
});

test('exportSprite serialization order', t => {
t.plan(9);
const vm = new VM();
vm.attachStorage(makeTestStorage());
vm.loadProject(fixture).then(() => {
vm.exportSprite(vm.runtime.targets[1].id, 'arraybuffer').then(serialized => {
JSZip.loadAsync(serialized).then(zip => {
const files = Object.keys(zip.files);
for (let i = 0; i < files.length; i++) {
// 4 costumes, 4 sounds
if (i === 0) {
t.equal(files[i], 'sprite.json', 'first file is sprite.json');
} else if (i < 5) {
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();
});
});
});
});

0 comments on commit 5d18963

Please sign in to comment.