Open
Conversation
aduh95
reviewed
Dec 15, 2022
MoLow
reviewed
Dec 15, 2022
| } | ||
|
|
||
| type TestFn = (t: TestContext) => any | Promise<any>; | ||
| type TestFn = (t: TestContext, done: (result?: any) => void) => any; |
Member
There was a problem hiding this comment.
Suggested change
| type TestFn = (t: TestContext, done: (result?: any) => void) => any; | |
| type TestFn = <T>(t: TestContext, done: (result?: T) => void) => any | <T>(t: TestContext) => Promise<T>; |
MoLow
reviewed
Dec 15, 2022
lib/test.d.ts
Outdated
Comment on lines
50
to
53
| export function test( | ||
| name: string, | ||
| options: TestOptions, | ||
| fn: TestFn |
Member
There was a problem hiding this comment.
Suggested change
| export function test( | |
| name: string, | |
| options: TestOptions, | |
| fn: TestFn | |
| export function test<T>( | |
| name: string, | |
| options: TestOptions, | |
| fn: TestFn<T> |
MoLow
reviewed
Dec 15, 2022
lib/test.d.ts
Outdated
Comment on lines
55
to
56
| export function test(name: string, fn: TestFn): Promise<void>; | ||
| export function test(options: TestOptions, fn: TestFn): Promise<void>; |
Member
There was a problem hiding this comment.
Suggested change
| export function test(name: string, fn: TestFn): Promise<void>; | |
| export function test(options: TestOptions, fn: TestFn): Promise<void>; | |
| export function test<T>(name: string, fn: TestFn<T>): Promise<void>; | |
| export function test<T>(options: TestOptions, fn: TestFn<T>): Promise<void>; |
Using .prettierrc:
```json
{
"plugins": ["prettier-plugin-jsdoc"]
}
```
Author
|
@MoLow thanks for the review Edit: misinterpreted your suggestion 🤦 will apply your changes! Edit2: couldn't get this to work, tried: type TestFn =
| ((t: TestContext, done: (result?: any) => void) => any)
| ((t: TestContext) => Promise<any>)
test(async (t) => {})Which yields: Making TestFn generic doesn't change much. |
aduh95
reviewed
Dec 16, 2022
Author
|
In order to test these changes, I wrote a quick import { expectType } from "tsd";
import test, { describe, it } from "../lib/test.js";
// # test()
// Parameters
expectType<void>(await test());
expectType<void>(await test("name", { only: true }));
expectType<void>(await test("name", { only: true }, () => {}));
expectType<void>(await test({ only: true }));
expectType<void>(await test({ only: true }, () => {}));
expectType<void>(await test("name", () => {}));
expectType<void>(await test(() => {}));
// TestFn
expectType<Promise<void>>(test(() => {}));
expectType<void>(await test((t) => {}));
expectType<void>(await test(async (t) => {}));
expectType<void>(await test((t, done) => done()));
expectType<void>(await test(async (t, done) => done())); // Test will fail
// # describe()
// Parameters
expectType<void>(describe());
expectType<void>(describe("name", { only: true }));
expectType<void>(describe("name", { only: true }, () => {}));
expectType<void>(describe({ only: true }));
expectType<void>(describe({ only: true }, () => {}));
expectType<void>(describe("name", () => {}));
expectType<void>(describe(() => {}));
// # it()
// Parameters
expectType<void>(it());
expectType<void>(it("name", { only: true }));
expectType<void>(it("name", { only: true }, () => {}));
expectType<void>(it({ only: true }));
expectType<void>(it({ only: true }, () => {}));
expectType<void>(it("name", () => {}));
expectType<void>(it(() => {}));In {
"scripts": {
"test:types": "tsd --files test/test.test-d.ts"
}
}And run with: npm i -D tsd
npm run test:typesIf wanted, I will commit these changes (and add |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Various improvements to the TypeScript types:
TestOptions.onlydoneparam toTestFntestReturnType toPromise<void>ItContextand replace param with initfn type withdoneTestContext.testtotypeof testTestContext.runOnly,TestContext.beforeEach,TestContext.afterEach,TestContext.nameI tried re-using the types from @types/node but these also seem incomplete/incorrect at places (e.g.
SuiteFn) so instead based these changes on the README of this package.Suggestions for further improvements:
describe.skipdescribe.todoit.skipit.skip@types/nodeand sync?If these are welcome, happy to contribute another PR addressing those.