Skip to content
Draft
Changes from 1 commit
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
58 changes: 58 additions & 0 deletions packages/core/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
interface TestTask {
description: string;
fn: () => Promise<void> | void;
result?: TestResult;
}

interface TestResult {
test: Test;
status: Extract<TaskStatus, "pass" | "fail" | "skipped">;
Comment thread
ElijahKotyluk marked this conversation as resolved.
Outdated
error?: Error;
duration?: number;
}

enum TaskStatus {
Pending = "pending",
Running = "running",
Pass = "pass",
Fail = "fail",
Skipped = "skipped",
}

class Test implements Test {
Comment thread
ElijahKotyluk marked this conversation as resolved.
Outdated
description: string;
fn: () => Promise<void> | void;
state: TaskStatus = TaskStatus.Pending;

// parent?: Suite; // @TODO - this should be a reference to the parent once they are created
result?: TestResult;

constructor(description: string, fn: () => Promise<void> | void) {
this.description = description;
this.fn = fn;
}

async run() {
const start = performance.now();

try {
this.state = TaskStatus.Running;
await this.fn();

this.result = {
test: this,
status: TaskStatus.Pass,
Comment thread
ElijahKotyluk marked this conversation as resolved.
Outdated
duration: performance.now() - start,
};
} catch (error) {
this.result = {
test: this,
status: TaskStatus.Fail,
Comment thread
ElijahKotyluk marked this conversation as resolved.
Outdated
error: error instanceof Error ? error : new Error(String(error)),
duration: performance.now() - start,
};
}
}
}

export { Test, type TestResult, type TestTask };