Skip to content

Commit 5c6d751

Browse files
committed
Refactor tests and prechecks for improved clarity and coverage
1 parent 0500029 commit 5c6d751

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import {timestamp} from '../../src/functions/timestamp.js'
2-
import {vi, expect, test, beforeEach} from 'vitest'
2+
import {vi, expect, test, beforeEach, afterEach} from 'vitest'
33

44
beforeEach(() => {
55
vi.clearAllMocks()
66
})
77

8+
afterEach(() => {
9+
vi.useRealTimers()
10+
})
11+
812
test('should return the current date in ISO 8601 format', () => {
913
const mockDate = new Date('2025-01-01T00:00:00.000Z')
10-
vi.spyOn(global, 'Date').mockImplementation(() => mockDate)
14+
vi.setSystemTime(mockDate)
1115

1216
const result = timestamp()
1317

14-
expect(result).toBe(mockDate.toISOString())
15-
16-
// Restore the original Date implementation
17-
global.Date.mockRestore()
18+
expect(result).toBe('2025-01-01T00:00:00.000Z')
1819
})

src/functions/prechecks.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,11 @@ export async function prechecks(context, octokit, data) {
326326
try {
327327
core.debug('raw graphql result for debugging:')
328328
core.debug(result)
329-
/* c8 ignore start */
330-
} catch {
329+
} /* istanbul ignore next */ catch {
331330
core.debug(
332331
'Could not output raw graphql result for debugging - This is bad'
333332
)
334333
}
335-
/* c8 ignore stop */
336334
}
337335

338336
// Get admin data

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,15 @@ export async function run() {
860860
}
861861
}
862862

863-
/* c8 ignore start */
863+
/* istanbul ignore next */
864864
if (core.getState('isPost') === 'true') {
865865
post()
866866
} else {
867+
/* istanbul ignore next */
867868
if (
868869
process.env.CI === 'true' &&
869870
process.env.BRANCH_DEPLOY_VITEST_TEST !== 'true'
870871
) {
871872
run()
872873
}
873874
}
874-
/* c8 ignore stop */

0 commit comments

Comments
 (0)