Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: task base type #41

Merged
merged 1 commit into from
Dec 9, 2021
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 src/runtime/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function collectTests(paths: string[]) {
computeMode: 'serial',
filepath,
tasks: [],
suite: {} as Suite,
}

setHooks(file, createSuiteHooks())
Expand Down
9 changes: 4 additions & 5 deletions src/runtime/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function createSuiteCollector(name: string, factory: TestFactory = () => { }, mo
name,
mode,
tasks: [],
suite: {} as Suite,
}
setHooks(suite, createSuiteHooks())
}
Expand Down Expand Up @@ -89,11 +90,9 @@ function createSuiteCollector(name: string, factory: TestFactory = () => { }, mo
suite.tasks = allChildren

allChildren.forEach((task) => {
if (task.type === 'test') {
task.suite = suite
if (file)
task.file = file
}
task.suite = suite
if (file)
task.file = file
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is useful to have the parent also for nested suites

})

return suite
Expand Down
25 changes: 13 additions & 12 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,30 @@ export type TestState = RunMode | 'pass' | 'fail'
export type SuiteState = RunMode | 'pass' | 'fail'
export type ComputeMode = 'serial' | 'concurrent'

export interface Test {
type: 'test'
export type TaskType = 'test' | 'suite'

export interface Task {
type: TaskType
name: string
mode: RunMode
computeMode: ComputeMode
suite: Suite
file?: File
result?: TestResult
result?: TaskResult
}

export interface Test extends Task {
type: 'test'
result?: TaskResult
}

export interface TestResult {
export interface TaskResult {
state: TestState
start: number
end?: number
error?: unknown
}

export type Task = Test | Suite

export type TestFunction = () => Awaitable<void>

interface ConcurrentCollector {
Expand Down Expand Up @@ -139,14 +144,10 @@ export interface SuiteHooks {
afterEach: HookListener<[Test, Suite]>[]
}

export interface Suite {
export interface Suite extends Task {
type: 'suite'
name: string
mode: RunMode
computeMode: ComputeMode
tasks: Task[]
file?: File
result?: TestResult
result?: TaskResult
}

export interface SuiteCollector {
Expand Down