11/*
22 * windows-smoke-test.js
33 *
4- * Verifies that a Windows prebuilt + bundled GTK runtime (DLLs + typelibs) can
5- * be loaded and used on a clean machine that has NO MSYS2/MinGW and NO compiler
6- * — i.e. exactly what a user gets from `npm install node-gtk` if we ship a
7- * self-contained Windows prebuilt.
4+ * Verifies that a Windows prebuilt + bundled GTK runtime can be loaded and used
5+ * on a clean machine that has NO MSYS2/MinGW and NO compiler — i.e. exactly what
6+ * a user gets from `npm install node-gtk`.
87 *
9- * It deliberately does NOT depend on anything from MSYS2; the only GTK bits it
10- * touches are the ones bundled next to the .node by windows-bundle-runtime.sh.
8+ * CRITICAL: this test sets NO environment variables. Everything (DLL search
9+ * path, GI typelib path, icon/schema/loader data) is wired up automatically by
10+ * lib/native.js when it loads the bundled prebuilt. The workflow runs this with
11+ * the runner's own MinGW stripped from PATH, so a pass proves the bundle is
12+ * fully self-sufficient via the auto-wiring alone.
1113 */
1214
1315const path = require ( 'path' )
@@ -26,39 +28,11 @@ if (fs.existsSync(bindingDir)) {
2628 console . log ( `bundled DLLs: ${ dlls . length } ` )
2729}
2830
29- // 1) Make the bundled GTK DLLs discoverable. This covers BOTH:
30- // - the addon's own static imports (resolved when node loads the .node)
31- // - GObject-Introspection's g_module_open() of each namespace's shared lib
32- // We REPLACE the PATH (rather than prepend) with the bundle dir + only the
33- // Windows system dirs. The GitHub windows-latest runner ships its own
34- // C:\mingw64; isolating the PATH proves the test uses ONLY the bundled
35- // runtime, not whatever GTK happens to be on the machine.
36- const sysRoot = process . env . SystemRoot || 'C:\\Windows'
37- process . env . PATH = [
38- bindingDir ,
39- path . dirname ( process . execPath ) , // node.exe dir
40- path . join ( sysRoot , 'System32' ) ,
41- sysRoot ,
42- ] . join ( path . delimiter )
43- // 2) Point GI at the bundled typelibs.
44- process . env . GI_TYPELIB_PATH =
45- typelibDir + ( process . env . GI_TYPELIB_PATH ? path . delimiter + process . env . GI_TYPELIB_PATH : '' )
46-
47- // Require the local package (its lib/native.js resolves the prebuilt via
48- // node-pre-gyp's binary.find, i.e. the same path users hit after install).
31+ // Require the local package. lib/native.js resolves the prebuilt via
32+ // node-pre-gyp's binary.find and auto-wires the bundled runtime — NO manual
33+ // PATH / GI_TYPELIB_PATH / XDG_DATA_DIRS setup here on purpose.
4934const gi = require ( path . join ( __dirname , '..' ) )
50- console . log ( 'OK: require(node-gtk) — prebuilt + bundled DLLs loaded' )
51-
52- // Belt and suspenders: also register the typelib dir through GI's own API.
53- try { gi . prependSearchPath ( typelibDir ) } catch ( e ) { /* ignore */ }
54-
55- // Point GTK4/Adwaita at the bundled runtime data so a real app could run.
56- const bundledShare = path . join ( bindingDir , 'share' )
57- if ( fs . existsSync ( bundledShare ) ) {
58- process . env . XDG_DATA_DIRS = bundledShare + ( process . env . XDG_DATA_DIRS ? path . delimiter + process . env . XDG_DATA_DIRS : '' )
59- const schemas = path . join ( bundledShare , 'glib-2.0' , 'schemas' )
60- if ( fs . existsSync ( schemas ) ) process . env . GSETTINGS_SCHEMA_DIR = schemas
61- }
35+ console . log ( 'OK: require(node-gtk) — prebuilt loaded and runtime auto-wired by native.js' )
6236
6337// The full quilx namespace set. Vte (3.91) has no Windows port, so it is
6438// expected to be unavailable; everything else must load.
@@ -111,4 +85,20 @@ try {
11185}
11286console . log ( 'live GTK4/Adwaita widgets:' , appOk ? 'ok' : 'skipped (no display)' )
11387
88+ // Exercise the bundled gdk-pixbuf image loaders + (portable) loaders.cache by
89+ // decoding a real PNG. This proves the loader subsystem works from the bundle.
90+ const PNG_1x1 = Buffer . from (
91+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==' ,
92+ 'base64' )
93+ const pngPath = path . join ( __dirname , '..' , 'smoke-test-pixel.png' )
94+ fs . writeFileSync ( pngPath , PNG_1x1 )
95+ try {
96+ const pixbuf = loaded . GdkPixbuf . Pixbuf . newFromFile ( pngPath )
97+ if ( pixbuf . getWidth ( ) !== 1 || pixbuf . getHeight ( ) !== 1 )
98+ throw new Error ( `unexpected pixbuf size ${ pixbuf . getWidth ( ) } x${ pixbuf . getHeight ( ) } ` )
99+ console . log ( 'OK: GdkPixbuf decoded a PNG via the bundled loaders' )
100+ } finally {
101+ try { fs . unlinkSync ( pngPath ) } catch ( e ) { /* ignore */ }
102+ }
103+
114104console . log ( '\n=== SMOKE TEST PASSED: GTK4/Adwaita prebuilt usable with NO compiler/MSYS2 ===' )
0 commit comments