Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
test_runner: support combining coverage reports#47686
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
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
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 |
|---|---|---|
| @@ -1,13 +1,15 @@ | ||
| 'use strict'; | ||
| const{ | ||
| ArrayFrom, | ||
| ArrayPrototypeMap, | ||
| ArrayPrototypePush, | ||
| JSONParse, | ||
| MathFloor, | ||
| NumberParseInt, | ||
| RegExp, | ||
| RegExpPrototypeExec, | ||
| RegExpPrototypeSymbolSplit, | ||
| SafeMap, | ||
| SafeSet, | ||
| StringPrototypeIncludes, | ||
| StringPrototypeLocaleCompare, | ||
| StringPrototypeStartsWith, | ||
| @@ -23,9 +25,7 @@ const{setupCoverageHooks } = require('internal/util'); | ||
| const{ tmpdir }=require('os'); | ||
| const{ join, resolve }=require('path'); | ||
| const{ fileURLToPath }=require('url'); | ||
| constkCoveragePattern= | ||
| `^coverage\\-${process.pid}\\-(\\d{13})\\-(\\d+)\\.json$`; | ||
| constkCoverageFileRegex=newRegExp(kCoveragePattern); | ||
| constkCoverageFileRegex=/^coverage-(\d+)-(\d{13})-(\d+)\.json$/; | ||
| constkIgnoreRegex=/\/\*node:coverageignorenext(?<count>\d+)?\*\//; | ||
| constkLineEndingRegex=/\r?\n$/u; | ||
| constkLineSplitRegex=/(?<=\r?\n)/u; | ||
| @@ -95,13 +95,6 @@ class TestCoverage{ | ||
| for(leti=0;i<coverage.length;++i){ | ||
| const{ functions, url }=coverage[i]; | ||
| if(StringPrototypeStartsWith(url,'node:')|| | ||
| StringPrototypeIncludes(url,'/node_modules/')|| | ||
| // On Windows some generated coverages are invalid. | ||
| !StringPrototypeStartsWith(url,'file:')){ | ||
| continue; | ||
| } | ||
| // Split the file source into lines. Make sure the lines maintain their | ||
| // original line endings because those characters are necessary for | ||
| // determining offsets in the file. | ||
| @@ -345,8 +338,7 @@ function mapRangeToLines(range, lines){ | ||
| } | ||
| functiongetCoverageFromDirectory(coverageDirectory){ | ||
| // TODO(cjihrig): Instead of only reading the coverage file for this process, | ||
| // combine all coverage files in the directory into a single data structure. | ||
| constresult=newSafeMap(); | ||
| letdir; | ||
| try{ | ||
| @@ -359,13 +351,149 @@ function getCoverageFromDirectory(coverageDirectory){ | ||
| constcoverageFile=join(coverageDirectory,entry.name); | ||
| constcoverage=JSONParse(readFileSync(coverageFile,'utf8')); | ||
| returncoverage.result; | ||
| mergeCoverage(result,coverage.result); | ||
| } | ||
| returnArrayFrom(result.values()); | ||
| }finally{ | ||
| if(dir){ | ||
| dir.closeSync(); | ||
| } | ||
| } | ||
| } | ||
| functionmergeCoverage(merged,coverage){ | ||
| for(leti=0;i<coverage.length;++i){ | ||
| constnewScript=coverage[i]; | ||
| const{ url }=newScript; | ||
| // Filter out core modules and the node_modules/ directory from results. | ||
| if(StringPrototypeStartsWith(url,'node:')|| | ||
| StringPrototypeIncludes(url,'/node_modules/')|| | ||
| // On Windows some generated coverages are invalid. | ||
| !StringPrototypeStartsWith(url,'file:')){ | ||
| continue; | ||
| } | ||
| constoldScript=merged.get(url); | ||
cjihrig marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| if(oldScript===undefined){ | ||
| merged.set(url,newScript); | ||
| }else{ | ||
| mergeCoverageScripts(oldScript,newScript); | ||
| } | ||
| } | ||
| } | ||
| functionmergeCoverageScripts(oldScript,newScript){ | ||
| // Merge the functions from the new coverage into the functions from the | ||
| // existing (merged) coverage. | ||
| for(leti=0;i<newScript.functions.length;++i){ | ||
| constnewFn=newScript.functions[i]; | ||
| letfound=false; | ||
| for(letj=0;j<oldScript.functions.length;++j){ | ||
| constoldFn=oldScript.functions[j]; | ||
| if(newFn.functionName===oldFn.functionName&& | ||
| newFn.ranges?.[0].startOffset===oldFn.ranges?.[0].startOffset&& | ||
| newFn.ranges?.[0].endOffset===oldFn.ranges?.[0].endOffset){ | ||
| // These are the same functions. | ||
| found=true; | ||
| // If newFn is block level coverage, then it will: | ||
| // - Replace oldFn if oldFn is not block level coverage. | ||
| // - Merge with oldFn if it is also block level coverage. | ||
| // If newFn is not block level coverage, then it has no new data. | ||
| if(newFn.isBlockCoverage){ | ||
| if(oldFn.isBlockCoverage){ | ||
| // Merge the oldFn ranges with the newFn ranges. | ||
| mergeCoverageRanges(oldFn,newFn); | ||
| }else{ | ||
| // Replace oldFn with newFn. | ||
| oldFn.isBlockCoverage=true; | ||
| oldFn.ranges=newFn.ranges; | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| if(!found){ | ||
| // This is a new function to track. This is possible because V8 can | ||
| // generate a different list of functions depending on which code paths | ||
| // are executed. For example, if a code path dynamically creates a | ||
| // function, but that code path is not executed then the function does | ||
| // not show up in the coverage report. Unfortunately, this also means | ||
| // that the function counts in the coverage summary can never be | ||
| // guaranteed to be 100% accurate. | ||
| ArrayPrototypePush(oldScript.functions,newFn); | ||
| } | ||
| } | ||
| } | ||
| functionmergeCoverageRanges(oldFn,newFn){ | ||
| constmergedRanges=newSafeSet(); | ||
| // Keep all of the existing covered ranges. | ||
| for(leti=0;i<oldFn.ranges.length;++i){ | ||
| constoldRange=oldFn.ranges[i]; | ||
| if(oldRange.count>0){ | ||
| mergedRanges.add(oldRange); | ||
| } | ||
| } | ||
| // Merge in the new ranges where appropriate. | ||
| for(leti=0;i<newFn.ranges.length;++i){ | ||
| constnewRange=newFn.ranges[i]; | ||
| letexactMatch=false; | ||
| for(letj=0;j<oldFn.ranges.length;++j){ | ||
| constoldRange=oldFn.ranges[j]; | ||
| if(doesRangeEqualOtherRange(newRange,oldRange)){ | ||
| // These are the same ranges, so keep the existing one. | ||
| oldRange.count+=newRange.count; | ||
| mergedRanges.add(oldRange); | ||
| exactMatch=true; | ||
| break; | ||
| } | ||
| // Look at ranges representing missing coverage and add ranges that | ||
| // represent the intersection. | ||
| if(oldRange.count===0&&newRange.count===0){ | ||
| if(doesRangeContainOtherRange(oldRange,newRange)){ | ||
| // The new range is completely within the old range. Discard the | ||
| // larger (old) range, and keep the smaller (new) range. | ||
| mergedRanges.add(newRange); | ||
| }elseif(doesRangeContainOtherRange(newRange,oldRange)){ | ||
| // The old range is completely within the new range. Discard the | ||
| // larger (new) range, and keep the smaller (old) range. | ||
| mergedRanges.add(oldRange); | ||
| } | ||
| } | ||
| } | ||
| // Add new ranges that do not represent missing coverage. | ||
| if(newRange.count>0&&!exactMatch){ | ||
| mergedRanges.add(newRange); | ||
| } | ||
| } | ||
| oldFn.ranges=ArrayFrom(mergedRanges); | ||
| } | ||
| functiondoesRangeEqualOtherRange(range,otherRange){ | ||
| returnrange.startOffset===otherRange.startOffset&& | ||
| range.endOffset===otherRange.endOffset; | ||
| } | ||
| functiondoesRangeContainOtherRange(range,otherRange){ | ||
| returnrange.startOffset<=otherRange.startOffset&& | ||
| range.endOffset>=otherRange.endOffset; | ||
| } | ||
| module.exports={ setupCoverage }; | ||
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
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,69 @@ | ||
| 'use strict'; | ||
| functionfnA(){ | ||
| letcnt=0; | ||
| try{ | ||
| cnt++; | ||
| thrownewError('boom'); | ||
| cnt++; | ||
| }catch(err){ | ||
| cnt++; | ||
| }finally{ | ||
| if(false){ | ||
| } | ||
| returncnt; | ||
| } | ||
| cnt++; | ||
| } | ||
| functionfnB(arr){ | ||
| for(leti=0;i<arr.length;++i){ | ||
| if(i===2){ | ||
| continue; | ||
| }else{ | ||
| fnE(1); | ||
| } | ||
| } | ||
| } | ||
| functionfnC(arg1,arg2){ | ||
| if(arg1===1){ | ||
| if(arg2===3){ | ||
| return-1; | ||
| } | ||
| if(arg2===4){ | ||
| return3; | ||
| } | ||
| if(arg2===5){ | ||
| return9; | ||
| } | ||
| } | ||
| } | ||
| functionfnD(arg){ | ||
| letcnt=0; | ||
| if(arg%2===0){ | ||
| cnt++; | ||
| }elseif(arg===1){ | ||
| cnt++; | ||
| }elseif(arg===3){ | ||
| cnt++; | ||
| }else{ | ||
| fnC(1,5); | ||
| } | ||
| returncnt; | ||
| } | ||
| functionfnE(arg){ | ||
| consta=arg??5; | ||
| returna; | ||
| } | ||
| module.exports={ fnA, fnB, fnC, fnD, fnE }; |
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' | ||
| const{test } = require('node:test'); | ||
| const common = require('./common'); | ||
| function notCalled(){ | ||
| } | ||
| test('first 1', () =>{ | ||
| common.fnA(); | ||
| common.fnD(100); | ||
| common.fnB([1, 2, 3]); | ||
| }); |
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,8 @@ | ||
| 'use strict' | ||
| const{test } = require('node:test'); | ||
| const common = require('./common'); | ||
| test('second 1', () =>{ | ||
| common.fnB([1, 2, 3]); | ||
| common.fnD(3); | ||
| }); |
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,8 @@ | ||
| 'use strict'; | ||
| const{ test }=require('node:test'); | ||
| constcommon=require('./common'); | ||
| test('third 1',()=>{ | ||
| common.fnC(1,4); | ||
| common.fnD(99); | ||
| }); |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.