-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixisound_smoke.harness.mjs
More file actions
67 lines (53 loc) · 2.07 KB
/
Copy pathpixisound_smoke.harness.mjs
File metadata and controls
67 lines (53 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPDX-License-Identifier: MPL-2.0
// bindings #2 — Node ESM harness for the @pixi/sound binding.
//
// Installs a globalThis.__as_pixi_sound mock before importing the
// generated module, drives each smoke* wrapper, and asserts the side
// effects (URL forwarded, transport calls counted, volume/loop set)
// were observed on the underlying mock sound instance.
import assert from "node:assert/strict";
class MockSound {
constructor(url) {
this.url = url;
this.playCount = 0;
this.stopCount = 0;
this.pauseCount = 0;
this.resumeCount = 0;
this.volume = 1.0;
this.loop = false;
}
play() { this.playCount += 1; }
stop() { this.stopCount += 1; }
pause() { this.pauseCount += 1; }
resume() { this.resumeCount += 1; }
}
let lastFromUrl = null;
globalThis.__as_pixi_sound = {
from(url) {
lastFromUrl = url;
return new MockSound(url);
},
};
const {
smokeFrom, smokePlay, smokeStop, smokePause, smokeResume,
smokeSetVolume, smokeSetLoop,
} = await import("./pixisound_smoke.deno.js");
const s = smokeFrom("assets/bgm.mp3");
assert.equal(lastFromUrl, "assets/bgm.mp3", "from URL reaches host");
assert.equal(s.url, "assets/bgm.mp3", "constructed sound carries url");
assert.equal(smokePlay(s), 0, "play returns 0");
assert.equal(smokePlay(s), 0, "play returns 0 (twice)");
assert.equal(s.playCount, 2, "play invoked twice");
assert.equal(smokeStop(s), 0, "stop returns 0");
assert.equal(s.stopCount, 1, "stop invoked once");
assert.equal(smokePause(s), 0, "pause returns 0");
assert.equal(s.pauseCount, 1, "pause invoked once");
assert.equal(smokeResume(s), 0, "resume returns 0");
assert.equal(s.resumeCount, 1, "resume invoked once");
assert.equal(smokeSetVolume(s, 0.5), 0, "setVolume returns 0");
assert.equal(s.volume, 0.5, "volume field updated");
assert.equal(smokeSetLoop(s, true), 0, "setLoop returns 0");
assert.equal(s.loop, true, "loop field updated");
assert.equal(smokeSetLoop(s, false), 0, "setLoop(false) returns 0");
assert.equal(s.loop, false, "loop field cleared");
console.log("pixisound_smoke.harness.mjs OK");