Unit Testing #16892
-
Is it possible to use unit testing when developing a plugin for cockpit? When running tests the code which works while viewing the plugin in cockpit can no longer import cockpit to be used with the unit test. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes, it is possible, and most practical for testing logic. Cockpit has QUnit JS unit tests for the Storage and Networking pages for example, and tons of unit tests for cockpit.js itself. This requires some plumbing: The qunit-* files in pkg/lib, webpacking them, and some plumbing in the Makefile. It also needs a http server -- qunit has some provisioning for this, but for cockpit we use our own (as it ships a web server anyway). So it is certainly possible but a lot of effort to set up. That's why starter-kit does not ship any unit tests, as in most cases for cockpit plugins, it's not worth the effort -- integration tests are more useful in general, and even easier to write with our test machinery. |
Beta Was this translation helpful? Give feedback.
-
Actually, have a look at cockpit-ostree -- that also does qunit unit tests, but in a much simpler way. The test does not have anything weird, the webpack.config.js builds it in a straightforward way, and package.json has script starters for it. |
Beta Was this translation helpful? Give feedback.
Actually, have a look at cockpit-ostree -- that also does qunit unit tests, but in a much simpler way. The test does not have anything weird, the webpack.config.js builds it in a straightforward way, and package.json has script starters for it.