-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add quiet test output mode #61
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
base: main
Are you sure you want to change the base?
Changes from all commits
70bf1dd
1c0613d
b049b10
4c8edc2
a9fa83e
f1117a0
4f07b3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,13 +26,17 @@ export const format = (chunk) => { | |
|
|
||
| const formatTime = (ms) => (ms ? color(` (${ms}ms)`, dim) : '') | ||
| const formatSuffix = (d) => `${formatTime(d.details.duration_ms)}${d.todo ? ' # TODO' : ''}` | ||
| const isNodeTestSummaryDiagnostic = (message) => | ||
| /^(suites|tests|pass|fail|cancelled|skipped|todo) \d+$/.test(message) || | ||
| /^duration_ms \d+(?:\.\d+)?$/.test(message) | ||
|
|
||
| const cwd = process.cwd() | ||
| const INBAND_PREFIX = 'EXODUS_TEST_INBAND:' | ||
| const inbandFileAbsolute = fileURLToPath(import.meta.resolve('./inband.js')) | ||
| const inbandFile = relative(cwd, inbandFileAbsolute) | ||
|
|
||
| const groupCI = CI && !process.execArgv.includes('--watch') && !LERNA_PACKAGE_NAME // lerna+nx groups already | ||
| const quiet = process.env.EXODUS_TEST_QUIET === '1' | ||
| export const timeLabel = color('Total time', dim) | ||
| const filename = (f) => (f === inbandFile || f === inbandFileAbsolute ? 'In-band tests' : f) | ||
| export const head = groupCI ? () => {} : (file) => console.log(color(`# ${filename(file)}`, 'bold')) | ||
|
|
@@ -100,9 +104,24 @@ export default async function nodeTestReporterExodus(source) { | |
| }) | ||
|
|
||
| const log = [] | ||
| const print = (msg) => (groupCI ? log.push(msg) : console.log(msg)) | ||
| const buffered = groupCI || quiet | ||
| const print = (msg) => (buffered ? log.push(msg) : console.log(msg)) | ||
| const dumpDiagnostics = () => { | ||
| if (!quiet || failedFiles.size > 0) { | ||
| for (const line of diagnostic) console.log(line) | ||
| } | ||
|
|
||
| diagnostic.length = 0 | ||
| } | ||
|
|
||
| const dump = () => { | ||
| middle(file, !failedFiles.has(file)) | ||
| const ok = !failedFiles.has(file) | ||
| if (quiet && ok) { | ||
| log.length = 0 | ||
| return | ||
| } | ||
|
|
||
| middle(file, ok) | ||
| for (const line of log) console.log(line) | ||
| log.length = 0 | ||
| tail() | ||
|
|
@@ -114,6 +133,14 @@ export default async function nodeTestReporterExodus(source) { | |
| let file | ||
| const diagnostic = [] | ||
| const delayed = [] | ||
| const finishWatchCycle = () => { | ||
| if (file !== undefined) dump() | ||
| dumpDiagnostics() | ||
| delayed.length = 0 | ||
| failedFiles.clear() | ||
| file = undefined | ||
| } | ||
|
|
||
| const isTopLevelTest = ({ nesting, line, column, name, file }) => | ||
| nesting === 0 && line === 1 && column === 1 && file.endsWith(name) && resolve(name) === file // some events have data.file resolved, some not) | ||
| const processNewFile = (data) => { | ||
|
|
@@ -123,7 +150,9 @@ export default async function nodeTestReporterExodus(source) { | |
| if (file !== undefined) dump() | ||
| file = newFile | ||
| assert(files.has(file), 'Cound not determine file') | ||
| head(file) | ||
| // quiet (non-CI): buffer the header so it only prints for failing suites (under CI, middle() emits it) | ||
| if (quiet && !groupCI) log.push(color(`# ${filename(file)}`, 'bold')) | ||
| else head(file) | ||
| } | ||
|
|
||
| const pathstr = (p) => (p[0]?.startsWith(INBAND_PREFIX) ? p.slice(1) : p).join(' > ') | ||
|
|
@@ -149,8 +178,11 @@ export default async function nodeTestReporterExodus(source) { | |
| while (delayed.length > 0) print(delayed.shift()) | ||
| break | ||
| case 'test:pass': | ||
| const label = data.skip ? color('⏭ SKIP ', dim) : color('✔ PASS ', 'green') | ||
| if (!pskip(path)) print(`${label}${pathstr(path)}${formatSuffix(data)}`) | ||
| if (!quiet) { | ||
| const label = data.skip ? color('⏭ SKIP ', dim) : color('✔ PASS ', 'green') | ||
| if (!pskip(path)) print(`${label}${pathstr(path)}${formatSuffix(data)}`) | ||
| } | ||
|
Comment on lines
+181
to
+184
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if architecturally this could've been done in a more extensible way e.g. abstract this behind a reporter interface that receives the log output and internally decides whether to buffer, print right away, remove parts of the output, etc.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but a much bigger refactor |
||
|
|
||
| assert(path.pop() === data.name) | ||
| break | ||
| case 'test:fail': | ||
|
|
@@ -170,10 +202,12 @@ export default async function nodeTestReporterExodus(source) { | |
| break | ||
| case 'test:watch:drained': | ||
| assert(!groupCI, 'Can not mix --watch with CI grouping') | ||
| if (quiet) finishWatchCycle() | ||
| console.log(color(`ℹ waiting for changes as we are in --watch mode`, 'blue')) | ||
| break | ||
| case 'test:diagnostic': | ||
| if (/^suites \d+$/.test(data.message)) break // we count suites = files | ||
| if (quiet && isNodeTestSummaryDiagnostic(data.message)) break // summary() prints the result | ||
| diagnostic.push(color(`ℹ ${data.message}`, 'blue')) | ||
| break | ||
| case 'test:stderr': | ||
|
|
@@ -188,7 +222,11 @@ export default async function nodeTestReporterExodus(source) { | |
| } | ||
|
|
||
| dump() | ||
| for (const line of delayed) console.log(line) | ||
| for (const line of diagnostic) console.log(line) | ||
| if (!quiet) { | ||
| for (const line of delayed) console.log(line) | ||
| } | ||
|
|
||
| dumpDiagnostics() | ||
|
|
||
| summary([...files], [...failedFiles]) | ||
| } | ||
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.
shouldn't this also be using setEnv to warn of conflicts in case the env var is already set?
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.
it currently it silently ignores the EXODUS_TEST_QUIET env var. I don't think we need to support two modes (env var and cli flag) for every single thing, or even most things, but let's wait to hear from @ChALkeR