-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[html coverage report] Add vendored package + generate HTML report #7528
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
Open
ChristopherDedominici
wants to merge
37
commits into
main
Choose a base branch
from
html-coverage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,530
−0
Open
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
731d409
mvp
ChristopherDedominici 4088b56
istanbul libCoverage: copy original js file in root assets folder
ChristopherDedominici e3d52e3
libReport
ChristopherDedominici 4dae722
report
ChristopherDedominici d002919
remove dependencies from istanbul in coverage-manager
ChristopherDedominici 95f8d9a
add 'node:' to imports
ChristopherDedominici f3e276f
replace import to istanbul with internal assets
ChristopherDedominici c77eb8d
remove unused library
ChristopherDedominici 7771d9f
replace html escape package
ChristopherDedominici 029bc26
replace make-dir with fs/promises
ChristopherDedominici 9be67d5
remove dependencies from istanbul npm packages
ChristopherDedominici 3a55628
base package
ChristopherDedominici cc5cb6a
move js istanbul libs in the new package
ChristopherDedominici 1856995
add postbuild script and re-organize coverage-manager
ChristopherDedominici e646399
exclude js, cjs, css, png from the gitignore
ChristopherDedominici 3047483
rename to hardhat-vendored
ChristopherDedominici c8ea036
exclude from gitignore
ChristopherDedominici 39ce891
delete test file
ChristopherDedominici c6f1e72
remove dist folder
ChristopherDedominici f78a224
fix package name and imports
ChristopherDedominici b28430a
rename folder to avoid gitignore
ChristopherDedominici 8c92ef9
fix copy-assets
ChristopherDedominici 022c6ae
fix exports after changing folder name
ChristopherDedominici a50b3b8
show colored lines in coverage report
ChristopherDedominici 0b89710
update tsconfig in new vendored package
ChristopherDedominici 50f3b4c
minor fixes
ChristopherDedominici f3591e7
Merge branch 'main' of github.com:NomicFoundation/hardhat into html-c…
ChristopherDedominici d0fba8e
Merge branch 'main' of github.com:NomicFoundation/hardhat into html-c…
ChristopherDedominici 3602408
lint:fix
ChristopherDedominici 006f834
Create gorgeous-swans-try.md
ChristopherDedominici f771d34
ignore spelling in vendored package src code
ChristopherDedominici 7724608
Merge branch 'html-coverage' of github.com:NomicFoundation/hardhat in…
ChristopherDedominici 9dde2ee
remove dependency from @nomicfoundation/hardhat-node-test-reporter
ChristopherDedominici 7542cdc
add reference to test reporter
ChristopherDedominici 8ed50de
Merge branch 'html-coverage' of github.com:NomicFoundation/hardhat in…
ChristopherDedominici f264363
add hardhat-node-test-reporter in package.json
ChristopherDedominici b26e193
Merge branch 'main' of github.com:NomicFoundation/hardhat into html-c…
ChristopherDedominici File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import libCoverage from "./lib-coverage/index.cjs"; | ||
| export default libCoverage; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| Copyright 2012-2015, Yahoo Inc. | ||
| Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. | ||
| */ | ||
| "use strict"; | ||
|
|
||
| /** | ||
| * istanbul-lib-coverage exports an API that allows you to create and manipulate | ||
| * file coverage, coverage maps (a set of file coverage objects) and summary | ||
| * coverage objects. File coverage for the same file can be merged as can | ||
| * entire coverage maps. | ||
| * | ||
| * @module Exports | ||
| */ | ||
| const { FileCoverage } = require("./lib/file-coverage.cjs"); | ||
| const { CoverageMap } = require("./lib/coverage-map.cjs"); | ||
| const { CoverageSummary } = require("./lib/coverage-summary.cjs"); | ||
|
|
||
| module.exports = { | ||
| /** | ||
| * creates a coverage summary object | ||
| * @param {Object} obj an argument with the same semantics | ||
| * as the one passed to the `CoverageSummary` constructor | ||
| * @returns {CoverageSummary} | ||
| */ | ||
| createCoverageSummary(obj) { | ||
| if (obj && obj instanceof CoverageSummary) { | ||
| return obj; | ||
| } | ||
| return new CoverageSummary(obj); | ||
| }, | ||
| /** | ||
| * creates a CoverageMap object | ||
| * @param {Object} obj optional - an argument with the same semantics | ||
| * as the one passed to the CoverageMap constructor. | ||
| * @returns {CoverageMap} | ||
| */ | ||
| createCoverageMap(obj) { | ||
| if (obj && obj instanceof CoverageMap) { | ||
| return obj; | ||
| } | ||
| return new CoverageMap(obj); | ||
| }, | ||
| /** | ||
| * creates a FileCoverage object | ||
| * @param {Object} obj optional - an argument with the same semantics | ||
| * as the one passed to the FileCoverage constructor. | ||
| * @returns {FileCoverage} | ||
| */ | ||
| createFileCoverage(obj) { | ||
| if (obj && obj instanceof FileCoverage) { | ||
| return obj; | ||
| } | ||
| return new FileCoverage(obj); | ||
| }, | ||
| }; | ||
|
|
||
| /** classes exported for reuse */ | ||
| module.exports.classes = { | ||
| /** | ||
| * the file coverage constructor | ||
| */ | ||
| FileCoverage, | ||
| }; |
134 changes: 134 additions & 0 deletions
134
v-next/hardhat/assets/lib-coverage/lib/coverage-map.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| Copyright 2012-2015, Yahoo Inc. | ||
| Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. | ||
| */ | ||
| "use strict"; | ||
|
|
||
| const { FileCoverage } = require("./file-coverage.cjs"); | ||
| const { CoverageSummary } = require("./coverage-summary.cjs"); | ||
|
|
||
| function maybeConstruct(obj, klass) { | ||
| if (obj instanceof klass) { | ||
| return obj; | ||
| } | ||
|
|
||
| return new klass(obj); | ||
| } | ||
|
|
||
| function loadMap(source) { | ||
| const data = Object.create(null); | ||
| if (!source) { | ||
| return data; | ||
| } | ||
|
|
||
| Object.entries(source).forEach(([k, cov]) => { | ||
| data[k] = maybeConstruct(cov, FileCoverage); | ||
| }); | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| /** CoverageMap is a map of `FileCoverage` objects keyed by file paths. */ | ||
| class CoverageMap { | ||
| /** | ||
| * @constructor | ||
| * @param {Object} [obj=undefined] obj A coverage map from which to initialize this | ||
| * map's contents. This can be the raw global coverage object. | ||
| */ | ||
| constructor(obj) { | ||
| if (obj instanceof CoverageMap) { | ||
| this.data = obj.data; | ||
| } else { | ||
| this.data = loadMap(obj); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * merges a second coverage map into this one | ||
| * @param {CoverageMap} obj - a CoverageMap or its raw data. Coverage is merged | ||
| * correctly for the same files and additional file coverage keys are created | ||
| * as needed. | ||
| */ | ||
| merge(obj) { | ||
| const other = maybeConstruct(obj, CoverageMap); | ||
| Object.values(other.data).forEach((fc) => { | ||
| this.addFileCoverage(fc); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * filter the coveragemap based on the callback provided | ||
| * @param {Function (filename)} callback - Returns true if the path | ||
| * should be included in the coveragemap. False if it should be | ||
| * removed. | ||
| */ | ||
| filter(callback) { | ||
| Object.keys(this.data).forEach((k) => { | ||
| if (!callback(k)) { | ||
| delete this.data[k]; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * returns a JSON-serializable POJO for this coverage map | ||
| * @returns {Object} | ||
| */ | ||
| toJSON() { | ||
| return this.data; | ||
| } | ||
|
|
||
| /** | ||
| * returns an array for file paths for which this map has coverage | ||
| * @returns {Array{string}} - array of files | ||
| */ | ||
| files() { | ||
| return Object.keys(this.data); | ||
| } | ||
|
|
||
| /** | ||
| * returns the file coverage for the specified file. | ||
| * @param {String} file | ||
| * @returns {FileCoverage} | ||
| */ | ||
| fileCoverageFor(file) { | ||
| const fc = this.data[file]; | ||
| if (!fc) { | ||
| throw new Error(`No file coverage available for: ${file}`); | ||
| } | ||
| return fc; | ||
| } | ||
|
|
||
| /** | ||
| * adds a file coverage object to this map. If the path for the object, | ||
| * already exists in the map, it is merged with the existing coverage | ||
| * otherwise a new key is added to the map. | ||
| * @param {FileCoverage} fc the file coverage to add | ||
| */ | ||
| addFileCoverage(fc) { | ||
| const cov = new FileCoverage(fc); | ||
| const { path } = cov; | ||
| if (this.data[path]) { | ||
| this.data[path].merge(cov); | ||
| } else { | ||
| this.data[path] = cov; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * returns the coverage summary for all the file coverage objects in this map. | ||
| * @returns {CoverageSummary} | ||
| */ | ||
| getCoverageSummary() { | ||
| const ret = new CoverageSummary(); | ||
| Object.values(this.data).forEach((fc) => { | ||
| ret.merge(fc.toSummary()); | ||
| }); | ||
|
|
||
| return ret; | ||
| } | ||
| } | ||
|
|
||
| module.exports = { | ||
| CoverageMap, | ||
| }; |
112 changes: 112 additions & 0 deletions
112
v-next/hardhat/assets/lib-coverage/lib/coverage-summary.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| Copyright 2012-2015, Yahoo Inc. | ||
| Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. | ||
| */ | ||
| "use strict"; | ||
|
|
||
| const percent = require("./percent.cjs"); | ||
| const dataProperties = require("./data-properties.cjs"); | ||
|
|
||
| function blankSummary() { | ||
| const empty = () => ({ | ||
| total: 0, | ||
| covered: 0, | ||
| skipped: 0, | ||
| pct: "Unknown", | ||
| }); | ||
|
|
||
| return { | ||
| lines: empty(), | ||
| statements: empty(), | ||
| functions: empty(), | ||
| branches: empty(), | ||
| branchesTrue: empty(), | ||
| }; | ||
| } | ||
|
|
||
| // asserts that a data object "looks like" a summary coverage object | ||
| function assertValidSummary(obj) { | ||
| const valid = | ||
| obj && obj.lines && obj.statements && obj.functions && obj.branches; | ||
| if (!valid) { | ||
| throw new Error( | ||
| "Invalid summary coverage object, missing keys, found:" + | ||
| Object.keys(obj).join(","), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * CoverageSummary provides a summary of code coverage . It exposes 4 properties, | ||
| * `lines`, `statements`, `branches`, and `functions`. Each of these properties | ||
| * is an object that has 4 keys `total`, `covered`, `skipped` and `pct`. | ||
| * `pct` is a percentage number (0-100). | ||
| */ | ||
| class CoverageSummary { | ||
| /** | ||
| * @constructor | ||
| * @param {Object|CoverageSummary} [obj=undefined] an optional data object or | ||
| * another coverage summary to initialize this object with. | ||
| */ | ||
| constructor(obj) { | ||
| if (!obj) { | ||
| this.data = blankSummary(); | ||
| } else if (obj instanceof CoverageSummary) { | ||
| this.data = obj.data; | ||
| } else { | ||
| this.data = obj; | ||
| } | ||
| assertValidSummary(this.data); | ||
| } | ||
|
|
||
| /** | ||
| * merges a second summary coverage object into this one | ||
| * @param {CoverageSummary} obj - another coverage summary object | ||
| */ | ||
| merge(obj) { | ||
| const keys = [ | ||
| "lines", | ||
| "statements", | ||
| "branches", | ||
| "functions", | ||
| "branchesTrue", | ||
| ]; | ||
| keys.forEach((key) => { | ||
| if (obj[key]) { | ||
| this[key].total += obj[key].total; | ||
| this[key].covered += obj[key].covered; | ||
| this[key].skipped += obj[key].skipped; | ||
| this[key].pct = percent(this[key].covered, this[key].total); | ||
| } | ||
| }); | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * returns a POJO that is JSON serializable. May be used to get the raw | ||
| * summary object. | ||
| */ | ||
| toJSON() { | ||
| return this.data; | ||
| } | ||
|
|
||
| /** | ||
| * return true if summary has no lines of code | ||
| */ | ||
| isEmpty() { | ||
| return this.lines.total === 0; | ||
| } | ||
| } | ||
|
|
||
| dataProperties(CoverageSummary, [ | ||
| "lines", | ||
| "statements", | ||
| "functions", | ||
| "branches", | ||
| "branchesTrue", | ||
| ]); | ||
|
|
||
| module.exports = { | ||
| CoverageSummary, | ||
| }; |
12 changes: 12 additions & 0 deletions
12
v-next/hardhat/assets/lib-coverage/lib/data-properties.cjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| "use strict"; | ||
|
|
||
| module.exports = function dataProperties(klass, properties) { | ||
| properties.forEach((p) => { | ||
| Object.defineProperty(klass.prototype, p, { | ||
| enumerable: true, | ||
| get() { | ||
| return this.data[p]; | ||
| }, | ||
| }); | ||
| }); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a "bridge" to expose the common js code into ESM js code, so that the ts file can then import it