Skip to content

Commit b77244a

Browse files
committed
Bootstrap GLFW before QML tests
1 parent dac8e05 commit b77244a

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"devDependencies": {
4848
"@node-3d/addon-tools": "10.0.5",
4949
"@node-3d/core": "6.3.0",
50+
"@node-3d/glfw": "7.3.1",
5051
"@rslib/core": "0.23.2",
5152
"@types/node": "24.13.2",
5253
"@types/three": "0.174.0",

test/3d-qml.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { strict as assert } from 'node:assert';
22
import { describe, it } from 'node:test';
33
import initForTest from './init.ts';
44

5-
const inited = initForTest();
5+
const inited = await initForTest();
66
const { QmlOverlay, QmlMaterial, QmlOverlayMaterial, loop, doc } = inited;
77

88
const initResults = [

test/compare.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { TScreenshotReportLevel } from '@node-3d/core/testing';
77

88
import initForTest from './init.ts';
99

10-
const inited = initForTest();
10+
const inited = await initForTest();
1111
const { QmlOverlay, loop, doc } = inited;
1212
const report = (level: TScreenshotReportLevel, message: string, error?: unknown): void => {
1313
if (error === undefined) {

test/init.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { platform } from 'node:process';
22
import * as three from 'three';
3-
import { init as initQml } from '../ts/index.ts';
43
import type { TCore3D, TGlfw, TInitOpts } from '@node-3d/core';
54
import type { TQml3D } from '../ts/index.ts';
65

@@ -27,19 +26,20 @@ const importCoreForTest = async () => {
2726
const nodeGlobal = globalThis as unknown as Record<string, unknown>;
2827
if (shouldUseHeadlessGlfw) {
2928
nodeGlobal['__isGlfwInited'] = true;
30-
}
31-
32-
const core = await import('@node-3d/core');
29+
const { glfw: bootstrappedGlfw } = await import('@node-3d/glfw');
30+
bootstrappedGlfw.initHint(bootstrappedGlfw.PLATFORM, bootstrappedGlfw.PLATFORM_NULL);
3331

34-
if (shouldUseHeadlessGlfw) {
35-
core.glfw.initHint(core.glfw.PLATFORM, core.glfw.PLATFORM_NULL);
36-
if (!core.glfw.init()) {
32+
if (!bootstrappedGlfw.init()) {
3733
throw new Error('Failed to initialize GLFW for headless tests');
3834
}
39-
core.glfw.defaultWindowHints();
35+
36+
bootstrappedGlfw.defaultWindowHints();
37+
bootstrappedGlfw.windowHint(bootstrappedGlfw.STENCIL_BITS, 0);
4038
nodeGlobal['__isGlfwInited'] = true;
4139
}
4240

41+
const core = await import('@node-3d/core');
42+
4343
return core;
4444
};
4545

@@ -79,8 +79,9 @@ const getInitOpts = (): TInitOpts => {
7979
};
8080
};
8181

82-
const initForTest = (): Omit<TCore3D, 'loop'> & TQml3D => {
82+
const initForTest = async (): Promise<Omit<TCore3D, 'loop'> & TQml3D> => {
8383
const node3d = init(getInitOpts());
84+
const { init: initQml } = await import('../ts/index.ts');
8485

8586
const { doc } = node3d;
8687

0 commit comments

Comments
 (0)