ember-cli-code-coverage icon indicating copy to clipboard operation
ember-cli-code-coverage copied to clipboard

Update README to callout existing issue with test coverage not being generated when running in CI

Open cah-john-ryan opened this issue 1 year ago • 2 comments

From: https://github.com/ember-cli-code-coverage/ember-cli-code-coverage/issues/420#issuecomment-2332270042

In reviewing comments from @kategengler here https://github.com/ember-cli-code-coverage/ember-cli-code-coverage/issues/380#issuecomment-1793077046, I have experimented and found the below interim solution.


The README should reflect the below interim solution while this issue is present.

Add the below line as a new property in the APP object of the file config/environment.js:

APP: {
    isRunningWithServerArgs: process.argv.includes('--server') || process.argv.includes('-s')
}

In the existing file tests/test-helper.js, replace the block of code:

import { forceModulesToBeLoaded, sendCoverage } from 'ember-cli-code-coverage/test-support';
import Qunit from 'qunit';

QUnit.done(async function() {
  forceModulesToBeLoaded();
  await sendCoverage();
});

with instead:

import { forceModulesToBeLoaded, sendCoverage } from 'ember-cli-code-coverage/test-support';
import Qunit from 'qunit';

if (config.APP.isRunningWithServerArgs) {
  // until Testem is patched, this will fail to POST coverage in CI mode (running tests with -s or --server as an argument)
  // Ref: https://github.com/testem/testem/issues/1577
  QUnit.done(async function () {
    forceModulesToBeLoaded();
    await sendCoverage();
  });
} else {
  //eslint-disable-next-line no-undef
  Testem.afterTests(function (config, data, callback) {
    forceModulesToBeLoaded();
    sendCoverage(callback);
  });
}

cah-john-ryan avatar Sep 05 '24 17:09 cah-john-ryan

Hello! Possibly a small oversight with this but we noticed that unless you check for test or t you may brick the ability to run tests from visiting /tests while the app is being served.

malatin3 avatar Feb 06 '25 10:02 malatin3

@cah-john-ryan Thank you for the workaround. I run tests in 6 containers and some of them don't save the coverage file 🤷‍♂ I typically get a 50:50 success rate - I mean 3 containers fail, 3 succeeds. I got to the point where I understood that there's no "enough time" to save them but I couldn't figure out why. Now I get it.

The workaround works great for me ❤

tniezurawski avatar Feb 09 '25 11:02 tniezurawski