mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2025-01-07 05:11:55 -05:00
cleanup tests a bit
This commit is contained in:
parent
2bd946423b
commit
e2da92fae7
2 changed files with 9 additions and 10 deletions
|
@ -116,11 +116,11 @@ class SoundPlayer extends EventEmitter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.volumeEffect !== null) {
|
if (this.volumeEffect === null) {
|
||||||
this.volumeEffect.connect(target);
|
|
||||||
} else {
|
|
||||||
this.outputNode.disconnect();
|
this.outputNode.disconnect();
|
||||||
this.outputNode.connect(target.getInputNode());
|
this.outputNode.connect(target.getInputNode());
|
||||||
|
} else {
|
||||||
|
this.volumeEffect.connect(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -39,14 +39,13 @@ tap.test('SoundPlayer', suite => {
|
||||||
|
|
||||||
suite.plan(4);
|
suite.plan(4);
|
||||||
|
|
||||||
suite.test('play initializes and creates chain', t => {
|
suite.test('play initializes and creates source node', t => {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
t.equal(soundPlayer.initialized, false, 'not yet initialized');
|
t.equal(soundPlayer.initialized, false, 'not yet initialized');
|
||||||
soundPlayer.play();
|
soundPlayer.play();
|
||||||
t.equal(soundPlayer.initialized, true, 'now is initialized');
|
t.equal(soundPlayer.initialized, true, 'now is initialized');
|
||||||
let buffer = audioContext.DECODE_AUDIO_DATA_RESULT.toJSON();
|
|
||||||
t.deepEqual(soundPlayer.outputNode.toJSON(), {
|
t.deepEqual(soundPlayer.outputNode.toJSON(), {
|
||||||
buffer,
|
buffer: audioContext.DECODE_AUDIO_DATA_RESULT.toJSON(),
|
||||||
inputs: [],
|
inputs: [],
|
||||||
loop: false,
|
loop: false,
|
||||||
loopEnd: 0,
|
loopEnd: 0,
|
||||||
|
@ -65,7 +64,7 @@ tap.test('SoundPlayer', suite => {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
soundPlayer.play();
|
soundPlayer.play();
|
||||||
soundPlayer.connect(audioEngine);
|
soundPlayer.connect(audioEngine);
|
||||||
t.deepEqual(audioEngine.inputNode.toJSON().inputs, [
|
t.deepEqual(help.engineInputs, [
|
||||||
soundPlayer.outputNode.toJSON()
|
soundPlayer.outputNode.toJSON()
|
||||||
], 'output node connects to input node');
|
], 'output node connects to input node');
|
||||||
t.end();
|
t.end();
|
||||||
|
@ -80,7 +79,7 @@ tap.test('SoundPlayer', suite => {
|
||||||
audioContext.$processTo(0);
|
audioContext.$processTo(0);
|
||||||
soundPlayer.stop();
|
soundPlayer.stop();
|
||||||
t.equal(soundPlayer.outputNode, null, 'nullify outputNode immediately (taken sound is stopping)');
|
t.equal(soundPlayer.outputNode, null, 'nullify outputNode immediately (taken sound is stopping)');
|
||||||
t.deepEqual(audioEngine.inputNode.toJSON().inputs, [{
|
t.deepEqual(help.engineInputs, [{
|
||||||
name: 'GainNode',
|
name: 'GainNode',
|
||||||
gain: {
|
gain: {
|
||||||
value: 1,
|
value: 1,
|
||||||
|
@ -90,13 +89,13 @@ tap.test('SoundPlayer', suite => {
|
||||||
}], 'output node connects to gain node to input node');
|
}], 'output node connects to gain node to input node');
|
||||||
|
|
||||||
audioContext.$processTo(audioEngine.DECAY_TIME / 2);
|
audioContext.$processTo(audioEngine.DECAY_TIME / 2);
|
||||||
const engineInputs = audioEngine.inputNode.toJSON().inputs;
|
const engineInputs = help.engineInputs;
|
||||||
t.notEqual(engineInputs[0].gain.value, 1, 'gain value should not be 1');
|
t.notEqual(engineInputs[0].gain.value, 1, 'gain value should not be 1');
|
||||||
t.notEqual(engineInputs[0].gain.value, 0, 'gain value should not be 0');
|
t.notEqual(engineInputs[0].gain.value, 0, 'gain value should not be 0');
|
||||||
t.equal(outputNode.$state, 'PLAYING');
|
t.equal(outputNode.$state, 'PLAYING');
|
||||||
|
|
||||||
audioContext.$processTo(audioEngine.DECAY_TIME);
|
audioContext.$processTo(audioEngine.DECAY_TIME);
|
||||||
t.deepEqual(audioEngine.inputNode.toJSON().inputs, [{
|
t.deepEqual(help.engineInputs, [{
|
||||||
name: 'GainNode',
|
name: 'GainNode',
|
||||||
gain: {
|
gain: {
|
||||||
value: 0,
|
value: 0,
|
||||||
|
|
Loading…
Reference in a new issue