Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Runner } from '#src'

await Runner.setTsEnv()
.addAssertPlugin()
.addExpectTypeOfPlugin()
.addPath('tests/unit/**/*Test.ts')
.setCliArgs(process.argv.slice(2))
.setGlobalTimeout(10000)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/test",
"version": "5.5.0",
"version": "5.6.0",
"description": "The Athenna test runner. Built on top of Japa.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
8 changes: 8 additions & 0 deletions src/mocks/Mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
} from '#src'
import { createSandbox } from 'sinon'
import { MockBuilder } from '#src/mocks/MockBuilder'
import type { FakeTimerInstallOpts } from '#src/types/FakeTimerInstallOpts'

export class Mock {
/**
Expand All @@ -32,6 +33,13 @@ export class Mock {
return new MockBuilder(Mock.sandbox, object, method)
}

/**
* Create a fake timer to mock dates in your application.
*/
public static useFakeTimers(config?: number | Date | FakeTimerInstallOpts) {
return Mock.sandbox.useFakeTimers(config)
}

/**
* Create a spy function for a given object.
*/
Expand Down
28 changes: 28 additions & 0 deletions src/types/FakeMethod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @athenna/test
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Names of clock methods that may be faked by install.
*/
export type FakeMethod =
| 'setTimeout'
| 'clearTimeout'
| 'setImmediate'
| 'clearImmediate'
| 'setInterval'
| 'clearInterval'
| 'Date'
| 'nextTick'
| 'hrtime'
| 'requestAnimationFrame'
| 'cancelAnimationFrame'
| 'requestIdleCallback'
| 'cancelIdleCallback'
| 'performance'
| 'queueMicrotask'
46 changes: 46 additions & 0 deletions src/types/FakeTimerInstallOpts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @athenna/test
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import type { FakeMethod } from '#src/types'

export interface FakeTimerInstallOpts {
/**
* Installs fake timers with the specified unix epoch (default: 0)
*/
now?: number | Date | undefined

/**
* An array with names of global methods and APIs to fake. By default, `@sinonjs/fake-timers` does not replace `nextTick()` and `queueMicrotask()`.
* For instance, `FakeTimers.install({ toFake: ['setTimeout', 'nextTick'] })` will fake only `setTimeout()` and `nextTick()`
*/
toFake?: FakeMethod[] | undefined

/**
* The maximum number of timers that will be run when calling runAll() (default: 1000)
*/
loopLimit?: number | undefined

/**
* Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
* 20ms for every 20ms change in the real system time) (default: false)
*/
shouldAdvanceTime?: boolean | undefined

/**
* Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
* in the real system time (default: 20)
*/
advanceTimeDelta?: number | undefined

/**
* Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers. These are not cleared by
* default, leading to potentially unexpected behavior if timers existed prior to installing FakeTimers. (default: false)
*/
shouldClearNativeTimers?: boolean | undefined
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/**
* @athenna/test
*
Expand All @@ -12,6 +12,7 @@
export * from '#src/types/Spy'
export * from '#src/types/Match'
export * from '#src/types/SpyMethod'
export * from '#src/types/FakeMethod'
export * from '#src/types/SpyInstance'
export * from '#src/types/Stub'
export * from '#src/types/StubMethod'
Expand Down
Loading