-
Notifications
You must be signed in to change notification settings - Fork 176
Original files in HTML reporter #648
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
Conversation
| '<div> while ( </div><div class="miss false" data-tooltip>value ) </div><div>{</div>']); | ||
| expect(output, 'missed original line not included').to.contains([ | ||
| '<tr class="miss">', | ||
| '<td class="source" data-tooltip> value = false;</td>']); |
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.
These are more specific assertion to test particular cases: chunks, missed lines, original filename, comments...
| exports.method = function (value) { | ||
|
|
||
| while (value) { | ||
| while ( value ) { |
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.
To make a difference between generated and original file, especially for chunks handling.
|
Sorry, for missing coverage, I'll fix it tomorrow. As I'm on windows, even when using ubuntu bash I can't run all the tests locally. It hangs, and sometimes even crash with a good old segfault 😀 |
lib/coverage.js
Outdated
| line: num, | ||
| column: chunk.column | ||
| }); | ||
| chunk.originalFilename = originalPosition.source.replace(Path.join(process.cwd(), '/').replace(/\\/g, '/'), ''); |
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.
Will Path.basename(originalPosition.source); work instead?
https://nodejs.org/api/path.html#path_path_basename_path_ext
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.
I've copy-pasted this from line 404, but I'll give a try, because using basename is definitely more understandable !
|
@feugy looks like a great improvement to our reporting. Thanks! |
|
Just to let you know: I've found that inlined and external source maps are not reported the same due to my latest modification. So my TODO list is:
|
|
Supporting inline maps involved a huge refactor, but it's nearly done. @geek while trying to figure out how to get sloc and hits in original files, I found that any lines are considered as "line of code", even comments ( Did I missed something ? |
lib/coverage.js
Outdated
| if (position !== originalPosition) { | ||
| source.originalFilename = originalPosition.source.replace(Path.join(process.cwd(), '/').replace(/\\/g, '/'), ''); | ||
| // Ensure folder separator to be url-friendly | ||
| source.originalFilename = originalPosition.source && originalPosition.source.replace(/\\/g, '/'); |
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.
Sourcemaps always expect path to use / separator, as URLs does, so we need to do the replacement.
Removing process.cwd() is useless as the sourcemap won't contain it.
|
|
||
| if (options.sourcemaps) { | ||
| internals.addSourceMapsInformation(ret, +num); | ||
| } |
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.
Move to the end of the loop, because we need to have the chunk before adding sourcemaps information
|
|
||
| for (let i = 0; i < lint.length; ++i) { | ||
| if (lint[i].filename.slice(-file.filename.length) === file.filename && lint[i].errors.length) { | ||
| if (lint[i].filename.replace(/\\/g, '/').slice(-file.filename.length) === file.filename && lint[i].errors.length) { |
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.
lint.filename is platform dependant, which is ok (notably when we fix lint issues), but file.filename always use /, so we need to to the replacement.
| <div id="filters"> | ||
| <input type="checkbox" checked="" onchange="filter(this)" value="generated" id="show-generated"> | ||
| <label for="show-generated">Show generated files</label> | ||
| </div> |
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.
From now, reporter displays both original and generated sources.
This toggle allows to show/hide generated files.
|
|
||
| .show { | ||
| position: relative; | ||
| display: inherit; |
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.
Otherwise, hidden generated files take some height in right-menu.
| <div class="file"> | ||
| <h2 id="{{this.filename}}">{{this.filename}}</h2> | ||
| <div class="file {{#if this.sourcemaps}}show generated{{/if}}"> | ||
| <h2 id="{{this.filename}}">{{this.filename}} {{#if this.generated}}(transformed to <a href="#{{this.generated}}">{{this.generated}})</a>{{/if}}</h2> |
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.
Link to the corresponding generated file.
| {{else}} | ||
| <td class="source"{{#if this.miss}} data-tooltip{{/if}}>{{this.source}}</td> | ||
| {{/if}} | ||
| {{#if this.originalFilename}}<td class="original-line" data-tooltip="{{this.originalFilename}}"><a href="#{{this.originalFilename}}__{{this.originalLine}}">{{this.originalLine}}</a></td>{{/if}} |
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.
If displaying a generated file, link to original file and line.
| <td class="sourcemaps line" data-tooltip>{{this.originalLine}}</td> | ||
| {{/if}} | ||
| </tr> | ||
| {{/if}} |
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 condensed version of previous code, to limit code duplication, although I agree it's less readable.
I've added a unic ID on each line to allow reference from generated files.
One possible improvement is to remove this. which are optional (handlebars implicitly look into this)
| { filename: 'test/coverage/while.js', lineNumber: '5', originalLineNumber: 11 }, | ||
| { filename: 'test/coverage/while.js', lineNumber: '6', originalLineNumber: 12 } | ||
| { filename: 'while.js', lineNumber: '4', originalLineNumber: 13 }, | ||
| { filename: 'while.js', lineNumber: '5', originalLineNumber: 14 } |
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.
Due to different test fixture, compiled with babel instead of traceur.
test/coverage.js
Outdated
| expect(missedLines).to.include([ | ||
| { filename: './while.js', lineNumber: '5', originalLineNumber: 11 }, | ||
| { filename: './while.js', lineNumber: '6', originalLineNumber: 12 } | ||
| { filename: 'while.js', lineNumber: '3', originalLineNumber: 8 } |
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.
The fact that only one missing line is detected is a possible bug.
I've replaced the sourcemaps-inline.js with a newer version processed by babel, and compacted into a single line:
'use strict';// Load modules
// Declare internals
const internals={};exports.method=function(value){while(value){value=false;}return value;};
//# sourceMappingURL=data:application/json;base64,...Coverage detects that while(value) is always false, but doesn't detect that value=false is never reached.
This only happens when generated file is compacted, I'll dig that a little more.
EDIT
The line is properly detected as missed, but because generated code is only on a single line, we need to checked missed chunks also.
| expect(Test.method.toString()).to.not.contain('13'); // This is the line of the inner use strict | ||
|
|
||
| const testFile = Path.join(__dirname, 'coverage/use-strict.js'); | ||
| const testFile = Path.join(__dirname, 'coverage/use-strict.js').replace(/\\/g, '/'); |
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.
To run tests on Windows
| Fs.writeFileSync = (path, output) => { | ||
|
|
||
| expect(path).to.endWith('test/lint/eslint/fix/success.js'); | ||
| expect(path).to.endWith(Path.join('test', 'lint', 'eslint', 'fix', 'success.js')); |
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.
To run tests on Windows
| }); | ||
| }); | ||
|
|
||
| Lab.report(script, { reporter: 'console', progress: 2, output: false }, (err, code, output) => { |
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.
All modifications here are needed to run tests on Windows
package.json
Outdated
| "test-cov-html": "./bin/_lab -fL -r html -m 3000 -o coverage.html", | ||
| "lint": "./bin/_lab -d -f -L", | ||
| "test-cov-html": "node bin/_lab -fL -r html -m 3000 -o coverage.html", | ||
| "lint": "node bin/_lab -d -f -L", |
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.
Unfortunately, Windows' cmd and Powershell doesn't understand the ./ syntax.
By using node invokation, we ensure a portable command.
| } | ||
| }); | ||
| done(); | ||
| }); |
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.
On Windows, global keys can actually be deleted, which makes those test not runnable.
I refactored them to:
- automatically delete globals set to 1, and not delete the pre-existing values
- check all counter globals existence and absence.
|
@feugy I think you found a bug that we are counting comments towards lines of code :/ |
|
@feugy everything here looks like really good changes. After the fix for the sloc, ping me and I will give it one final review before merging. Awesome work! |
|
@feugy any luck finding time to look at this PR again... it looks very close to being complete. |
Sloc and coverage display are broken for now
HTML reporter now displays original and generated files (a toggle allows to hide them). Hits, sloc and misses are still broken in original files.
Don't show sloc/percentage on generated file content in Html reporter.
|
Hello @geek ! For Html reporter, I've finally decided to hide sloc counter / coverage percentage on original files, to only show them on generated files. In fact, sourcemaps allow to reverse the original file content, but can't be blindly used to recompute SLOC & coverage. But this leads me to another (and way more important) fix.
I've fixed this, to rely only on the AST output. Now SLOC is:
All this works (I've added another test), but has an unexpected impact: it mechanically lower the overall coverage percentage. I leave you the final appreciation, I can easily revert the SLOC computation to what it was before. |
| expect(result.code).to.equal(1); | ||
| expect(result.output).to.contain('1 tests complete'); | ||
| expect(result.output).to.contain('Coverage: 92.86% (1/14)'); | ||
| expect(result.output).to.contain('Coverage: 90.00% (1/10)'); |
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.
Due to the new SLOC algorithm
| expect(cov.sloc).to.equal(49); | ||
| expect(cov.misses).to.equal(19); | ||
| expect(cov.hits).to.equal(33); | ||
| expect(cov.hits).to.equal(30); |
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.
Due to the new SLOC algorithm
| expect(cov.sloc).to.equal(12); | ||
| expect(cov.misses).to.equal(0); | ||
| expect(cov.hits).to.equal(16); | ||
| expect(cov.hits).to.equal(12); |
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.
Due to the new SLOC algorithm
test/coverage.js
Outdated
| expect(cov.sloc).to.equal(13); | ||
| expect(cov.misses).to.equal(1); | ||
| expect(cov.hits).to.equal(15); | ||
| expect(cov.hits).to.equal(10); |
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.
Due to the new SLOC algorithm
| expect(err).not.to.exist(); | ||
| expect(output).to.contain('<div class="stats medium">'); | ||
| expect(output).to.contain('<span class="cov medium">71.43</span>'); | ||
| expect(output).to.contain('<span class="cov medium">66.67</span>'); |
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.
Due to the new SLOC algorithm
|
@feugy looks good so far, I am going to take a closer look later and merge/release. |
|
@feugy do we need the |
|
@feugy if you run the html report on lab it will report |
|
@geek about the report.html, its a mistake (test outputs I've forgot to delete). About the coverage, I'm more concerned: there must be an some lines I've considered as commented and that were hit. |
|
@geek, nicely spotted ! It was the opportunity for me to refactor the code, and use only the AST to detect commented lines. Can you please give a try ? |
|
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
This is a first attempt to fix #614.
My idea is to adapt the HTML report to display original files when source maps is present.
It works well, notably to display uncovered lines or statement.
Sloc number, coverage percent and "covered/not covered" counter are wrong for now, because they are computed from generated files, and not from original files.
I had to update the
while.jstest fixture using latest traceur to make sure we display original source with comment and white spaces, and this explains the small fixes on coverage tests.