Skip to content

Commit

Permalink
test: fix faked clock
Browse files Browse the repository at this point in the history
  • Loading branch information
stuft2 committed Jul 26, 2024
1 parent 0968693 commit 50189ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions test/production.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ interface Context {

const test = ava as TestFn<Context>

test.before((t) => {
/* Stub the date time */
const jan1st = new Date(2021, 0, 1)

Check failure on line 17 in test/production.spec.ts

View workflow job for this annotation

GitHub Actions / Lint Module

Expected indentation of 2 spaces but found 4
t.context.now = jan1st

Check failure on line 18 in test/production.spec.ts

View workflow job for this annotation

GitHub Actions / Lint Module

Expected indentation of 2 spaces but found 4
t.context.clock = sinon.useFakeTimers(jan1st.getTime())

Check failure on line 19 in test/production.spec.ts

View workflow job for this annotation

GitHub Actions / Lint Module

Expected indentation of 2 spaces but found 4
})

test.beforeEach((t) => {
/* Capture the stdout pipe */
process.stdout.write = (buffer: string) => {
t.context.logged += buffer
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()
})

Expand Down
14 changes: 8 additions & 6 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ interface Context {

const test = ava as TestFn<Context>

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) => {
t.context.logged += buffer
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()
})

Expand Down

0 comments on commit 50189ad

Please sign in to comment.