scratch-vm/test/unit/blocks_music.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

const test = require('tap').test;
2017-11-14 14:58:16 -05:00
const Music = require('../../src/extensions/scratch3_music/index.js');
let playedDrum;
let playedInstrument;
const runtime = {
audioEngine: {
numInstruments: 3,
instrumentPlayer: {
loadInstrument: instrument => (playedInstrument = instrument)
}
}
};
const blocks = new Music(runtime);
2017-11-15 14:10:50 -05:00
blocks._playDrumNum = (util, drum) => (playedDrum = drum);
const util = {
2017-11-15 14:10:50 -05:00
stackFrame: Object.create(null),
target: {
2017-11-15 14:10:50 -05:00
audioPlayer: null
2017-11-13 10:57:36 -05:00
},
2017-11-15 14:10:50 -05:00
yield: () => null
};
test('playDrum uses 1-indexing and wrap clamps', t => {
let args = {DRUM: 1};
blocks.playDrumForBeats(args, util);
t.strictEqual(playedDrum, 0);
2017-11-15 14:10:50 -05:00
args = {DRUM: blocks.DRUM_INFO.length + 1};
blocks.playDrumForBeats(args, util);
t.strictEqual(playedDrum, 0);
t.end();
});
test('setInstrument uses 1-indexing and wrap clamps', t => {
// Stub getMusicState
blocks._getMusicState = () => ({});
let args = {INSTRUMENT: 1};
blocks.setInstrument(args, util);
t.strictEqual(playedInstrument, 0);
args = {INSTRUMENT: runtime.audioEngine.numInstruments + 1};
blocks.setInstrument(args, util);
t.strictEqual(playedInstrument, 0);
t.end();
});