-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add formatter plugins and start reimplementing builtins #2400
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
358abbb
wip initial implementation
davidjgoss 3c93cbf
refactor to allow custom formatter plugins
davidjgoss e4e78cf
test permutations of resolving
davidjgoss ade5f14
refactor find logic
davidjgoss 8ff54d6
Merge branch 'main' into feat/new-formatter-part-1
davidjgoss File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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,25 @@ | ||
import { promisify } from 'node:util' | ||
import { finished } from 'node:stream' | ||
import CucumberHtmlStream from '@cucumber/html-formatter' | ||
import resolvePkg from 'resolve-pkg' | ||
import { FormatterPlugin } from '../../plugin' | ||
|
||
export default { | ||
type: 'formatter', | ||
formatter({ on, write }) { | ||
const htmlStream = new CucumberHtmlStream( | ||
resolvePkg('@cucumber/html-formatter', { cwd: __dirname }) + | ||
'/dist/main.css', | ||
resolvePkg('@cucumber/html-formatter', { cwd: __dirname }) + | ||
'/dist/main.js' | ||
) | ||
on('message', (message) => htmlStream.write(message)) | ||
htmlStream.on('data', (chunk) => write(chunk)) | ||
|
||
return async () => { | ||
htmlStream.end() | ||
await promisify(finished)(htmlStream) | ||
} | ||
}, | ||
documentation: 'Outputs a HTML report', | ||
} satisfies FormatterPlugin |
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,30 @@ | ||
import { FormatterImplementation } from '../index' | ||
import JsonFormatter from '../json_formatter' | ||
import ProgressFormatter from '../progress_formatter' | ||
import ProgressBarFormatter from '../progress_bar_formatter' | ||
import RerunFormatter from '../rerun_formatter' | ||
import SnippetsFormatter from '../snippets_formatter' | ||
import SummaryFormatter from '../summary_formatter' | ||
import UsageFormatter from '../usage_formatter' | ||
import UsageJsonFormatter from '../usage_json_formatter' | ||
import JunitFormatter from '../junit_formatter' | ||
import messageFormatter from './message' | ||
import htmlFormatter from './html' | ||
|
||
const builtin: Record<string, FormatterImplementation> = { | ||
// new plugin-based formatters | ||
html: htmlFormatter, | ||
message: messageFormatter, | ||
// legacy class-based formatters | ||
json: JsonFormatter, | ||
progress: ProgressFormatter, | ||
'progress-bar': ProgressBarFormatter, | ||
rerun: RerunFormatter, | ||
snippets: SnippetsFormatter, | ||
summary: SummaryFormatter, | ||
usage: UsageFormatter, | ||
'usage-json': UsageJsonFormatter, | ||
junit: JunitFormatter, | ||
} | ||
|
||
export default builtin |
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,9 @@ | ||
import { FormatterPlugin } from '../../plugin' | ||
|
||
export default { | ||
type: 'formatter', | ||
formatter({ on, write }) { | ||
on('message', (message) => write(JSON.stringify(message) + '\n')) | ||
}, | ||
documentation: 'Emits Cucumber messages in NDJSON format', | ||
} satisfies FormatterPlugin |
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,31 @@ | ||
import path from 'node:path' | ||
import { Writable } from 'node:stream' | ||
import { mkdirp } from 'mkdirp' | ||
import fs from 'mz/fs' | ||
import { ILogger } from '../logger' | ||
|
||
export async function createStream( | ||
target: string, | ||
onStreamError: () => void, | ||
cwd: string, | ||
logger: ILogger | ||
): Promise<Writable> { | ||
const absoluteTarget = path.resolve(cwd, target) | ||
|
||
try { | ||
await mkdirp(path.dirname(absoluteTarget)) | ||
} catch (error) { | ||
logger.warn('Failed to ensure directory for formatter target exists') | ||
} | ||
|
||
const stream: Writable = fs.createWriteStream(null, { | ||
fd: await fs.open(absoluteTarget, 'w'), | ||
}) | ||
|
||
stream.on('error', (error: Error) => { | ||
logger.error(error.message) | ||
onStreamError() | ||
}) | ||
|
||
return stream | ||
} |
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.
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.
Cleaning up formatter streams should happen after formatter plugins have had a chance to do their own cleaning up.