forked from scratchfoundation/scratch-vm
-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e0549b
commit 5d18963
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); | ||
}); |