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+
functionfreezeClock(): void{
43+
constnow=Date.now()
44+
vi.spyOn(Date,'now').mockReturnValue(now)
45+
}
46+
4047
functionreporter(animated: boolean): StartupReporter{
4148
constinstance=createStartupReporter({ animated })
4249
reporters.push(instance)
4350
returninstance
4451
}
4552

4653
it('should keep the progress line in place while loading',async()=>{
54+
freezeClock()
4755
constrenderer=awaitrender(()=>{
4856
conststartup=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
constrenderer=awaitrender(async()=>{
153162
constrestore=wrapStdoutAsConsolaDoes()
154163
try{

0 commit comments

Comments
 (0)