mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
df56e615ec
Resolves #1601. Does not include the project JSON since that would require knowledge of a project ID, which the VM has not been responsible for so far. For now, it is the responsibility of the consumer to determine if these assets should be saved or not. Otherwise the VM would need to be responsible for saving, which has been out of its scope.
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
const test = require('tap').test;
|
|
|
|
const {collectAssets} = require('../../src/serialization/serialize-assets');
|
|
|
|
const RenderedTarget = require('../../src/sprites/rendered-target');
|
|
const Sprite = require('../../src/sprites/sprite');
|
|
const VirtualMachine = require('../../src/virtual-machine');
|
|
|
|
test('spec', t => {
|
|
t.type(collectAssets, 'function');
|
|
t.end();
|
|
});
|
|
|
|
test('collectAssets', t => {
|
|
const vm = new VirtualMachine();
|
|
const sprite = new Sprite(null, vm.runtime);
|
|
const target = new RenderedTarget(sprite, vm.runtime);
|
|
vm.runtime.targets = [target];
|
|
const [
|
|
soundAsset1,
|
|
soundAsset2,
|
|
costumeAsset1
|
|
] = [{assetId: 1}, {assetId: 2}, {assetId: 3}];
|
|
sprite.sounds = [{id: 1, asset: soundAsset1}, {id: 2, asset: soundAsset2}];
|
|
sprite.costumes = [{id: 1, asset: costumeAsset1}];
|
|
const assets = collectAssets(vm.runtime);
|
|
t.deepEqual(assets, [soundAsset1, soundAsset2, costumeAsset1]);
|
|
t.end();
|
|
});
|
|
|
|
test('getter', t => {
|
|
const vm = new VirtualMachine();
|
|
const sprite = new Sprite(null, vm.runtime);
|
|
const target = new RenderedTarget(sprite, vm.runtime);
|
|
vm.runtime.targets = [target];
|
|
sprite.sounds = [{id: 1, asset: {}}, {id: 2, asset: {}}];
|
|
sprite.costumes = [{id: 1, asset: {}}];
|
|
const assets = vm.assets;
|
|
t.type(assets.length, 'number');
|
|
t.equal(assets.length, 3);
|
|
t.end();
|
|
});
|