import test from 'node:test'; import assert from 'node:assert/strict'; import { existsSync } from 'node:fs'; import { trackFor, Music } from '../src/engine/music.js'; import { story } from '../src/story/story.js'; test('il brano giusto per titolo, fine e scena', () => { const s = { music: { title: 't.mp3', game: 'g.mp3', ending: 'e.mp3' }, scenes: { a: {}, b: { music: 'b.mp3' } } }; assert.equal(trackFor(s, { screen: 'title', scene: 'a' }), 't.mp3'); assert.equal(trackFor(s, { screen: 'intro', scene: 'a' }), 't.mp3'); assert.equal(trackFor(s, { screen: 'ending', scene: 'a' }), 'e.mp3'); assert.equal(trackFor(s, { screen: 'game', scene: 'a' }), 'g.mp3'); assert.equal(trackFor(s, { screen: 'game', scene: 'b' }), 'b.mp3'); assert.equal(trackFor({ scenes: {} }, { screen: 'game', scene: 'x' }), null); }); test('volume e muto', () => { const m = new Music({ volume: 0.5, muted: true }); assert.equal(m.setVolume(1.4), 1); assert.equal(m.muted, false, 'alzare il volume toglie il muto'); assert.equal(m.toggle(), true); assert.equal(m.setVolume(-1), 0); assert.deepEqual(m.settings(), { volume: 0, muted: true }); }); test('i brani della storia esistono', () => { const files = [...Object.values(story.music ?? {}), ...Object.values(story.scenes).map(s => s.music).filter(Boolean)]; assert.ok(files.length); for (const f of files) assert.ok(existsSync(new URL('../' + f, import.meta.url)), `manca ${f}`); });