Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Feb 4, 2021

Conversation

endurance21
Copy link
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
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!

Copy link
Member

@therewasaguy therewasaguy left a comment

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);

test/tests/p5.Amplitude.js Outdated Show resolved Hide resolved
test/tests/p5.Amplitude.js Show resolved Hide resolved
test/index.html Outdated Show resolved Hide resolved
@therewasaguy
Copy link
Member

therewasaguy commented Aug 24, 2020

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
Collaborator Author

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

alos removed
use strict keyword

@endurance21
Copy link
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
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
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!

Copy link
Member

@montoyamoraga montoyamoraga left a comment

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
Copy link
Contributor

oshoham commented Jan 2, 2021

@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?

src/audioWorklet/index.js Outdated Show resolved Hide resolved
@endurance21
Copy link
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
Collaborator Author

@oshoham it worked that way! thanks again!

@endurance21
Copy link
Collaborator Author

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

test/tests/p5.Amplitude.js Outdated Show resolved Hide resolved
test/tests/p5.Amplitude.js Show resolved Hide resolved
src/audioWorklet/index.js Outdated Show resolved Hide resolved
src/audioWorklet/index.js Outdated Show resolved Hide resolved
test/test.js Outdated Show resolved Hide resolved
test/tests.js Show resolved Hide resolved
test/tests/p5.Amplitude.js Show resolved Hide resolved
Copy link
Member

@therewasaguy therewasaguy left a comment

Choose a reason for hiding this comment

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

awesome work @endurance21 !

test/setup.js Show resolved Hide resolved
test/tests.js Show resolved Hide resolved
<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
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
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!

test/tests/p5.Amplitude.js Show resolved Hide resolved
test/tests/p5.Oscillator.js Show resolved Hide resolved
test/tests/p5.SoundFile.js Show resolved Hide resolved
@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