(Superseded) Set up plugin continuous integration tests on Travis CI

@david thanks so much for the comprehensive post, it helped immensely when getting my own plugin’s specs running in Travis :heart:

Here’s an example: Travis CI, and the scripts common to all my plugins live in:

From implementing this (and banging my head against my desk a lot) I’ve got a few improvements to propose:

Extract plugin name from plugin.rb

We have a discrepancy between the name of our plugins (e.g. mozilla-iam) and the name of its repo (e.g. discourse-mozilla-iam).

So I came up with a little oneliner to extract that name from plugin.rb rather than the directory:

(some extra escapes will have to be thrown in to put it in a .travis.yml)

Travis log folding

Like Travis does automatically with all the pre-install and pre-script gubbins, you can force Travis to fold a section of output by echoing travis_fold:start:#{id} and travis_fold:end:#{id}

So like:

echo "travis_fold:start:discourse_setup"

and

echo "travis_fold:end:discourse_setup"

I did however spend far too long getting this working, because I managed to misspell discourse in the end command without noticing :expressionless:

To actually wrap the relevant sections with that command I had to roll my own near-duplicate of discourse/lib/tasks/docker.rake at main · discourse/discourse · GitHub.

I’d propose that script puts some fold commands if TRAVIS=true.

Measure code coverage and export to Coveralls

This is probably the least supported thing I got kinda working, and probably requires further discussion in its own topic.

It can be seen in practice here: mozilla/discourse-mozilla-iam | Coveralls - Test Coverage History & Statistics

The measuring of coverage itself is a bit quirky. Presumably because of the order in which files are loaded, any code executed in plugin.rb doesn’t get picked up by simplecov. I’m sure there’s some way around this, but I haven’t been able to figure it out (and I’ve just got around the problem by moving all the code I can into separate files).

To actually get coverage running, I import this file at the top of all my specs:

Which relies on those gems being installed, which I achieve like so:

It would be :ok_hand: to see support for this in core. There’s a smattering for some of it already:

But simplecov isn’t in the Gemfile.

To then get coverage exported to Coveralls, I needed to export a couple of environment variables to docker.


Happy to submit a PR incorporating some of these improvements upstream, but I’ll take guidance on which would be welcomed.

Also, if anyone has any ideas about how to check JS test coverage that would be welcomed by me! There seemed to be a few methods of getting LCOV-formatted data out of QUnit-run tests, but none seemed to slot nicely into our existing tooling.

「いいね!」 7