mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Move music-related unit tests into a separate file
This commit is contained in:
parent
50c646259c
commit
dc4767646f
2 changed files with 51 additions and 41 deletions
48
test/unit/blocks_music.js
Normal file
48
test/unit/blocks_music.js
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
const test = require('tap').test;
|
||||||
|
const Music = require('../../src/blocks/scratch3_music');
|
||||||
|
let playedDrum;
|
||||||
|
let playedInstrument;
|
||||||
|
const runtime = {
|
||||||
|
audioEngine: {
|
||||||
|
numDrums: 3,
|
||||||
|
numInstruments: 3,
|
||||||
|
instrumentPlayer: {
|
||||||
|
loadInstrument: instrument => (playedInstrument = instrument)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const blocks = new Music(runtime);
|
||||||
|
const util = {
|
||||||
|
target: {
|
||||||
|
audioPlayer: {
|
||||||
|
playDrumForBeats: drum => (playedDrum = drum)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
test('playDrum uses 1-indexing and wrap clamps', t => {
|
||||||
|
let args = {DRUM: 1};
|
||||||
|
blocks.playDrumForBeats(args, util);
|
||||||
|
t.strictEqual(playedDrum, 0);
|
||||||
|
|
||||||
|
args = {DRUM: runtime.audioEngine.numDrums + 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();
|
||||||
|
});
|
|
@ -1,18 +1,8 @@
|
||||||
const test = require('tap').test;
|
const test = require('tap').test;
|
||||||
const Sound = require('../../src/blocks/scratch3_sound');
|
const Sound = require('../../src/blocks/scratch3_sound');
|
||||||
let playedSound;
|
let playedSound;
|
||||||
let playedDrum;
|
|
||||||
let playedInstrument;
|
const blocks = new Sound();
|
||||||
const runtime = {
|
|
||||||
audioEngine: {
|
|
||||||
numDrums: 3,
|
|
||||||
numInstruments: 3,
|
|
||||||
instrumentPlayer: {
|
|
||||||
loadInstrument: instrument => (playedInstrument = instrument)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const blocks = new Sound(runtime);
|
|
||||||
const util = {
|
const util = {
|
||||||
target: {
|
target: {
|
||||||
sprite: {
|
sprite: {
|
||||||
|
@ -24,8 +14,7 @@ const util = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
audioPlayer: {
|
audioPlayer: {
|
||||||
playSound: soundId => (playedSound = soundId),
|
playSound: soundId => (playedSound = soundId)
|
||||||
playDrumForBeats: drum => (playedDrum = drum)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -82,30 +71,3 @@ test('playSound prioritizes sound name if given a string', t => {
|
||||||
t.strictEqual(playedSound, 'fourth soundId');
|
t.strictEqual(playedSound, 'fourth soundId');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('playDrum uses 1-indexing and wrap clamps', t => {
|
|
||||||
let args = {DRUM: 1};
|
|
||||||
blocks.playDrumForBeats(args, util);
|
|
||||||
t.strictEqual(playedDrum, 0);
|
|
||||||
|
|
||||||
args = {DRUM: runtime.audioEngine.numDrums + 1};
|
|
||||||
blocks.playDrumForBeats(args, util);
|
|
||||||
t.strictEqual(playedDrum, 0);
|
|
||||||
|
|
||||||
t.end();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('setInstrument uses 1-indexing and wrap clamps', t => {
|
|
||||||
// Stub getSoundState
|
|
||||||
blocks._getSoundState = () => ({});
|
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue