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

feat(phaserx): allow running phaser in headless mode for unit testing in jest #112

Merged
merged 3 commits into from
Jul 27, 2022

Conversation

davidkol
Copy link
Contributor

  • allow jest unit testing on phaser layer
  • skip waiting for phaser textures when running in headless mode
  • check if renderer exists before using it

@davidkol davidkol requested a review from alvrs July 27, 2022 16:04
Comment on lines 22 to 23
renderer?.pipelines?.add(HueTintAndOutlineFXPipeline.KEY, new HueTintAndOutlineFXPipeline(this.game));
renderer?.pipelines?.add(MultiHueTintPipeline.KEY, new MultiHueTintPipeline(this.game));
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the first question mark? (Is renderer undefined in Headless mode or only pipelines?)

Suggested change
renderer?.pipelines?.add(HueTintAndOutlineFXPipeline.KEY, new HueTintAndOutlineFXPipeline(this.game));
renderer?.pipelines?.add(MultiHueTintPipeline.KEY, new MultiHueTintPipeline(this.game));
renderer.pipelines?.add(HueTintAndOutlineFXPipeline.KEY, new HueTintAndOutlineFXPipeline(this.game));
renderer.pipelines?.add(MultiHueTintPipeline.KEY, new MultiHueTintPipeline(this.game));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like we dont, renderer is defined, great catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

scratch that, it didnt save when i ran the tests with that change, renderer is NOT defined and does in fact need to be checked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could also mock this function instead of checking for renderer

@@ -87,7 +87,7 @@ export function createChunkedTilemap<TileKeys extends number, LayerKeys extends
);

if (layer.hasHueTintShader) {
layers[key].pipeline = (scene.game.renderer as Phaser.Renderer.WebGL.WebGLRenderer).pipelines.get(
layers[key].pipeline = (scene.game.renderer as Phaser.Renderer.WebGL.WebGLRenderer)?.pipelines?.get(
Copy link
Member

Choose a reason for hiding this comment

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

Same question here, is renderer undefined in Headless mode or just pipelines?

Suggested change
layers[key].pipeline = (scene.game.renderer as Phaser.Renderer.WebGL.WebGLRenderer)?.pipelines?.get(
layers[key].pipeline = (scene.game.renderer as Phaser.Renderer.WebGL.WebGLRenderer).pipelines?.get(

@alvrs alvrs merged commit 22bc4d8 into main Jul 27, 2022
@ludns ludns deleted the david/phaser-fixes-for-unit-testing branch December 13, 2022 09:59
LPSCRYPT pushed a commit to LPSCRYPT/esp that referenced this pull request Jan 23, 2023
… in jest (latticexyz#112)

* feat(phaserx): allow running phaser in headless mode for unit testing

* fix(phaserx): clean up renderer undefined checks and headless equality check

* refactor(phaserx): clean up renderer pipeline checks
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.

2 participants