Skip to content

Commit c92f1b3

Browse files
committed
test: add API shape test for build output
1 parent 26e664d commit c92f1b3

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

.github/workflows/ci-cd.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ jobs:
4040
- name: Setup & Test
4141
run: |
4242
npm ci
43+
npm run clean
44+
npm run test # runs on source files
4345
npm run build
44-
npm run test
46+
npm run test:build # requires build output
4547
4648
- name: Semantic release (configured to run dry if branch is other than 'develop')
4749
env:

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
"browser": "./dist/web/scratch-storage.js",
1414
"types": "./dist/types/index.d.ts",
1515
"scripts": {
16-
"build": "rimraf dist && webpack --mode=production",
16+
"build": "npm run clean && webpack --mode=production",
17+
"clean": "rimraf dist",
1718
"commitmsg": "commitlint -e $GIT_PARAMS",
1819
"coverage": "tap ./test/{unit,integration}/*.js --coverage --coverage-report=lcov",
1920
"prepare": "husky install",
2021
"semantic-release": "semantic-release",
2122
"test": "npm run test:lint && jest \"test[\\\\/](unit|integration)\"",
23+
"test:build": "jest \"test[\\\\/]build\"",
2224
"test:clearCache": "jest --clearCache",
2325
"test:integration": "jest \"test[\\\\/]integration\"",
2426
"test:lint": "eslint .",

test/build/api.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)