Skip to content

Commit

Permalink
Improved test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Jan 19, 2024
1 parent c316bc9 commit 4305ec6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 21 deletions.
59 changes: 51 additions & 8 deletions test/unit/builders/audiobuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default function waveformDataAudioBufferTests(WaveformData) {
context("given an AudioBuffer", function() {
it("should return a valid waveform", function(done) {
var options = {
audio_buffer: sampleAudioBuffer
audio_buffer: sampleAudioBuffer,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -39,10 +40,9 @@ export default function waveformDataAudioBufferTests(WaveformData) {
});
});

it("should return a valid waveform without using a worker", function(done) {
it("should return a valid waveform using a worker", function(done) {
var options = {
audio_buffer: sampleAudioBuffer,
disable_worker: true
audio_buffer: sampleAudioBuffer
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -61,7 +61,8 @@ export default function waveformDataAudioBufferTests(WaveformData) {
it("should adjust the length of the waveform when using a different scale", function(done) {
var options = {
audio_buffer: sampleAudioBuffer,
scale: 128
scale: 128,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -79,7 +80,8 @@ export default function waveformDataAudioBufferTests(WaveformData) {

it("should return waveform data points", function(done) {
var options = {
audio_buffer: sampleAudioBuffer
audio_buffer: sampleAudioBuffer,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -97,7 +99,8 @@ export default function waveformDataAudioBufferTests(WaveformData) {
it("should return correctly scaled waveform data points", function(done) {
var options = {
audio_buffer: sampleAudioBuffer,
amplitude_scale: 2.0
amplitude_scale: 2.0,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -112,10 +115,50 @@ export default function waveformDataAudioBufferTests(WaveformData) {
});
});

it("should return multiple channels of waveform data points", function(done) {
var options = {
audio_buffer: sampleAudioBuffer,
split_channels: true,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
expect(err).to.not.be.ok;

expect(waveform.channels).to.equal(4);

expect(waveform.channel(0).min_sample(0)).to.equal(-1);
expect(waveform.channel(0).max_sample(0)).to.equal(0);

expect(waveform.channel(1).min_sample(0)).to.equal(-1);
expect(waveform.channel(1).max_sample(0)).to.equal(0);

expect(waveform.channel(2).min_sample(0)).to.equal(-90);
expect(waveform.channel(2).max_sample(0)).to.equal(89);

expect(waveform.channel(3).min_sample(0)).to.equal(-1);
expect(waveform.channel(3).max_sample(0)).to.equal(0);

expect(waveform.channel(0).min_sample(waveform.length - 1)).to.equal(-1);
expect(waveform.channel(0).max_sample(waveform.length - 1)).to.equal(0);

expect(waveform.channel(1).min_sample(waveform.length - 1)).to.equal(-1);
expect(waveform.channel(1).max_sample(waveform.length - 1)).to.equal(0);

expect(waveform.channel(2).min_sample(waveform.length - 1)).to.equal(-90);
expect(waveform.channel(2).max_sample(waveform.length - 1)).to.equal(89);

expect(waveform.channel(3).min_sample(waveform.length - 1)).to.equal(-1);
expect(waveform.channel(3).max_sample(waveform.length - 1)).to.equal(0);
done();
});
});

it("should return 16-bit waveform data", function(done) {
var options = {
audio_buffer: sampleAudioBuffer,
bits: 16
bits: 16,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand Down
35 changes: 22 additions & 13 deletions test/unit/builders/webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
it("should return an error if the audio buffer is invalid", function(done) {
var options = {
audio_context: audioContext,
array_buffer: new ArrayBuffer(1024)
array_buffer: new ArrayBuffer(1024),
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -42,7 +43,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
it("shouldn't cause an unhandledrejection on error", function(done) {
var options = {
audio_context: audioContext,
array_buffer: new ArrayBuffer(1024)
array_buffer: new ArrayBuffer(1024),
disable_worker: true
};

function listener() {
Expand All @@ -62,7 +64,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
it("should only invoke the callback once on error", function(done) {
var options = {
audio_context: audioContext,
array_buffer: new ArrayBuffer(1024)
array_buffer: new ArrayBuffer(1024),
disable_worker: true
};
var count = 0;

Expand All @@ -79,7 +82,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
it("should return a valid waveform", function(done) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer
array_buffer: sampleBuffer,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -96,11 +100,10 @@ export default function waveformDataAudioContextTests(WaveformData) {
});
});

it("should return a valid waveform without using a worker", function(done) {
it("should return a valid waveform using a worker", function(done) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer,
disable_worker: true
array_buffer: sampleBuffer
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -119,7 +122,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
it("should return the decoded audio", function(done) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer
array_buffer: sampleBuffer,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform, audioBuffer) {
Expand All @@ -136,7 +140,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer,
scale: 128
scale: 128,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -155,7 +160,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
it("should return waveform data points", function(done) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer
array_buffer: sampleBuffer,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -176,7 +182,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer,
amplitude_scale: 2.0
amplitude_scale: 2.0,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand All @@ -195,7 +202,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer,
split_channels: true
split_channels: true,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand Down Expand Up @@ -234,7 +242,8 @@ export default function waveformDataAudioContextTests(WaveformData) {
var options = {
audio_context: audioContext,
array_buffer: sampleBuffer,
bits: 16
bits: 16,
disable_worker: true
};

WaveformData.createFromAudio(options, function(err, waveform) {
Expand Down

0 comments on commit 4305ec6

Please sign in to comment.