stalgiag / p5.xr

a library that helps turn p5.js sketches into immersive experiences using WebXR
GNU Lesser General Public License v2.1
117 stars 25 forks source link

p5xr.sessionCheck() not working in unit test #32

Closed vedhant closed 5 years ago

vedhant commented 5 years ago

I noticed that in unit testing with karma and mocha, p5xr.sessionCheck() is not working. More particularly, in sessionCheck() the promise navigator.xr.requestDevice() never gets resolved and remains pending indefinitely. I tested by opening the karma test server on my mobile and debugged remotely. However, (this is quite strange) when I click debug button on the karma test page on my phone, this issue disappears.

vedhant commented 5 years ago

I think this happens only with the polyfilled version

vedhant commented 5 years ago

After a ton of digging I found that the specific function - navigator.getVRDisplays() does not work in the test files. Polyfill uses this function. It does not work because karma runs the tests in an iframe. The entire p5xr constext is in an iframe and by default webvr doesn't allow navigator.getVRDisplays to resolve. If I run the function in the chrome debugger, it clearly works which also proves the point that the iframe is creating all the issues.

stalgiag commented 5 years ago

Nice detective work!