[whatwg/streams] Fix coverage script for reference implementation (#1135)

As noted in [my comment on web-platform-tests/wpt#29190](https://github.com/web-platform-tests/wpt/pull/29190#issuecomment-855036997), it looks like `npm run coverage` has been broken for a while on the reference implementation. 😬

[Previously](https://github.com/whatwg/streams/blob/99ffba7a632c261566c12da60bb35800a42e3b3f/reference-implementation/run-web-platform-tests.js), we would use `require()` to load the reference implementation, which Istanbul can instrument. [Nowadays](https://github.com/whatwg/streams/blob/9beefc2ac041a1a848088962d56eb03e89a8bf07/reference-implementation/run-web-platform-tests.js) however, we first bundle the reference implementation with Browserify and then `eval()` that inside the test's `window`. As a result, Istanbul is unable to instrument our code and cannot report any coverage.

This PR fixes this by instrumenting the bundle with `babel-plugin-istanbul`. (There's also a `browserify-istanbul` plugin, but it uses an old version of Istanbul which doesn't support all the latest JavaScript syntax. The Babel plugin seems to be the recommended approach.) We also need to make sure that coverage results are kept between tests, so we inject the `__coverage__` variable from Node's global scope into each test's `window`.

To do:
* [ ] Only enable Istanbul transform if we're running the tests with coverage reporting enabled? However I don't know how we could detect that... (`global.__coverage__` is initially still `undefined` even with coverage reporting enabled.)
You can view, comment on, or merge this pull request online at:

  https://github.com/whatwg/streams/pull/1135


-- Commit Summary --

  * Set up browserify-istanbul for test runner
  * Switch to babelify and babel-plugin-istanbul

-- File Changes --

    M reference-implementation/package.json (3)
    M reference-implementation/run-web-platform-tests.js (8)

-- Patch Links --

https://github.com/whatwg/streams/pull/1135.patch

https://github.com/whatwg/streams/pull/1135.diff


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1135

Received on Friday, 4 June 2021 23:10:21 UTC