Coverage is not written unless `-s` is provided
Have tested numerous times and coverage is never written when I do ember t, it is only written when I do ember t -s. This doesnt play well with the CI jobs of course. I do use embroider.
On the current versions of almost all addons. Have checked the docs and have the babel plugin correct, have the ember-concurrency plugin before it. Using mirage, have the /write-coverage in the correct place, etc. I believe I have it configured correctly because I do get coverage, just have to specify -s.
Anyone got any idea on what could be the issue?
I do notice that when I run tests, I get the following error which to me looks like it is attempting an http request (assuming attempting to write coverage)
BadRequestError: request aborted
at IncomingMessage.onAborted (/Users/brian.gantzler/source/rxid/ember/ember-rxid/node_modules/raw-body/index.js:245:10)
at IncomingMessage.emit (node:events:520:28)
at IncomingMessage._destroy (node:_http_incoming:224:10)
at _destroy (node:internal/streams/destroy:122:10)
at IncomingMessage.destroy (node:internal/streams/destroy:84:5)
at abortIncoming (node:_http_server:806:9)
at socketOnClose (node:_http_server:800:3)
at Socket.emit (node:events:532:35)
at TCP.<anonymous> (node:net:338:12)
As a followup on an interim fix when running into the above situation. We have found that this plugin makes an API call to /write-coverage that is failing to complete when the amount of data being reported becomes too large. We have verified this by stripping applications exhibiting this issue to where the data being reported was reduced in size and then started to see consistent success in the generation of coverage data.
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.
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);
});
}