Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove internal patches #10

Open
johanneswuerbach opened this issue Feb 13, 2015 · 3 comments
Open

Remove internal patches #10

johanneswuerbach opened this issue Feb 13, 2015 · 3 comments

Comments

@johanneswuerbach
Copy link
Contributor

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.

@piuccio
Copy link
Contributor

piuccio commented Feb 16, 2015

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 testem/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 testem/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

  • inject some code into any test page without asking the user to change the test code
  • add error middlewares
  • better shut down the server, considering that there might be user code between the end of a test and closing the browser

@johanneswuerbach
Copy link
Contributor Author

Testem has now an official way to add custom middlewares, doesn't this solve both issues? testem/testem#410

@piuccio
Copy link
Contributor

piuccio commented Feb 16, 2015

No, is this solution was never implemented. Middlewares now go first. I still need to add something after this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants