Is there any way to write unit tests for GNOME-Shell extensions
Asked Answered
L

1

6

I am currently trying to refactor an existing gnome-shell extension's codebase. Part of that is introducing unit tests as it seems rather neglectful to not use tests in 2016.

After some tinkering I managed to setup a working node-phantomjs-qunit pipeline that actually gets me somewhere.

However, shell extensions use a custom imports-mechanic as well as some amendments to build in classes (ex: String.format via GJS) that make it impossible to actually test those files in a isolated environment, that is: not within the shell.

So my question is: Is it really true that it is impossible to write unit tests for shell extensions?

Lycaonia answered 21/8, 2016 at 11:45 Comment(2)
Not totally impossible to do but definitely not worth the effort. The small core group of GNOME Shell developers keep changing the internal APIs which means in practice, one often has to rework an extension whenever a new version of the GNOME Shell is released.Hunker
@fpmurphy1 thanks for the feedback. I'm well aware of the rapid API changes, but still I think having some basic coverage would still be preferable. If only to get an early warning if things break.Lycaonia
E
1

I've done some work with unit tests with gnome shell extensions, take a look at this extension for a complete example:

https://github.com/emerinohdz/power-alt-tab

I've used webpack with babel (optional) and GJS. It is even built using Travis CI.

I've included a dumb polyfill for the GS parts I needed, and provided an alternative to handle modules, using ES6 imports instead of the default GS imports mechanism. No integration tests are possible right now, only unit tests, but at least you have control of most of your codebase.

Embryectomy answered 27/11, 2017 at 3:53 Comment(2)
That doesn't even install Gnome-Shell, much less run any integration tests against it...Milford
The OP asked for unit tests, and that is unit testing the extension (there's even a comment I placed on the answer saying integration tests are not possible), if you are looking for integration tests go for it and let us know how it goes!Embryectomy

© 2022 - 2024 — McMap. All rights reserved.