Sitelet https://github.com/processing/p5.js-sound/pull/541
Skip to content

modernized the TESTING architecture of the codebase { GSOC} - #541

Merged
endurance21 merged 7 commits into
processing:masterfrom
endurance21:testingFinal
Feb 4, 2021
Merged

endurance21 merged 7 commits into
processing:masterfrom
endurance21:testingFinal

Conversation

@endurance21

Copy link
Copy Markdown
Collaborator

MORE CLEANER AND INTUITIVE TESTING ARCHITECTURE

  • getting rid of requirejs .finally !

  • used es6 imports

  • used npm to download "chai" and "mocha" and removed the cached version in test/testDeps/chai.js , test/testDeps/mocha.js
    thus reducing the size of the codebase !

  • can be further linked to karma.js for headless testing ! { future goals}

  • can be further used for integrating in CI environment !

@endurance21

Copy link
Copy Markdown
Collaborator Author

@therewasaguy @kyle1james
this one for the testing architecture !

for now i have removed sinon.js ,from test/testDeps/sinon.js , i would like to hear some suggestions about its requirements for unit testing now and in future!

@therewasaguy therewasaguy left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thus reducing the size of the codebase

Seriously! This is awesome Screen Shot 2020-08-24 at 12 16 43 AM

Aside from a couple minor comments, the only real issue is that this isn't working on Firefox (79.0). Getting this error

Uncaught DOMException: AudioWorkletNode constructor: Unknown AudioWorklet name 'sound-file-processor'

I suspect it has something to do with the way we're importing the audio worklet modules inline with raw-loader here

const moduleSources = [
require('raw-loader!./recorderProcessor').default,
require('raw-loader!./soundFileProcessor').default,
require('raw-loader!./amplitudeProcessor').default,
];

It's possible that raw-loader doesn't work well with firefox <script ... type="module">

Hoping for a quick fix, I tried upgrading the raw-loader dependency to 4.0.1 but that doesn't seem to resolve the issue...

UPDATE

seems like raw-loader is working as expected, it's just loading the modules after we need them

p5.prototype.registerMethod('init', function () {
if (initializedAudioWorklets) return;
// ensure that a preload function exists so that p5 will wait for preloads to finish
if (!this.preload && !window.preload) {
this.preload = function () {};
}
// use p5's preload system to load necessary AudioWorklet modules before setup()
this._incrementPreload();
const onWorkletModulesLoad = function () {
initializedAudioWorklets = true;
this._decrementPreload();
}.bind(this);
loadAudioWorkletModules().then(onWorkletModulesLoad);

Comment thread test/tests/p5.Amplitude.js Outdated
Comment thread test/tests/p5.Amplitude.js
Comment thread test/index.html Outdated
@therewasaguy

therewasaguy commented Aug 24, 2020 •

Copy link
Copy Markdown
Member

alright, I think the issue with Firefox is actually an issue with how we've structured some of the tests. For example, I've commented out all of the import statements in test.js except for tests/p5.Master.js and that test runs just fine. Meanwhile tests/p5.SoundFile.js has a problem. The issue is that we're creating a p5.Amplitude (which needs an AudioWorklet module) before the p5 init method has completed, and for some reason Firefox is the only browser that hasn't registered the AudioWorklet modules by this point.

We can fix this by creating the amplitude as part of the test lifecycle, wrapping this

var a = new p5.Amplitude();

in a before method

  var a;

  before(() => {
    a = new p5.Amplitude();
  });

@endurance21

Copy link
Copy Markdown
Collaborator Author

@therewasaguy added sinon.js for as it was used inside test/tests/p5.soundRecorder.js

alos removed
use strict keyword

Comment thread test/tests/p5.Oscillator.js
Comment thread test/tests/p5.SoundFile.js
@endurance21

Copy link
Copy Markdown
Collaborator Author

@therewasaguy

this audioWorklet is not loading at the correct time of its access by p5.oscilllator and other processors .
and causing the problem .and mocha hooks is not enough to fix them i see.
This is the problem !
audioWorklet

Divyanshu Raj and others added 2 commits October 1, 2020 02:31
…e 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
@endurance21

Copy link
Copy Markdown
Collaborator Author

@therewasaguy i have solved the problem ,

actually, there was no way we could be able to know when all AudioWorkletProcessor will load finally so I have attached a new
promise to know when will all audioWorklet processors will be laoded finally and then used that promise to load the test !

the tests are running fine in firefox too !

and issue seems to be resolved !
have a look then we can move forward
!

@endurance21

Copy link
Copy Markdown
Collaborator Author

@therewasaguy hey! it been long seeing this.
Lets have a good warm up start and we can move ahead for smth good coming year!

@montoyamoraga montoyamoraga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @endurance21 all of this looks great, thanks!
i'm not familiar with the changes you are doing,
and i don't know how to test it, so i will let someone else merge it :)

@oshoham

oshoham commented Jan 2, 2021

Copy link
Copy Markdown
Contributor

@therewasaguy i have solved the problem ,

actually, there was no way we could be able to know when all AudioWorkletProcessor will load finally so I have attached a new
promise to know when will all audioWorklet processors will be laoded finally and then used that promise to load the test !

the tests are running fine in firefox too !

and issue seems to be resolved !
have a look then we can move forward
!

Hey @endurance21, the intention of the AudioWorkletProcessor loading code that I wrote was that all processor modules would be available when p5's setup function runs.

At the time, there was no way to ask p5 to wait for an arbitrary promise before running setup, but I was able to use p5's internal preloading hook to load the modules, which is guaranteed to finish before setup.

Is it possible for you to just use the p5 setup function in your tests instead of adding a new promise that isn't used anywhere else in the codebase?

Alternatively, if p5 has better support for promises these days, maybe you could replace the preloading code entirely?

Comment thread src/audioWorklet/index.js Outdated
Comment thread src/audioWorklet/index.js
@endurance21

Copy link
Copy Markdown
Collaborator Author

@oshoham thanks a ton for the review, I need to give it a shot by using preload hook and see if that helps.

@endurance21

Copy link
Copy Markdown
Collaborator Author

@oshoham it worked that way! thanks again!

@endurance21

Copy link
Copy Markdown
Collaborator Author

@therewasaguy i have tested on firefox and chrome too, tests are running smooth now!

Comment thread test/tests/p5.Amplitude.js Outdated
Comment thread test/tests/p5.Amplitude.js
Comment thread src/audioWorklet/index.js Outdated
Comment thread src/audioWorklet/index.js Outdated
Comment thread test/test.js Outdated
Comment thread test/tests.js
Comment thread test/tests/p5.Amplitude.js

@therewasaguy therewasaguy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome work @endurance21 !

Comment thread test/setup.js
Comment thread test/tests.js
Comment thread test/index.html
<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>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're dependent on the file structure of node_modules here, just an observation, but I do think this is better than what we had before !

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

earlier those files are stored with fixed version in codebase , now we use npm install and it downloads from npm for every codebase setup!
that way we just reduced file size of our codebase!

Comment thread test/tests/p5.Amplitude.js
Comment thread test/tests/p5.Oscillator.js
Comment thread test/tests/p5.SoundFile.js
@endurance21
endurance21 merged commit 2fd6a90 into processing:master Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants