|
| 1 | +/** |
| 2 | + * @fileoverview Tests the build output to verify the public API of scratch-storage. |
| 3 | + */ |
| 4 | + |
| 5 | +const ScratchStorageModule = require('../../dist/node/scratch-storage.js'); |
| 6 | + |
| 7 | +/** @type {ScratchStorageModule.ScratchStorage} */ |
| 8 | +let storage; |
| 9 | + |
| 10 | +beforeEach(() => { |
| 11 | + const {ScratchStorage} = ScratchStorageModule; |
| 12 | + storage = new ScratchStorage(); |
| 13 | +}); |
| 14 | + |
| 15 | +test('constructor', () => { |
| 16 | + const {ScratchStorage} = ScratchStorageModule; |
| 17 | + expect(storage).toBeInstanceOf(ScratchStorage); |
| 18 | +}); |
| 19 | + |
| 20 | +test('DataFormat', () => { |
| 21 | + const {DataFormat} = ScratchStorageModule; |
| 22 | + expect(DataFormat).toBeDefined(); |
| 23 | + expect(DataFormat.JPG).toBe('jpg'); |
| 24 | + expect(DataFormat.JSON).toBe('json'); |
| 25 | + expect(DataFormat.MP3).toBe('mp3'); |
| 26 | + expect(DataFormat.PNG).toBe('png'); |
| 27 | + expect(DataFormat.SB2).toBe('sb2'); |
| 28 | + expect(DataFormat.SB3).toBe('sb3'); |
| 29 | + expect(DataFormat.SVG).toBe('svg'); |
| 30 | + expect(DataFormat.WAV).toBe('wav'); |
| 31 | +}); |
| 32 | + |
| 33 | +test('AssetType', () => { |
| 34 | + const {AssetType, DataFormat} = ScratchStorageModule; |
| 35 | + expect(AssetType).toBeDefined(); |
| 36 | + expect(AssetType.ImageBitmap.contentType).toBe('image/png'); |
| 37 | + expect(AssetType.ImageVector.contentType).toBe('image/svg+xml'); |
| 38 | + expect(AssetType.Project.runtimeFormat).toBe(DataFormat.JSON); |
| 39 | + expect(AssetType.Sound.immutable).toBe(true); |
| 40 | + expect(AssetType.Sprite.name).toBe('Sprite'); |
| 41 | +}); |
| 42 | + |
| 43 | +test('Asset', () => { |
| 44 | + const {Asset, AssetType} = ScratchStorageModule; |
| 45 | + expect(Asset).toBeDefined(); |
| 46 | + const asset = new Asset( |
| 47 | + AssetType.ImageVector, |
| 48 | + 'some-hash' |
| 49 | + ); |
| 50 | + expect(asset).toBeInstanceOf(Asset); |
| 51 | + expect(asset.dataFormat).toBe('svg'); |
| 52 | + expect(asset.assetId).toBe('some-hash'); |
| 53 | +}); |
| 54 | + |
| 55 | +test('Helper', () => { |
| 56 | + const {Helper} = ScratchStorageModule; |
| 57 | + expect(Helper).toBeDefined(); |
| 58 | + const helper = new Helper(); |
| 59 | + expect(helper).toBeInstanceOf(Helper); |
| 60 | +}); |
| 61 | + |
| 62 | +test('scratchFetch API', () => { |
| 63 | + const scratchFetch = storage.scratchFetch; |
| 64 | + expect(scratchFetch).toBeDefined(); |
| 65 | + expect(typeof scratchFetch.scratchFetch).toBe('function'); |
| 66 | + expect(typeof scratchFetch.setMetadata).toBe('function'); |
| 67 | + expect(typeof scratchFetch.unsetMetadata).toBe('function'); |
| 68 | + expect(typeof scratchFetch.getMetadata).toBe('function'); |
| 69 | +}); |
0 commit comments