Skip to content

Commit 2fd6a90

Browse files
endurance21Divyanshu Raj
andauthored
modernized the TESTING architecture of the codebase { GSOC} (#541)
* modernized the TESTING architecture of the codebase * added sinon.js support for soundRecorder.js testing and removed use strict declaration * * src/audioWorklet/index.js - added p5.audioWorkletInitilized promise to ensure proper loading of AudioWorklet modules for * sounFile processor * Oscillator processor * Amplitude processor * test/index.js - then used dynamic import to import the tests after each of worklet processors have been loaded successfully * solved loading of audioWorklet processors in testing by use of p5 instance mode * fixed audioworklet import Co-authored-by: Divyanshu Raj <[email protected]>
1 parent a7d8cb0 commit 2fd6a90

31 files changed

+1059
-43858
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"amdclean": "~2.0",
1414
"babel-loader": "^8.0.6",
1515
"babel-plugin-preval": "^3.0.1",
16+
"chai": "3.4.1",
1617
"eslint-config-prettier": "^6.11.0",
1718
"eslint-plugin-prettier": "^3.1.3",
1819
"grunt": "~0.4.5",
@@ -24,6 +25,7 @@
2425
"grunt-mocha": "^1.0.4",
2526
"grunt-open": "^0.2.3",
2627
"grunt-webpack": "^3.1.3",
28+
"mocha": "2.3.4",
2729
"prettier": "2.0.5",
2830
"raw-loader": "^3.0.0",
2931
"tslint-config-prettier": "^1.18.0",
@@ -35,6 +37,7 @@
3537
"dependencies": {
3638
"audioworklet-polyfill": "^1.1.2",
3739
"p5": "1.0.0",
40+
"sinon": "^9.0.3",
3841
"startaudiocontext": "^1.2.1",
3942
"tone": "0.10.0"
4043
},

src/audioWorklet/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const moduleSources = [
66
];
77
const ac = p5sound.audiocontext;
88

9-
let initializedAudioWorklets = false;
109

1110
function loadAudioWorkletModules() {
1211
return Promise.all(
@@ -19,7 +18,6 @@ function loadAudioWorkletModules() {
1918
}
2019

2120
p5.prototype.registerMethod('init', function () {
22-
if (initializedAudioWorklets) return;
2321
// ensure that a preload function exists so that p5 will wait for preloads to finish
2422
if (!this.preload && !window.preload) {
2523
this.preload = function () {};
@@ -28,7 +26,6 @@ p5.prototype.registerMethod('init', function () {
2826
// use p5's preload system to load necessary AudioWorklet modules before setup()
2927
this._incrementPreload();
3028
const onWorkletModulesLoad = function () {
31-
initializedAudioWorklets = true;
3229
this._decrementPreload();
3330
}.bind(this);
3431
loadAudioWorkletModules().then(onWorkletModulesLoad);

test/index.html

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
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-
<script>
8-
window.setup = function setup() {};
9-
new p5();
10-
</script>
11-
<script src="./testDeps/mocha.js"></script>
12-
<script data-main="test.js" src="./testDeps/require.js"></script>
13-
<link rel="stylesheet" href="./testDeps/mocha.css" />
14-
</head>
15-
<body>
16-
<div id="mocha"></div>
17-
<script>
18-
mocha.setup('bdd')
19-
</script>
20-
</body>
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>
2116
</html>

test/setup.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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');
4+
5+
let test_has_run = false;
6+
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.masterVolume(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);

test/test.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)