Skip to content

Commit 4d65d7c

Browse files
authored
requiring user interaction before running tests, per chrome autoplay policy (#511)
* requiring user interaction before running tests, resolves an issue with chrome and it's autoplay policy * using p5 userStartAudio() for test runner
1 parent 0716ceb commit 4d65d7c

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

test/test.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require.config({
2-
baseUrl:'./',
3-
paths : {
4-
'lib' : '../lib',
5-
'chai' : './testDeps/chai',
2+
baseUrl: './',
3+
paths: {
4+
'lib': '../lib',
5+
'chai': './testDeps/chai',
66
'sinon': './testDeps/sinon'
77
}
88
});
@@ -13,7 +13,7 @@ var allTests = [
1313
'tests/p5.Amplitude',
1414
'tests/p5.Oscillator',
1515
'tests/p5.Distortion',
16-
'tests/p5.Effect',
16+
'tests/p5.Effect',
1717
'tests/p5.Filter',
1818
'tests/p5.FFT',
1919
'tests/p5.Compressor',
@@ -27,6 +27,21 @@ var allTests = [
2727

2828
p5.prototype.masterVolume(0);
2929

30-
require(allTests, function(){
31-
mocha.run();
30+
var test_has_run = false;
31+
32+
require(allTests, function () {
33+
document.getElementById('mocha').innerHTML = 'click to begin tests';
34+
35+
// chromes autoplay policy requires a user interaction
36+
// before the audiocontext can activate
37+
function mousePressed() {
38+
if (!test_has_run) {
39+
document.getElementById('mocha').innerHTML = '';
40+
p5.prototype.userStartAudio();
41+
mocha.run();
42+
test_has_run = true;
43+
}
44+
}
45+
46+
document.addEventListener('click', mousePressed, false);
3247
});

0 commit comments

Comments
 (0)