How to generate and display coverage when running tests with Pongo for custom Kong API Gateway plugins written in Lua

I am writing a few kong custom plugins in Lua. I am using Kong 2.3.3 and Lua 5.1.

I have some test cases (unit tests + integration tests) and i am running them with pongo run -coverage option. I have already installed luacov (and also cluacov, both with luarocks install) and all my tests are passing but no luacov files are being generated with coverage data. I am not running pongo from Docker, i have installed and configured it in my local machine (which is Linux Ubuntu 20.04).

I have already tried a few things as follows:

  • my .busted file is setting coverage = true, verbose = true and output = "gtest" (already tried utfTerminal, tap and json too)
  • tried adding luacov as a dependency to my rockspec file... the build does not fail but no coverage file is generated
  • i even tried running the tests without pongo, using busted directly but this is a very bad option because things like spec.helpers, or the cjson lib are not set in my LUAPATH


  • A quick way to do this is to modify pongo

    Edit your file to:

    • add coverage flag to busted --coverage
    • call luacov to generate the report luacov
    • display the report cat

    locate where busted is called, line 959 for me:

    "/bin/sh" "-c" "bin/busted --coverage --helper=bin/busted_helper.lua ${busted_params[*]} ${busted_files[*]};luacov;cat"

    Install luacov, edit assets/Dockerfile after busted installation add luacov:

        && luarocks install busted-htest \
        && luarocks install luacov \

    pongo run will give you

    File                                                                              Hits  Missed Coverage
    /kong-plugin/kong/plugins/myplugin/schema.lua                                     105   1      99.06%
    /kong-plugin/spec/myplugin/01-schema_spec.lua                                     199   5      97.55%