Skip to content
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

Update log.js to support async reporter plugins #71

Merged
merged 4 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/file-set-pipeline/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function log(context, settings) {
func = settings.reporter
}

let diagnostics = func(
let diagnostics = await func(
context.files.filter(
(file) => file.data.unifiedEngineGiven && !file.data.unifiedEngineIgnored
),
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @callback VFileReporter
* @param {Array<VFile>} files
* @param {VFileReporterOptions} options
* @returns {string}
* @returns {string | Promise<string>}
*
* @typedef Settings
* @property {Options['processor']} processor
Expand Down
26 changes: 26 additions & 0 deletions test/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const windows = process.platform === 'win32'
const cross = windows ? '×' : '✖'
const danger = windows ? '‼' : '⚠'

/** @type {import('unified-engine').VFileReporter} */
const vfileReporterPrettyAsync = async (files) => vfileReporterPretty(files)

// See: <https://github.com/sindresorhus/eslint-formatter-pretty/blob/159b30a/index.js#L90-L93>.
const original = process.env.CI

Expand Down Expand Up @@ -169,6 +172,29 @@ test('reporting', async () => {
)
})

await new Promise((resolve) => {
const stderr = spy()

engine(
{
processor: noop(),
cwd: new URL('two-files/', fixtures),
streamError: stderr.stream,
files: ['.'],
extensions: ['txt'],
reporter: vfileReporterPrettyAsync
},
(error, code) => {
assert.deepEqual(
[error, code, stripAnsi(stderr())],
[null, 0, ''],
'should support async reporters'
)
resolve(undefined)
}
)
})

await new Promise((resolve) => {
const stderr = spy()
const cwd = new URL('two-files/', fixtures)
Expand Down