Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.2k stars 1.17k forks source link

Vitest using JSDOM crashes on PhaserJS unit test #2123

Closed zewa666 closed 2 years ago

zewa666 commented 2 years ago

Issue or Feature

I'm using node-canvas through JSDOM in a Vitest where I'm trying to setup a PhaserJS game. The initial execution works perfectly but on a test-watcher rerun the execution crashes or, even worse, the terminal keeps hanging, on Ubuntu. On Windows it merely crashses all the time.

(process:16044): GLib-GObject-WARNING **: 19:29:39.729: cannot register existing type 'PangoFontMap'

(process:16044): GLib-GObject-WARNING **: 19:29:39.729: cannot add private field to invalid (non-instantiatable) type '<invalid>'

(process:16044): GLib-GObject-CRITICAL **: 19:29:39.729: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(process:16044): GLib-CRITICAL **: 19:29:39.729: g_once_init_leave: assertion 'result != 0' failed

(process:16044): GLib-GObject-CRITICAL **: 19:29:39.729: g_type_register_static: assertion 'parent_type > 0' failed

(process:16044): GLib-GObject-WARNING **: 19:29:39.729: cannot add private field to invalid (non-instantiatable) type '<invalid>'

(process:16044): GLib-GObject-CRITICAL **: 19:29:39.729: g_type_add_interface_static: assertion 'G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(process:16044): GLib-CRITICAL **: 19:29:39.729: g_once_init_leave: assertion 'result != 0' failed

(process:16044): GLib-GObject-CRITICAL **: 19:29:39.729: g_type_register_static: assertion 'parent_type > 0' failed

(process:16044): GLib-GObject-WARNING **: 19:29:39.729: cannot register existing type 'PangoCairoFontMap'

Steps to Reproduce

Here's a repro with instructions in the readme https://github.com/zewa666/phaser-vitest-bug

Your Environment

zewa666 commented 2 years ago

when setting isolate: false it starts to work though this is more of a workaround. anyways, since I'm tbh not sure whether its Vitest, Phaser or Canvas causing the root issue I'll close this one.

shuji-koike commented 10 months ago

I came across the same problem using node-canvas with pdfjs-dist

sadly isolate: false did not work for me... but, I kept reading the vitest document and found this!

https://vitest.dev/config/#pool-1-0-0 Some libraries written in native languages, such as Prisma, bcrypt and canvas, have problems when running in multiple threads and run into segfaults. In these cases it is advised to use forks pool instead.

and setting pool: 'forks' worked like a charm!

Anyways thanks for pointing out, saved my day!