ptomato / jasmine-gjs

Jasmine for GJS
MIT License
20 stars 8 forks source link

Cannot import St library #24

Closed elvetemedve closed 6 years ago

elvetemedve commented 6 years ago

The problem

When I try to import the St library

const St = imports.gi.St;

And run jasmine, I get the error message below.

Exception occurred inside Jasmine: Error: Requiring St, version none: Typelib file for namespace 'St' (any version) not found @/home/geza/Sites/gnome-shell-extension-system-monitor/System_Monitor@bghome.gmail.com/indicator.js:2:7 @/home/geza/Sites/gnome-shell-extension-system-monitor/spec/indicatorSpec.js:1:7 Jasmine<.loadSpecs/<@/home/geza/Sites/gnome-shell-extension-system-monitor/share/jasmine-gjs/jasmineBoot.js:120:17 Jasmine<.loadSpecs@/home/geza/Sites/gnome-shell-extension-system-monitor/share/jasmine-gjs/jasmineBoot.js:115:9 wrapper@resource:///org/gnome/gjs/modules/_legacy.js:82:22 Jasmine<.execute@/home/geza/Sites/gnome-shell-extension-system-monitor/share/jasmine-gjs/jasmineBoot.js:129:9 wrapper@resource:///org/gnome/gjs/modules/_legacy.js:82:22 run/<@/home/geza/Sites/gnome-shell-extension-system-monitor/share/jasmine-gjs/command.js:227:13 run@resource:///org/gnome/gjs/modules/mainloop.js:33:5 run@/home/geza/Sites/gnome-shell-extension-system-monitor/share/jasmine-gjs/command.js:243:5 @bin/jasmine:50:1

See also https://stackoverflow.com/questions/14002684/how-to-import-st-library-in-gjs

Should jasmine-gjs load the St library or I should create a stub for it?

ptomato commented 6 years ago

The St library is private to gnome-shell, and can only be loaded inside a binary that has the st code linked in. Enabling a setup that does this for gnome-shell's own unit tests is issue #14. However, it's out of scope for this project to "de-privatize" a specific other project's library.

Such a setup described in #14 might work for unit-testing gnome-shell extensions. For now, I would recommend at least separating your core code from UI code and stubbing out the UI code, then hopefully you can achieve good test coverage without depending on a graphical environment anyway.

elvetemedve commented 6 years ago

I thought this is the official way to test a Gnome Shell Extension. Meaning I should be able to test everyting with Jasmine without actually runing the extension by Gnome Shell.

I'll try to avoid testing UI components directly. Thanks for the hint.

ptomato commented 6 years ago

I'm not sure there is currently an official way, but I'd love for jasmine-gjs to become it :smile: Let me know what your experiences are.

I can't introduce a direct dependency on gnome-shell though, because then projects that have nothing to do with gnome-shell will have to pull it in.