UNPKG

1.39 kBJavaScriptView Raw
1const md5 = require('js-md5');
2const test = require('tap').test;
3
4const ScratchStorage = require('../../dist/node/scratch-storage');
5
6var storage;
7test('constructor', t => {
8 storage = new ScratchStorage();
9 t.type(storage, ScratchStorage);
10 t.end();
11});
12
13const defaultAssetTypes = [storage.AssetType.ImageBitmap, storage.AssetType.ImageVector, storage.AssetType.Sound];
14const defaultIds = {};
15
16test('getDefaultAssetId', t => {
17 for (var i = 0; i < defaultAssetTypes.length; ++i) {
18 const assetType = defaultAssetTypes[i];
19 const id = storage.getDefaultAssetId(assetType);
20 t.type(id, 'string');
21 defaultIds[assetType.name] = id;
22 }
23 t.end();
24});
25
26test('load', t => {
27 const promises = [];
28 const checkAsset = (assetType, id, asset) => {
29 t.type(asset, storage.Asset);
30 t.strictEqual(asset.assetId, id);
31 t.strictEqual(asset.assetType, assetType);
32 t.ok(asset.data.length);
33 t.strictEqual(md5(asset.data), id);
34 };
35 for (var i = 0; i < defaultAssetTypes.length; ++i) {
36 const assetType = defaultAssetTypes[i];
37 const id = defaultIds[assetType.name];
38
39 const promise = storage.load(assetType, id);
40 t.type(promise, 'Promise');
41
42 promises.push(promise);
43
44 promise.then(asset => checkAsset(assetType, id, asset));
45 }
46
47 return Promise.all(promises);
48});