Skip to content

Commit 49a6f89

Browse files
committed
(chore) : Changed test filing structure
Signed-off-by: Abhijay Jain <[email protected]>
1 parent de83cd8 commit 49a6f89

33 files changed

+96
-132
lines changed

test/index.html

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
11
<html>
2-
<head>
3-
<meta charset="utf-8" />
4-
<title>TESTS</title>
5-
<script src="../lib/p5.js"></script>
6-
<script src="../lib/p5.sound.js"></script>
7-
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
8-
<script src="../node_modules/mocha/mocha.js"></script>
9-
<script src="../node_modules/chai/chai.js"></script>
10-
<script src="../node_modules/sinon/pkg/sinon.js"></script>
11-
</head>
12-
<body>
13-
<div id="mocha"></div>
14-
<script src="./setup.js" type="module"></script>
15-
</body>
16-
</html>
2+
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>TESTS</title>
6+
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
7+
<script src="../lib/p5.js"></script>
8+
<script src="../lib/p5.sound.js"></script>
9+
</head>
10+
11+
<body>
12+
<div id="mocha"></div>
13+
<script src="../node_modules/mocha/mocha.js" type="text/javascript" charset="utf-8"></script>
14+
<script src="../node_modules/chai/chai.js"></script>
15+
<script src="../node_modules/sinon/pkg/sinon.js"></script>
16+
<script src="./setup.js"></script>
17+
18+
<script src="./tests.js" type="text/javascript"></script>
19+
20+
<script type="text/javascript">
21+
const startTest = () => {
22+
let test_has_run = false;
23+
document.getElementById('mocha').innerHTML = 'click to begin tests';
24+
25+
// chromes autoplay policy requires a user interaction
26+
// before the audiocontext can activate
27+
const mousePressed = () => {
28+
if (!test_has_run) {
29+
document.getElementById('mocha').innerHTML = '';
30+
p5._throwValidationErrors = true;
31+
p5.prototype.outputVolume(0);
32+
p5.prototype.userStartAudio();
33+
mocha.run();
34+
test_has_run = true;
35+
}
36+
};
37+
document.addEventListener('click', mousePressed, false);
38+
};
39+
40+
//operating p5 in instance mode ( read more about it here - https://github.com/processing/p5.js/wiki/Global-and-instance-mode )
41+
const s = (sketch) => {
42+
sketch.setup = () => {
43+
mocha.reporter('html');
44+
mocha.setup('bdd');
45+
const expect = chai.expect;
46+
startTest();
47+
};
48+
};
49+
50+
new p5(s);
51+
</script>
52+
</body>
53+
</html>

test/setup.js

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
1-
const startTest = () => {
2-
//dynamic importing the modules , this ensures that tests must run after audioWorklet processors have been loaded properly
3-
import('./tests.js');
1+
mocha.setup('bdd');
42

5-
let test_has_run = false;
3+
new p5();
4+
p5._throwValidationErrors = true;
5+
p5.prototype.outputVolume(0);
6+
p5.prototype.userStartAudio();
67

7-
document.getElementById('mocha').innerHTML = 'click to begin tests';
8-
9-
// chromes autoplay policy requires a user interaction
10-
// before the audiocontext can activate
11-
const mousePressed = () => {
12-
if (!test_has_run) {
13-
document.getElementById('mocha').innerHTML = '';
14-
p5.prototype.outputVolume(0);
15-
p5.prototype.userStartAudio();
16-
mocha.run();
17-
test_has_run = true;
18-
}
19-
};
20-
document.addEventListener('click', mousePressed, false);
21-
};
22-
23-
//operating p5 in instance mode ( read more about it here - https://github.com/processing/p5.js/wiki/Global-and-instance-mode )
24-
const s = (sketch) => {
25-
sketch.setup = () => {
26-
mocha.setup('bdd');
27-
startTest();
28-
};
29-
};
30-
31-
new p5(s);
8+
const expect = chai.expect;

test/tests.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1-
import('./tests/main.js');
2-
import('./tests/p5.Helpers.js');
3-
import('./tests/p5.PeakDetect.js');
4-
import('./tests/p5.OnsetDetect.js');
5-
import('./tests/p5.Distortion.js');
6-
import('./tests/p5.AudioContext.js');
7-
import('./tests/p5.Looper.js');
8-
import('./tests/p5.Metro.js');
9-
import('./tests/p5.Effect.js');
10-
import('./tests/p5.Filter.js');
11-
import('./tests/p5.Gain.js');
12-
import('./tests/p5.FFT.js');
13-
import('./tests/p5.SoundLoop.js');
14-
import('./tests/p5.Compressor.js');
15-
import('./tests/p5.EQ.js');
16-
import('./tests/p5.AudioIn.js');
17-
import('./tests/p5.AudioVoice.js');
18-
import('./tests/p5.MonoSynth.js');
19-
import('./tests/p5.PolySynth.js');
20-
import('./tests/p5.SoundRecorder.js');
21-
import('./tests/p5.SoundFile.js');
22-
import('./tests/p5.Amplitude.js');
23-
import('./tests/p5.Oscillator.js');
24-
import('./tests/p5.Envelope.js');
25-
import('./tests/p5.Pulse.js');
26-
import('./tests/p5.Noise.js');
27-
import('./tests/p5.Panner.js');
28-
import('./tests/p5.Panner3d.js');
29-
import('./tests/p5.Delay.js');
30-
import('./tests/p5.Reverb.js');
31-
import('./tests/p5.Listener3d.js');
1+
let spec = [
2+
'./tests/main.js',
3+
'./tests/p5.Helpers.js',
4+
'./tests/p5.PeakDetect.js',
5+
'./tests/p5.OnsetDetect.js',
6+
'./tests/p5.Distortion.js',
7+
'./tests/p5.AudioContext.js',
8+
'./tests/p5.Looper.js',
9+
'./tests/p5.Metro.js',
10+
'./tests/p5.Effect.js',
11+
'./tests/p5.Filter.js',
12+
'./tests/p5.Gain.js',
13+
'./tests/p5.FFT.js',
14+
'./tests/p5.SoundLoop.js',
15+
'./tests/p5.Compressor.js',
16+
'./tests/p5.EQ.js',
17+
'./tests/p5.AudioIn.js',
18+
'./tests/p5.AudioVoice.js',
19+
'./tests/p5.MonoSynth.js',
20+
'./tests/p5.PolySynth.js',
21+
'./tests/p5.SoundRecorder.js',
22+
'./tests/p5.SoundFile.js',
23+
'./tests/p5.Amplitude.js',
24+
'./tests/p5.Oscillator.js',
25+
'./tests/p5.Envelope.js',
26+
'./tests/p5.Pulse.js',
27+
'./tests/p5.Noise.js',
28+
'./tests/p5.Panner.js',
29+
'./tests/p5.Panner3d.js',
30+
'./tests/p5.Delay.js',
31+
'./tests/p5.Reverb.js',
32+
'./tests/p5.Listener3d.js',
33+
];
34+
35+
spec.map((file) => {
36+
var string = ['<script src="./', file, '" type="text/javascript" ></script>'];
37+
document.write(string.join(''));
38+
});

test/tests/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const expect = chai.expect;
21
describe('main output', function () {
32
it('can initiate main class', function () {
43
expect(p5.soundOut.input).to.have.property('gain');

test/tests/p5.Amplitude.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Amplitude', function () {
42
this.timeout(1000);
53

test/tests/p5.AudioContext.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.AudioContext', function () {
42
describe('getAudioContext', function () {
53
it('returns a audioContext', function () {

test/tests/p5.AudioIn.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.AudioIn', function () {
42
let mic;
53
beforeEach(function () {

test/tests/p5.AudioVoice.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.AudioVoice', function () {
42
it('can be created and disposed', function () {
53
let av = new p5.AudioVoice();

test/tests/p5.Compressor.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Compressor', function () {
42
it('can be created and disposed', function () {
53
let compressor = new p5.Compressor();

test/tests/p5.Delay.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Delay', function () {
42
let noise = new p5.Noise();
53
it('can be created', function (done) {

test/tests/p5.Distortion.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Distortion', function () {
42
it('can be created and disposed', function () {
53
let distortion = new p5.Distortion();

test/tests/p5.EQ.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.EQ', function () {
42
it('can be created and disposed', function () {
53
const origSoundArrayLength = p5.soundOut.soundArray.length;

test/tests/p5.Effect.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Effect', function () {
42
it('can be created and disposed', function () {
53
const effect = new p5.Effect();

test/tests/p5.Envelope.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Envelope', function () {
42
it('can be created and disposed without any arguments', function () {
53
let envelope = new p5.Envelope();

test/tests/p5.FFT.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.FFT', function () {
42
it('can be created and disposed', function () {
53
let fft = new p5.FFT();

test/tests/p5.Filter.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Filter', function () {
42
it('can be created and disposed', function () {
53
let filter = new p5.Filter();

test/tests/p5.Gain.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const expect = chai.expect;
21
let gain;
32

43
describe('p5.Gain', function () {

test/tests/p5.Helpers.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('Helpers functions', function () {
42
it('sampleRate can get sample rate', function () {
53
expect(p5.prototype.sampleRate()).to.be.a('number');

test/tests/p5.Listener3d.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Listener3D', function () {
42
let listener3d;
53
it('can be created', function () {

test/tests/p5.Looper.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Looper', function () {
42
it('setBPM sets the BPM for all parts', function () {
53
let part1 = new p5.Part();

test/tests/p5.Metro.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const expect = chai.expect;
21
let metro;
32

43
describe('p5.Metro', function () {

test/tests/p5.MonoSynth.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.MonoSynth', function () {
42
it('can be created and disposed', function () {
53
const monoSynth = new p5.MonoSynth();

test/tests/p5.Noise.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Noise', function () {
42
it('can be created and disposed', function () {
53
let noise = new p5.Noise();

test/tests/p5.OnsetDetect.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.OnsetDetect', function () {
42
it('can be initalized ', function () {
53
const onsetDetect = new p5.OnsetDetect(40, 120, 0.8, () => {});

test/tests/p5.Oscillator.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Oscillator', function () {
42
this.timeout(1000);
53

test/tests/p5.Panner.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// const expect = chai.expect;
2-
31
describe('p5.Panner', function () {
42
let ac, output, input;
53
beforeEach(function () {

test/tests/p5.Panner3d.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Panner3d', function () {
42
it('can be created and disposed', function () {
53
let panner3d = new p5.Panner3D();

test/tests/p5.PeakDetect.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.PeakDetect', function () {
42
it('can be initialized without any arguments', function () {
53
const peakDetect = new p5.PeakDetect();

test/tests/p5.PolySynth.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.PolySynth', function () {
42
const audioContext = p5.prototype.getAudioContext();
53

test/tests/p5.Pulse.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.Pulse', function () {
42
it('can be created without any arguments', function () {
53
let pulse = new p5.Pulse();

test/tests/p5.Reverb.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
p5.prototype.soundFormats('mp3', 'ogg');
42
let soundFile = p5.prototype.loadSound('./testAudio/drum');
53

test/tests/p5.SoundLoop.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.SoundLoop', function () {
42
it('can be initialized without any arguments', function () {
53
let sloop = new p5.SoundLoop();

test/tests/p5.SoundRecorder.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const expect = chai.expect;
2-
31
describe('p5.SoundRecorder', function () {
42
let inputSoundFile;
53
let writeFileSub;

0 commit comments

Comments
 (0)