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

Use latest istanbul lib packages #377

Merged
merged 9 commits into from
Jun 19, 2019

Conversation

pr1sm
Copy link
Contributor

@pr1sm pr1sm commented May 16, 2019

Changes

This PR should address #375

pr1sm added 9 commits May 14, 2019 20:37
The istanbul package is deprecated in favor several split packages that
control different aspects of how istanbul works. This commit adds the
recommended packages that will be used in future commits as
karma-coverage's usage of istanbul is updated to the latest api.
This commit refactors the in memory report implementation to use the new
istanbul report API.

Report creation is removed from newer versions of the istanbul API, so
this commit adds a set of utility functions to wrap around the new API
and provide similar functionality as the old API. The top level export
uses the new utility function to register the in-memory report.
This commit updates the preprocessor to use istanbul-lib-instrument
instead of the deprecated istanbul package. The biggest change in this
refactor is using a callable function instead of a constructor when
creating instrumenters

The old istanbul package exposed the Instrumenter directly, allowing the
preprocessor to create an instance of it. istanbul-lib-instrument,
however, exposes a callable function that creates an Instrumenter.
This commit updates the preprocessor to follow this new pattern of using
a callable function. In order to ensure backwards compatibility, a
utility function is added to wrap constructors with a callable function
for creation automatically.

This change allows the following configuration for creating instrumenters:
1. An object that contains an Instrumenter constructor
2. An Instrumenter constructor itself
3. A callable function that returns an Instrumenter instance.

This commit also uses the istanbul-lib-source-maps package to handle
storing source maps. A global source map store registers source maps so
they can be used later on in the reporter.
This commit updates the reporter by using the istanbul-lib-coverage
package api for handling coverage checking/management and the
istanbul-lib-report package api for handling reporting.

The new apis remove the need for collectors and remove the need to
handle disposing collectors.
This commit removes the source-cache-store and source-cache files as
they are no longer being used. The source-map-store and
istanbul-lib-source-maps are used instead, so these files are no longer
needed.
This commit updates the report creator utility to allow resetting the
custom reporter map.
This commit updates the preprocessor to properly access file coverage
when storing it in the global coverage map (when includeAllSources is
true). The previous method did not work because the returned
instrumented code from the default istanbul instrumenter returns the
coverage map in a POJO object instead of JSON notation. This breaks the
coverage regex used to match and parse the coverage map.

The istanbul instrumenter offers the ability to receive the coverage map
for the last instrumented file through a separate function, so that is
tested for and used if it is supported. The original method is used as a
fallback for backwards compatibility.

This commit also addresses changes from the v0 instanbul instrumenter
options. The changes are additive only to maintain backwards compatibility
for other instrumenters.
This commit fixes errors with accessing data properly during the
checkCoverage method. A previous commit updated the implementation to
use istanbul-lib-coverage, but this involved an api change to access the
raw coverage data (which checkCoverage uses).

This commit also fixes the checking coverage for each file by using a
map to store file coverage summaries instead of merging summaries like
the global results. Per file coverage now works as expected.
This commit updates the mocking done in unit tests to properly mock the
new istanbul API. Additionally, new unit test suites are added for the
utility methods report-creator and source-map-store.
@dogoku
Copy link

dogoku commented Jun 18, 2019

@pr1sm awesome work!
Will give this a go (on a repo with 1000s of tests) and let you know if anything pops up.

@mschaaf
Copy link

mschaaf commented Jun 19, 2019

I tested this PR on one of my projects and it works. Thanks.

@johnjbarton johnjbarton merged commit f40d6af into karma-runner:master Jun 19, 2019
@limonte
Copy link

limonte commented Jul 4, 2019

tested this PR on https://github.com/sweetalert2/sweetalert2 project, all is well, please make a release 🚀

@limonte
Copy link

limonte commented Jul 11, 2019

ping @zzo @dignifiedquire please make a release

@Goran216
Copy link

Goran216 commented Aug 20, 2019

Ping! @zzo @dignifiedquire @johnjbarton

@zzo
Copy link
Contributor

zzo commented Aug 20, 2019

you want @johnjbarton I think...

@johnjbarton
Copy link
Contributor

done

@Goran216
Copy link

I understand that this is not related to karma-coverage but I am trying to ignore some private methods with /* istanbul ignore next */ and it doesn't work. I thought it's because karma-coverage not using latest istanbul features but now that it's updated it's still the same. So frustrating. Does anyone have any idea?

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

Successfully merging this pull request may close these issues.

7 participants