-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support reporters #10
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
2c70756
Support reporters
mcollina f79cf1d
fixup
mcollina 4efd9c6
fixup
mcollina 121117e
fixup
mcollina b49c13d
fixup
mcollina 23a30e5
fixup
mcollina d357876
fixup
mcollina 2f00c1b
fixup
mcollina 4e51c24
fixup
mcollina 4b0d434
fixup
mcollina e29e731
fixup
mcollina 238eb1b
implement md reporter
mcollina c950701
fixup
mcollina 0281c2c
fixup
mcollina a52619c
fixup
mcollina d98d429
fixup
mcollina e929c16
fixup
mcollina d3dcaf8
fixup
mcollina 1d94e56
fixup
mcollina cae5f9f
fixup
mcollina 9eb610d
Add tests for reports
mcollina 5c60620
fixup
mcollina 3545a3d
fixup
mcollina bf63ec9
fixup
mcollina d5b62ed
fixup
mcollina 057692f
fixup
mcollina 059613f
fixup
mcollina 99293de
fixup
mcollina 1c86df4
fixup
mcollina 4bb4699
fixup
mcollina 19c5edc
fixup
mcollina 18ad832
fixup
mcollina 1a414b5
fixup
mcollina 815bc98
fixup
mcollina 787a677
docs
mcollina 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
This file contains 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 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 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 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,114 @@ | ||
import { Transform } from 'node:stream' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
function normalizeFile (file, cwd) { | ||
let res = file | ||
if (file.startsWith('file://')) { | ||
try { | ||
res = fileURLToPath(new URL(file)) | ||
} catch (err) { | ||
if (err.code === 'ERR_INVALID_FILE_URL_PATH') { | ||
res = fileURLToPath(new URL(file.replace('file:///', 'file://'))) | ||
} | ||
} | ||
} | ||
res = res.replace(cwd, '') | ||
if (res.startsWith('/') || res.startsWith('\\')) { | ||
res = res.slice(1) | ||
} | ||
return res | ||
} | ||
|
||
function eventToLine (event) { | ||
return `* __${event.data.name}__, duration ${event.data.details.duration_ms}ms, line ${event.data.line}\n` | ||
} | ||
|
||
export class MarkdownReporter extends Transform { | ||
constructor (opts) { | ||
super({ | ||
...opts, | ||
objectMode: true | ||
}) | ||
|
||
this._files = {} | ||
this._cwd = opts?.cwd | ||
} | ||
|
||
getFile (path) { | ||
const file = this._files[path] || { | ||
pass: [], | ||
fail: [] | ||
} | ||
this._files[path] = file | ||
return file | ||
} | ||
|
||
_transform (event, encoding, callback) { | ||
if (!event.data.file) { | ||
callback() | ||
return | ||
} | ||
|
||
const path = normalizeFile(event.data.file, this._cwd) | ||
const file = this.getFile(path) | ||
switch (event.type) { | ||
case 'test:pass': | ||
file.pass.push(event) | ||
break | ||
case 'test:fail': | ||
file.fail.push(event) | ||
break | ||
} | ||
|
||
callback() | ||
} | ||
|
||
_flush (callback) { | ||
this.push('# Summary\n') | ||
for (const [path, file] of Object.entries(this._files)) { | ||
this.push(`## ${path}\n`) | ||
if (file.pass.length > 0) { | ||
this.push('### :white_check_mark: Pass\n') | ||
for (const event of file.pass) { | ||
this.push(eventToLine(event)) | ||
} | ||
} | ||
if (file.fail.length > 0) { | ||
this.push('### :x: Fail\n') | ||
for (const event of file.fail) { | ||
this.push(eventToLine(event)) | ||
} | ||
} | ||
} | ||
this.push(null) | ||
callback() | ||
} | ||
} | ||
|
||
export class GithubWorkflowFailuresReporter extends Transform { | ||
constructor (opts) { | ||
super({ | ||
...opts, | ||
objectMode: true | ||
}) | ||
|
||
this._files = {} | ||
this._cwd = opts?.cwd | ||
} | ||
|
||
_transform (event, encoding, callback) { | ||
if (!event.data.file) { | ||
callback() | ||
return | ||
} | ||
|
||
const path = normalizeFile(event.data.file, this._cwd) | ||
switch (event.type) { | ||
case 'test:fail': | ||
this.push(`::error file=${path},line=${event.data.line}::${event.data.name}\n`) | ||
break | ||
} | ||
|
||
callback() | ||
} | ||
} |
This file contains 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 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 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
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.
I don't think your assesment is correct here, my understanding is that the URL that failed to be converted to path is
file:///foo/test/add.test.ts
, which indeed does not make sense on Windows. But that's a value constructed in your tests, not one generated by the test runner IIUC.I'll try to send a PR.
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 was failing with a Windows path.
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.
#13