untilConsoleLog() — vite Function Reference
Architecture documentation for the untilConsoleLog() function in hmr-ssr.spec.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD d934b93a_55ae_d127_f94e_413ed5ae3fc9["untilConsoleLog()"] 2f2e510b_d491_14bf_c7ee_0c390a8b3218["hmr-ssr.spec.ts"] d934b93a_55ae_d127_f94e_413ed5ae3fc9 -->|defined in| 2f2e510b_d491_14bf_c7ee_0c390a8b3218 4683aae9_ed38_13f7_9722_9bb9c593adfb["untilConsoleLogAfter()"] 4683aae9_ed38_13f7_9722_9bb9c593adfb -->|calls| d934b93a_55ae_d127_f94e_413ed5ae3fc9 style d934b93a_55ae_d127_f94e_413ed5ae3fc9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
playground/hmr-ssr/__tests__/hmr-ssr.spec.ts lines 996–1075
async function untilConsoleLog(
target?: string | RegExp | Array<string | RegExp>,
expectOrder = true,
): Promise<string[]> {
const { promise, resolve, reject } = promiseWithResolvers<void>()
let timeoutId: ReturnType<typeof setTimeout>
const logsMessages = []
try {
const isMatch = (matcher: string | RegExp) => (text: string) =>
typeof matcher === 'string' ? text === matcher : matcher.test(text)
let processMsg: (text: string) => boolean
if (!target) {
processMsg = () => true
} else if (Array.isArray(target)) {
if (expectOrder) {
const remainingTargets = [...target]
processMsg = (text: string) => {
const nextTarget = remainingTargets.shift()
expect(text).toMatch(nextTarget)
return remainingTargets.length === 0
}
} else {
const remainingMatchers = target.map(isMatch)
processMsg = (text: string) => {
const nextIndex = remainingMatchers.findIndex((matcher) =>
matcher(text),
)
if (nextIndex >= 0) {
remainingMatchers.splice(nextIndex, 1)
}
return remainingMatchers.length === 0
}
}
} else {
processMsg = isMatch(target)
}
const handleMsg = (text: string) => {
try {
text = text.replace(/\n$/, '')
logsMessages.push(text)
const done = processMsg(text)
if (done) {
resolve()
logsEmitter.off('log', handleMsg)
}
} catch (err) {
reject(err)
logsEmitter.off('log', handleMsg)
}
}
timeoutId = setTimeout(() => {
const nextTarget = Array.isArray(target)
? expectOrder
? target[0]
: target.join(', ')
: target
reject(
new Error(
`Timeout waiting for console logs. Waiting for: ${nextTarget}`,
),
)
logsEmitter.off('log', handleMsg)
}, 5000)
logsEmitter.on('log', handleMsg)
} catch (err) {
reject(err)
}
await promise
clearTimeout(timeoutId)
return logsMessages
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does untilConsoleLog() do?
untilConsoleLog() is a function in the vite codebase, defined in playground/hmr-ssr/__tests__/hmr-ssr.spec.ts.
Where is untilConsoleLog() defined?
untilConsoleLog() is defined in playground/hmr-ssr/__tests__/hmr-ssr.spec.ts at line 996.
What calls untilConsoleLog()?
untilConsoleLog() is called by 1 function(s): untilConsoleLogAfter.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free