From 50189ad4531f7a22142d7f9213bd4e21d47779c6 Mon Sep 17 00:00:00 2001 From: Spencer Tuft Date: Fri, 26 Jul 2024 16:20:52 -0600 Subject: [PATCH] test: fix faked clock --- test/production.spec.ts | 14 ++++++++------ test/test.spec.ts | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/production.spec.ts b/test/production.spec.ts index da8bd64..4a25238 100644 --- a/test/production.spec.ts +++ b/test/production.spec.ts @@ -12,6 +12,13 @@ interface Context { const test = ava as TestFn +test.before((t) => { + /* Stub the date time */ + const jan1st = new Date(2021, 0, 1) + t.context.now = jan1st + t.context.clock = sinon.useFakeTimers(jan1st.getTime()) +}) + test.beforeEach((t) => { /* Capture the stdout pipe */ process.stdout.write = (buffer: string) => { @@ -19,17 +26,12 @@ test.beforeEach((t) => { return true } - /* Stub the date time */ - const jan1st = new Date(2021, 0, 1) - t.context.now = jan1st - t.context.clock = sinon.useFakeTimers(jan1st.getTime()) - process.env.NODE_ENV = 'production' t.context.logged = '' t.context.logger = ByuLogger() }) -test.afterEach((t) => { +test.after((t) => { t.context.clock.restore() }) diff --git a/test/test.spec.ts b/test/test.spec.ts index 274e9e3..8c98003 100644 --- a/test/test.spec.ts +++ b/test/test.spec.ts @@ -12,6 +12,13 @@ interface Context { const test = ava as TestFn +test.before((t) => { + /* Stub the date time */ + const jan1st = new Date(2021, 0, 1) + t.context.now = jan1st + t.context.clock = sinon.useFakeTimers(jan1st.getTime()) +}) + test.beforeEach((t) => { /* Capture the stdout pipe */ process.stdout.write = (buffer: string) => { @@ -19,17 +26,12 @@ test.beforeEach((t) => { return true } - /* Stub the date time */ - const jan1st = new Date(2021, 0, 1) - t.context.now = jan1st - t.context.clock = sinon.useFakeTimers(jan1st.getTime()) - process.env.NODE_ENV = 'test' t.context.logged = '' t.context.logger = ByuLogger() }) -test.afterEach((t) => { +test.after((t) => { t.context.clock.restore() })