-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add testing setup #4
Comments
@kevinramharak Thank you!
It would be great if this could be achieved. Thank you for the information regarding the boot issue. |
I managed to find a setup with This does not require a yarn upgrade. It also removes a lot of pain with running phaser in node, having to use
|
@kevinramharak Great! One thing I noticed is that there isn't a 'hideBanner' property in the BannerConfig options. Could it be a mistake for 'hidePhaser'? Could you then create a Pull Request against master? |
I messed around with the repository to try and add a testing framework.
I initially tried to setup
vitest
but ran into issues not being able to mockrequire
calls, which causes some issues internally with Phaser when ran in a node environment.Jest
I tried again with
jest
and you can check out the branch here: https://github.com/laineus/phavuer/compare/master...kevinramharak:phavuer:feature/add-tests-jest?expand=1.It became larger than I intended because of the following issues:
yarn
v1 has a bug where in the dependency tree it installs a wrong version. Its the classic dependency of a dependency of a dependency problem, so its not easily fixed. The only workaround I found is to upgrade yarn tov3
orv4
.canvas
additionally tojsdom
because even with the headless mode, Phaser still uses some API's when booting that require an actual implementation.__mocks__/phaser3spectorjs.js
is required because of a webpackDefinePlugin
quirk (Statement is always true phaserjs/phaser#6644)props.config.banner
check for the Phavuer banner to not pollute the logs when running tests. See https://github.com/phaserjs/phaser/blob/v3.70.0/src/core/Config.js#L305Note that the test
emits the boot event
fails. This is because Phaser only emits that event async when thenew Phaser()
constructor runs beforeDOMContentLoaded
emits. If it runs after, it will emit theboot
event sync (https://github.com/phaserjs/phaser/blob/master/src/dom/DOMContentLoaded.js#L27).Therefore in Phavuer the lines:
Will never actually catch the
boot
event, because the event is emitted before the listener is attached. Since Phavuer is part of a Vue application, I doubt there will ever be an instance where the vue application is mounted before theDOMContentLoaded
event is emitted.My suggestion would be to drop the
boot
event. An alternative is to use thepostBoot
callback (see https://newdocs.phaser.io/docs/3.60.0/Phaser.Types.Core.CallbacksConfig).But in that case the
boot
event will actually be emitted after theready
event. see https://github.com/phaserjs/phaser/blob/v3.70.0/src/core/Game.js#L416-L434.Could you check out the branch and see if this is a workable setup for tests? I might try another
vitest
setup and see if I can avoid upgradingyarn
, but I think that might give more issues since it doesn't aim to supportrequire
, and Phaser is very dependent on howrequire
works.Vitest
With a lot of pain I setup
vitest
here: https://github.com/laineus/phavuer/compare/master...kevinramharak:phavuer:feature/add-tests-vitest?expand=1This uses the experimental browser feature from vitest, which has your tests run in an actual browser.
This fixes so much pain with
jsdom
andcanvas
, so I think its miles better than usingjest
with ajsdom
/canvas
setup.The only ugly thing there was having to set
string-width
to^4.2.2
because of ESM issues deep in the dependency tree.The text was updated successfully, but these errors were encountered: