Skip to content
Closed
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
51 changes: 40 additions & 11 deletions packages/bun-types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ declare module "bun:test" {
each<T>(
table: T[],
): (label: string, fn: (...args: T[]) => void | Promise<unknown>, options?: number | TestOptions) => void;
each(
strings: TemplateStringsArray,
...values: any[]
): (
label: string,
fn: (obj: { [k: string]: any }) => void | Promise<unknown>,
options?: number | TestOptions,
) => void;
}
/**
* Runs a test.
Expand Down Expand Up @@ -582,6 +590,11 @@ declare module "bun:test" {
* Ensures that a specific number of assertions are made
*/
assertions(neededAssertions: number): void;

/**
* Get information about the current test
*/
getState(): Readonly<TestState>;
}

/**
Expand Down Expand Up @@ -921,7 +934,7 @@ declare module "bun:test" {
*
* @param expected the expected value
*/
toBeOneOf(expected: Array<unknown> | Iterable<unknown>): void;
toBeOneOf(expected: unknown[] | Iterable<unknown>): void;
/**
* Asserts that a value contains what is expected.
*
Expand Down Expand Up @@ -1560,21 +1573,36 @@ declare module "bun:test" {
equals: EqualsFunction;
}

interface MatcherState {
//assertionCalls: number;
export interface TestState {
/** The name of the current test */
currentTestName: string;
//currentConcurrentTestName?: () => string | undefined;
//currentTestName?: string;
/** The path of the current test file */
testPath: string;
/** Number of `expect()` calls that passed so far */
//numPassingAsserts: number;
/** Total number of `expect()` calls so far */
assertionCalls: number;
//error?: Error;
//expand: boolean;
//expectedAssertionsNumber: number | null;
/** Expected number of `expect()` calls, as set by calling `expect.assertions(n)` */
expectedAssertionsNumber: number | null;
//expectedAssertionsNumberError?: Error;
//isExpectingAssertions: boolean;
/** Whether the test expects at least one `expect()` calls, as set by calling `expect.hasAssertions()` */
isExpectingAssertions: boolean;
//isExpectingAssertionsError?: Error;

/** Errors for the `expect.soft()` calls that failed so far */
//suppressedErrors: Error[];
//snapshotState: unknown;
/** Whether to report more verbose messages */
expand: boolean;
}

interface MatcherState extends TestState {
/** Whether the `expect()` call had the ".not" modifier */
isNot: boolean;
//numPassingAsserts: number;
promise: string;
//suppressedErrors: Array<Error>;
//testPath?: string;
/** Whether the `expect()` call had the either ".resolves" or the ".rejects" modifier */
promise: "resolves" | "rejects" | "";
}

type MatcherHintColor = (arg: string) => string; // subset of Chalk type
Expand All @@ -1587,6 +1615,7 @@ declare module "bun:test" {
stringify(value: unknown): string;
printReceived(value: unknown): string;
printExpected(value: unknown): string;
diff(a: unknown, b: unknown): string;
matcherHint(
matcherName: string,
received?: unknown,
Expand Down
4 changes: 4 additions & 0 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5970,6 +5970,10 @@ pub const CallFrame = opaque {
pub fn argumentsCount(self: *const CallFrame) usize {
return @as(usize, @intCast((@as([*]align(alignment) const JSC.JSValue, @ptrCast(@alignCast(self))) + Sizes.Bun_CallFrame__argumentCountIncludingThis)[0].asInt32() - 1));
}

pub fn argumentsSlice(self: *const CallFrame) []const JSValue {
return self.argumentsPtr()[0..self.argumentsCount()];
}
};

// pub const WellKnownSymbols = extern struct {
Expand Down
Loading