Skip to content

Commit eacb946

Browse files
committed
test: freeze clock when testing startup logs
1 parent cd9735e commit eacb946

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/nuxt-cli/test/unit/dev-startup-log.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,23 @@ describe('startup reporter', () => {
3535

3636
afterEach(() => {
3737
reporters.splice(0).forEach(reporter => reporter.stop())
38+
vi.restoreAllMocks()
3839
})
3940

41+
/** The transient line renders elapsed time from the wall clock, which would otherwise tick between the update and the assertion. */
42+
function freezeClock(): void {
43+
const now = Date.now()
44+
vi.spyOn(Date, 'now').mockReturnValue(now)
45+
}
46+
4047
function reporter(animated: boolean): StartupReporter {
4148
const instance = createStartupReporter({ animated })
4249
reporters.push(instance)
4350
return instance
4451
}
4552

4653
it('should keep the progress line in place while loading', async () => {
54+
freezeClock()
4755
const renderer = await render(() => {
4856
const startup = reporter(true)
4957
startup.update(snapshot())
@@ -149,6 +157,7 @@ describe('startup reporter', () => {
149157
}
150158

151159
it('should keep the progress line in place under the dev console wrapper', async () => {
160+
freezeClock()
152161
const renderer = await render(async () => {
153162
const restore = wrapStdoutAsConsolaDoes()
154163
try {

0 commit comments

Comments
 (0)