Skip to content

Commit 37a7644

Browse files
Merge pull request #626 from satyasaibhushan/improving-tests-Gsoc
(Gsoc'21) (Week-1) Fixes broken tests
2 parents 0490632 + 4577368 commit 37a7644

File tree

11 files changed

+867
-507
lines changed

11 files changed

+867
-507
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
},
3636
"parserOptions": {
37-
"ecmaVersion": 6,
37+
"ecmaVersion": 8,
3838
"sourceType": "module",
3939
"allowImportExportEverywhere": true
4040
}

lib/p5.sound.js

Lines changed: 809 additions & 463 deletions
Large diffs are not rendered by default.

lib/p5.sound.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/p5.sound.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/p5.sound.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/soundRecorder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SoundRecorder {
9191
this._inputChannels = 2;
9292
this._outputChannels = 2; // stereo output, even if input is mono
9393

94-
const workletBufferSize = safeBufferSize(1024);
94+
const workletBufferSize = (this.bufferSize = safeBufferSize(1024));
9595

9696
this._workletNode = new AudioWorkletNode(
9797
ac,

test/tests/p5.EQ.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,30 @@ describe('p5.EQ', function () {
3636
expect(eq.bands[2].biquad.type).to.equal('peaking');
3737
});
3838

39-
it('a bands gain value can be changed', function () {
39+
it("a band's gain value can be changed", function () {
4040
const eq = new p5.EQ(8);
4141
expect(eq.bands[2].gain()).to.equal(0);
4242
eq.bands[2].gain(30);
4343
expect(eq.bands[2].gain()).to.equal(30);
4444
});
4545

46-
it('a bands freq value can be changed', function () {
46+
it('a band has correct default value', function () {
47+
const eq = new p5.EQ(8);
48+
setTimeout(() => {
49+
expect(eq.bands[0].freq()).to.equal(100);
50+
}, 100);
51+
});
52+
53+
it("a band's freq value can be changed", function () {
4754
const eq = new p5.EQ(8);
48-
expect(eq.bands[0].freq()).to.equal(100);
4955
eq.bands[0].freq(200);
50-
expect(eq.bands[0].gain()).to.equal(0);
51-
expect(eq.bands[0].freq()).to.equal(200);
56+
setTimeout(() => {
57+
expect(eq.bands[0].gain()).to.equal(0);
58+
expect(eq.bands[0].freq()).to.equal(200);
59+
}, 100);
5260
});
5361

54-
it('a bands type can be changed', function () {
62+
it("a band's type can be changed", function () {
5563
const eq = new p5.EQ();
5664
expect(eq.bands[2]._untoggledType).to.equal('peaking');
5765
eq.bands[2].setType('highshelf');

test/tests/p5.Helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ describe('Testing helpers function', function () {
88

99
it('p5.prototype.midiToFreq helper function', function () {
1010
const freq = p5.prototype.midiToFreq(100);
11-
expect(freq).to.equal(2637.0204553029594);
11+
expect(freq).to.be.approximately(2637.0204553029594, 0.00000000001);
1212
});
1313

1414
it('p5.prototype.noteToFreq helper function', function () {
1515
const freq = p5.prototype.noteToFreq('C4');
16-
expect(freq).to.equal(261.6255653005986);
16+
expect(freq).to.be.approximately(261.6255653005986, 0.00000000001);
1717
});
1818

1919
it('p5.prototype.soundFormats helper function', function () {

test/tests/p5.MonoSynth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ describe('p5.MonoSynth', function () {
1515
expect(monoSynth.oscillator.freq().value).to.equal(110);
1616
monoSynth.dispose();
1717
done();
18-
}, 1);
18+
}, 10);
1919
});
2020
});

test/tests/p5.PolySynth.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ describe('p5.PolySynth', function () {
1212
const polySynth = new p5.PolySynth();
1313
const noteDuration = 0.01;
1414

15-
const noteTriggerTime = audioContext.currentTime;
16-
const noteActiveTime = noteTriggerTime + noteDuration / 2;
17-
const noteDoneTime = noteTriggerTime + noteDuration;
15+
const getTriggerTime = () => audioContext.currentTime;
16+
const getActiveTime = () => getTriggerTime() + noteDuration / 2;
17+
const getDoneTime = () => getTriggerTime() + noteDuration;
1818

19-
expect(polySynth._voicesInUse.getValueAtTime(noteTriggerTime)).to.equal(0);
19+
expect(polySynth._voicesInUse.getValueAtTime(getTriggerTime())).to.equal(0);
2020

2121
polySynth.play('A2', 0, 0, noteDuration);
22-
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(1);
22+
expect(polySynth._voicesInUse.getValueAtTime(getActiveTime())).to.equal(1);
2323
polySynth.play('A3', 0, 0, noteDuration);
24-
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(2);
24+
expect(polySynth._voicesInUse.getValueAtTime(getActiveTime())).to.equal(2);
2525
polySynth.play('A4', 0, 0, noteDuration);
26-
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(3);
26+
expect(polySynth._voicesInUse.getValueAtTime(getActiveTime())).to.equal(3);
2727

28-
expect(polySynth._voicesInUse.getValueAtTime(noteDoneTime)).to.equal(0);
28+
expect(polySynth._voicesInUse.getValueAtTime(getDoneTime())).to.equal(0);
2929

3030
polySynth.dispose();
3131
});

0 commit comments

Comments
 (0)