diff --git a/test/SoundPlayer.js b/test/SoundPlayer.js index 5d7a98e..c55fe6f 100644 --- a/test/SoundPlayer.js +++ b/test/SoundPlayer.js @@ -17,14 +17,16 @@ tap.test('SoundPlayer', suite => { } }; - suite.beforeEach(async () => { + suite.beforeEach(() => { audioContext = new AudioContext(); audioEngine = new AudioEngine(audioContext); // sound will be 0.1 seconds long audioContext.DECODE_AUDIO_DATA_RESULT = audioContext.createBuffer(2, 4410, 44100); audioContext.DECODE_AUDIO_DATA_FAILED = false; const data = new Uint8Array(44100); - soundPlayer = await audioEngine.decodeSoundPlayer({data}); + return audioEngine.decodeSoundPlayer({data}).then(result => { + soundPlayer = result; + }); }); suite.afterEach(() => { @@ -114,55 +116,55 @@ tap.test('SoundPlayer', suite => { soundPlayer.play(); soundPlayer.finished().then(() => log.push('play 1 finished')); soundPlayer.connect(audioEngine); - let oldPlayerNode; + const firstPlayNode = soundPlayer.outputNode; + + audioContext.$processTo(0.005); return Promise.resolve() - .then(() => { + .then(() => { - audioContext.$processTo(0.005); - t.equal(soundPlayer.outputNode.$state, 'PLAYING'); + t.equal(soundPlayer.outputNode.$state, 'PLAYING'); - oldPlayerNode = soundPlayer.outputNode; - soundPlayer.play(); - soundPlayer.finished().then(() => log.push('play 2 finished')); + soundPlayer.play(); + soundPlayer.finished().then(() => log.push('play 2 finished')); // wait for a micro-task loop to fire our previous events - return Promise.resolve(); - }) - .then(() => { + return Promise.resolve(); + }) + .then(() => { - t.equal(log[0], 'play 1 finished'); - t.notEqual(soundPlayer.outputNode, oldPlayerNode, 'created new player node'); + t.equal(log[0], 'play 1 finished'); + t.notEqual(soundPlayer.outputNode, firstPlayNode, 'created new player node'); - t.equal(help.engineInputs.length, 2, 'there should be 2 players connected'); - t.equal(oldPlayerNode.$state, 'PLAYING'); - t.equal(soundPlayer.outputNode.$state, 'PLAYING'); - t.equal(help.engineInputs[0].gain.value, 1, 'old sound connectect to gain node with volume 1'); + t.equal(help.engineInputs.length, 2, 'there should be 2 players connected'); + t.equal(firstPlayNode.$state, 'PLAYING'); + t.equal(soundPlayer.outputNode.$state, 'PLAYING'); + t.equal(help.engineInputs[0].gain.value, 1, 'old sound connectect to gain node with volume 1'); - audioContext.$processTo(audioContext.currentTime + 0.001); - t.notEqual(help.engineInputs[0].gain.value, 1, + audioContext.$processTo(audioContext.currentTime + 0.001); + t.notEqual(help.engineInputs[0].gain.value, 1, 'old sound connected to gain node which will fade'); - audioContext.$processTo(audioContext.currentTime + audioEngine.DECAY_TIME + 0.001); - t.equal(soundPlayer.outputNode.$state, 'PLAYING'); - t.equal(oldPlayerNode.$state, 'FINISHED'); + audioContext.$processTo(audioContext.currentTime + audioEngine.DECAY_TIME + 0.001); + t.equal(soundPlayer.outputNode.$state, 'PLAYING'); + t.equal(firstPlayNode.$state, 'FINISHED'); - t.equal(help.engineInputs[0].gain.value, 0, 'faded old sound to 0'); + t.equal(help.engineInputs[0].gain.value, 0, 'faded old sound to 0'); - t.equal(log.length, 1); - audioContext.$processTo(audioContext.currentTime + 0.2); + t.equal(log.length, 1); + audioContext.$processTo(audioContext.currentTime + 0.2); // wait for a micro-task loop to fire our previous events - return Promise.resolve(); - }) - .then(() => { + return Promise.resolve(); + }) + .then(() => { - t.equal(log[1], 'play 2 finished'); - t.equal(help.engineInputs.length, 1, 'old sound disconneted itself after done'); - t.equal(log.length, 2); + t.equal(log[1], 'play 2 finished'); + t.equal(help.engineInputs.length, 1, 'old sound disconneted itself after done'); + t.equal(log.length, 2); - t.end(); - }); + t.end(); + }); }); suite.end();