Allow definition of mock requestMIDIAccess
function as a WebMidi.enable()
option
#223
Replies: 3 comments
-
This makes sense. However, we would need to check whether A bit of back story: unit tests for the library use a module called |
Beta Was this translation helpful? Give feedback.
-
With the e2e testing scenario, there will be an existing I see that you're using JZZ's I suppose this would/could also be a great way to run the unit tests for WebMidi.js. Native libraries such as RtMidi can be such a pain to manage in a cross-platform testing environment. |
Beta Was this translation helpful? Give feedback.
-
I only tried running the tests on macOS but the |
Beta Was this translation helpful? Give feedback.
-
It looks like Jazz's web-midi-test package would be a great way to mock MIDI sources and destinations for E2E testing. It appears to mock the
navigator.requestMIDIAccess()
function and allows the definition of virtual MIDI sources and destinations. I'm guessing that it works similar to the JZZ package, emulating the browser's Web MIDI API and routing it to virtual devices rather than JZZ's node implementation.WebMidi.js currently contains this code:
...which might lead us to belive that we could just do something similar to
web-midi-test
's example of:However, in the case of E2E test, the
navigator
global is there. We just want to use a DIFFERENTrequestMIDIAccess()
function. I don't believe that we can overwrite therequestMIDIAccess
function. So what if there was a property ofrequestMIDIAccessFunction
as a property ofWebMidi.enable(options)
. So the code would look something like this:I intentionally picked the name
requestMIDIAccessFunction
because it's big and awkward and scary looking... and hopefully people will avoid it if they don't know what it is. 🙂Internally, you'd do something like this in
WebMidi.js
:Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions