Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Oct 25, 2023
1 parent d6be35d commit de1e83d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/common/framework/params_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class CaseParamsBuilder<CaseP extends {}>
}
}

yield [caseP as DeepReadonly<CaseP>, undefined];
yield [caseP as DeepReadonly<typeof caseP>, undefined];
}
}

Expand Down Expand Up @@ -303,7 +303,10 @@ export class SubcaseParamsBuilder<CaseP extends {}, SubcaseP extends {}>

const subcases = Array.from(this.subcases(caseP));
if (subcases.length) {
yield [caseP as DeepReadonly<CaseP>, subcases as DeepReadonly<SubcaseP>[]];
yield [
caseP as DeepReadonly<typeof caseP>,
subcases as DeepReadonly<typeof subcases[number]>[],
];
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/common/internal/test_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ export function makeTestGroupForUnitTesting<F extends Fixture>(
/** Parameter name for batch number (see also TestBuilder.batch). */
const kBatchParamName = 'batch__';

type TestFn<F extends Fixture, P extends {}> = (t: F & { params: P }) => Promise<void> | void;
type TestFn<F extends Fixture, P extends {}> = (
t: F & { params: DeepReadonly<P> }
) => Promise<void> | void;
type BeforeAllSubcasesFn<S extends SubcaseBatchState, P extends {}> = (
s: S & { params: P }
s: S & { params: DeepReadonly<P> }
) => Promise<void> | void;

export class TestGroup<F extends Fixture> implements TestGroupBuilder<F> {
Expand Down Expand Up @@ -217,7 +219,7 @@ interface TestBuilderWithParams<F extends Fixture, CaseP extends {}, SubcaseP ex
* Set the test function.
* @param fn the test function.
*/
fn(fn: TestFn<F, DeepReadonly<Merged<CaseP, SubcaseP>>>): void;
fn(fn: TestFn<F, Merged<CaseP, SubcaseP>>): void;
/**
* Mark the test as unimplemented.
*/
Expand Down
6 changes: 5 additions & 1 deletion src/common/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export type TypeEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
export function assertTypeTrue<T extends true>() {}

export type Primitive = string | number | boolean | undefined | null | Function | symbol;
/**
* Deep version of the Readonly<> type, with support for tuples (up to length 7).
* <https://gist.github.com/masterkidan/7322752f569b1bba53e0426266768623>
*/
export type DeepReadonly<T> = T extends [infer A]
? DeepReadonlyObject<[A]>
: T extends [infer A, infer B]
Expand All @@ -40,6 +43,7 @@ export type DeepReadonly<T> = T extends [infer A]
? DeepReadonlyArray<A>
: DeepReadonlyObject<T>;

type Primitive = string | number | boolean | undefined | null | Function | symbol;
type DeepReadonlyArray<T> = ReadonlyArray<DeepReadonly<T>>;
type DeepReadonlyObject<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> };

Expand Down

0 comments on commit de1e83d

Please sign in to comment.