Skip to content

Commit

Permalink
(chore) : Changed test filing structure
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijay Jain <[email protected]>
  • Loading branch information
Abhijay007 committed Jan 20, 2023
1 parent de83cd8 commit 49a6f89
Show file tree
Hide file tree
Showing 33 changed files with 96 additions and 132 deletions.
67 changes: 52 additions & 15 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
<html>
<head>
<meta charset="utf-8" />
<title>TESTS</title>
<script src="../lib/p5.js"></script>
<script src="../lib/p5.sound.js"></script>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
</head>
<body>
<div id="mocha"></div>
<script src="./setup.js" type="module"></script>
</body>
</html>

<head>
<meta charset="utf-8" />
<title>TESTS</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<script src="../lib/p5.js"></script>
<script src="../lib/p5.sound.js"></script>
</head>

<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/sinon/pkg/sinon.js"></script>
<script src="./setup.js"></script>

<script src="./tests.js" type="text/javascript"></script>

<script type="text/javascript">
const startTest = () => {
let test_has_run = false;
document.getElementById('mocha').innerHTML = 'click to begin tests';

// chromes autoplay policy requires a user interaction
// before the audiocontext can activate
const mousePressed = () => {
if (!test_has_run) {
document.getElementById('mocha').innerHTML = '';
p5._throwValidationErrors = true;
p5.prototype.outputVolume(0);
p5.prototype.userStartAudio();
mocha.run();
test_has_run = true;
}
};
document.addEventListener('click', mousePressed, false);
};

//operating p5 in instance mode ( read more about it here - https://github.com/processing/p5.js/wiki/Global-and-instance-mode )
const s = (sketch) => {
sketch.setup = () => {
mocha.reporter('html');
mocha.setup('bdd');
const expect = chai.expect;
startTest();
};
};

new p5(s);
</script>
</body>
</html>
35 changes: 6 additions & 29 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
const startTest = () => {
//dynamic importing the modules , this ensures that tests must run after audioWorklet processors have been loaded properly
import('./tests.js');
mocha.setup('bdd');

let test_has_run = false;
new p5();
p5._throwValidationErrors = true;
p5.prototype.outputVolume(0);
p5.prototype.userStartAudio();

document.getElementById('mocha').innerHTML = 'click to begin tests';

// chromes autoplay policy requires a user interaction
// before the audiocontext can activate
const mousePressed = () => {
if (!test_has_run) {
document.getElementById('mocha').innerHTML = '';
p5.prototype.outputVolume(0);
p5.prototype.userStartAudio();
mocha.run();
test_has_run = true;
}
};
document.addEventListener('click', mousePressed, false);
};

//operating p5 in instance mode ( read more about it here - https://github.com/processing/p5.js/wiki/Global-and-instance-mode )
const s = (sketch) => {
sketch.setup = () => {
mocha.setup('bdd');
startTest();
};
};

new p5(s);
const expect = chai.expect;
69 changes: 38 additions & 31 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import('./tests/main.js');
import('./tests/p5.Helpers.js');
import('./tests/p5.PeakDetect.js');
import('./tests/p5.OnsetDetect.js');
import('./tests/p5.Distortion.js');
import('./tests/p5.AudioContext.js');
import('./tests/p5.Looper.js');
import('./tests/p5.Metro.js');
import('./tests/p5.Effect.js');
import('./tests/p5.Filter.js');
import('./tests/p5.Gain.js');
import('./tests/p5.FFT.js');
import('./tests/p5.SoundLoop.js');
import('./tests/p5.Compressor.js');
import('./tests/p5.EQ.js');
import('./tests/p5.AudioIn.js');
import('./tests/p5.AudioVoice.js');
import('./tests/p5.MonoSynth.js');
import('./tests/p5.PolySynth.js');
import('./tests/p5.SoundRecorder.js');
import('./tests/p5.SoundFile.js');
import('./tests/p5.Amplitude.js');
import('./tests/p5.Oscillator.js');
import('./tests/p5.Envelope.js');
import('./tests/p5.Pulse.js');
import('./tests/p5.Noise.js');
import('./tests/p5.Panner.js');
import('./tests/p5.Panner3d.js');
import('./tests/p5.Delay.js');
import('./tests/p5.Reverb.js');
import('./tests/p5.Listener3d.js');
let spec = [
'./tests/main.js',
'./tests/p5.Helpers.js',
'./tests/p5.PeakDetect.js',
'./tests/p5.OnsetDetect.js',
'./tests/p5.Distortion.js',
'./tests/p5.AudioContext.js',
'./tests/p5.Looper.js',
'./tests/p5.Metro.js',
'./tests/p5.Effect.js',
'./tests/p5.Filter.js',
'./tests/p5.Gain.js',
'./tests/p5.FFT.js',
'./tests/p5.SoundLoop.js',
'./tests/p5.Compressor.js',
'./tests/p5.EQ.js',
'./tests/p5.AudioIn.js',
'./tests/p5.AudioVoice.js',
'./tests/p5.MonoSynth.js',
'./tests/p5.PolySynth.js',
'./tests/p5.SoundRecorder.js',
'./tests/p5.SoundFile.js',
'./tests/p5.Amplitude.js',
'./tests/p5.Oscillator.js',
'./tests/p5.Envelope.js',
'./tests/p5.Pulse.js',
'./tests/p5.Noise.js',
'./tests/p5.Panner.js',
'./tests/p5.Panner3d.js',
'./tests/p5.Delay.js',
'./tests/p5.Reverb.js',
'./tests/p5.Listener3d.js',
];

spec.map((file) => {
var string = ['<script src="./', file, '" type="text/javascript" ></script>'];
document.write(string.join(''));
});
1 change: 0 additions & 1 deletion test/tests/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const expect = chai.expect;
describe('main output', function () {
it('can initiate main class', function () {
expect(p5.soundOut.input).to.have.property('gain');
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Amplitude.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Amplitude', function () {
this.timeout(1000);

Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.AudioContext.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.AudioContext', function () {
describe('getAudioContext', function () {
it('returns a audioContext', function () {
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.AudioIn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.AudioIn', function () {
let mic;
beforeEach(function () {
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.AudioVoice.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.AudioVoice', function () {
it('can be created and disposed', function () {
let av = new p5.AudioVoice();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Compressor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Compressor', function () {
it('can be created and disposed', function () {
let compressor = new p5.Compressor();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Delay.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Delay', function () {
let noise = new p5.Noise();
it('can be created', function (done) {
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Distortion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Distortion', function () {
it('can be created and disposed', function () {
let distortion = new p5.Distortion();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.EQ.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.EQ', function () {
it('can be created and disposed', function () {
const origSoundArrayLength = p5.soundOut.soundArray.length;
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Effect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Effect', function () {
it('can be created and disposed', function () {
const effect = new p5.Effect();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Envelope.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Envelope', function () {
it('can be created and disposed without any arguments', function () {
let envelope = new p5.Envelope();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.FFT.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.FFT', function () {
it('can be created and disposed', function () {
let fft = new p5.FFT();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Filter', function () {
it('can be created and disposed', function () {
let filter = new p5.Filter();
Expand Down
1 change: 0 additions & 1 deletion test/tests/p5.Gain.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const expect = chai.expect;
let gain;

describe('p5.Gain', function () {
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('Helpers functions', function () {
it('sampleRate can get sample rate', function () {
expect(p5.prototype.sampleRate()).to.be.a('number');
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Listener3d.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Listener3D', function () {
let listener3d;
it('can be created', function () {
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Looper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Looper', function () {
it('setBPM sets the BPM for all parts', function () {
let part1 = new p5.Part();
Expand Down
1 change: 0 additions & 1 deletion test/tests/p5.Metro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const expect = chai.expect;
let metro;

describe('p5.Metro', function () {
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.MonoSynth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.MonoSynth', function () {
it('can be created and disposed', function () {
const monoSynth = new p5.MonoSynth();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Noise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Noise', function () {
it('can be created and disposed', function () {
let noise = new p5.Noise();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.OnsetDetect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.OnsetDetect', function () {
it('can be initalized ', function () {
const onsetDetect = new p5.OnsetDetect(40, 120, 0.8, () => {});
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Oscillator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Oscillator', function () {
this.timeout(1000);

Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Panner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// const expect = chai.expect;

describe('p5.Panner', function () {
let ac, output, input;
beforeEach(function () {
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Panner3d.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Panner3d', function () {
it('can be created and disposed', function () {
let panner3d = new p5.Panner3D();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.PeakDetect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.PeakDetect', function () {
it('can be initialized without any arguments', function () {
const peakDetect = new p5.PeakDetect();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.PolySynth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.PolySynth', function () {
const audioContext = p5.prototype.getAudioContext();

Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Pulse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.Pulse', function () {
it('can be created without any arguments', function () {
let pulse = new p5.Pulse();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.Reverb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

p5.prototype.soundFormats('mp3', 'ogg');
let soundFile = p5.prototype.loadSound('./testAudio/drum');

Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.SoundLoop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.SoundLoop', function () {
it('can be initialized without any arguments', function () {
let sloop = new p5.SoundLoop();
Expand Down
2 changes: 0 additions & 2 deletions test/tests/p5.SoundRecorder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const expect = chai.expect;

describe('p5.SoundRecorder', function () {
let inputSoundFile;
let writeFileSub;
Expand Down

0 comments on commit 49a6f89

Please sign in to comment.