Open johanneswuerbach opened 9 years ago
I wrote that code. It works like this:
This code adds some custom middlewares to the internal express object.
This can't be done with the proxy configuration because some of them have to be loaded even before testem defaults. The proxy config loads them after, I opened airportyh/testem#341 in the past, but apparently a better solution was coming and that PR was never merged.
The two most important middlewares are
The first one has to be injected before any other middleware and there's no way to do it right now. The second one instead goes at the end, but errors are swallowed by the last static middleware.
Back to the previous point, I need to create a custom version of testem.js because I need to inject extra JS code in every test page.
Testem multi works both with configuration
and custom test page
. When running in custom file ({"test_page": "tests.html"}
) there's no way to inject in every test an extra script, unless you want to modify every test page.
This code injects '../../../../public/testem/istanbul_coverage.js'
into testem.js.
That's why I need to add have middlewares even before testem default ones.
The file listens to Testem.on("all-test-results")
to send back the coverage to the custom endpoint. The request has to be synchronous or you'll have problems with airportyh/testem#360. I remember having to use a setTimeout to make it work, but I can't find it in the code, so that's probably working fine with a sync POST.
tl;dr
Testem has now an official way to add custom middlewares, doesn't this solve both issues? https://github.com/airportyh/testem/pull/410
No, is this solution was never implemented. Middlewares now go first. I still need to add something after this one.
What kind of hooks would you need to stop patching testem internals like https://github.com/sideroad/testem-multi/blob/master/lib/coverage_middleware.js#L12?
This patch is broken since
0.6.24
and I can really ensure, that we don't refactor code between releases.