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

chore: migrate type tests to TSTyche #135

Closed

Conversation

mrazauskas
Copy link
Contributor

This PR migrates type tests to TSTyche. It is a new type testing tool which is replacing tsd-lite and jest-runner-tsd.

Just to draw your attention, tsd-lite is deprecated. I was maintaining it and I was helping with the runner as well. Unfortunately the inner architecture of tsd is very limiting. To improve it I had to write a type test runner from scratch. Please meet TSTyche:

  • lightweight (no dependencies, it loads and uses TypeScript you already have installed),
  • performant (just give it a spin),
  • ships with familiar expect style assertions (and has matchers like .toHaveProperty()),
  • can test on specified versions of TypeScript: tstyche --target 4.8,latest.

Currently TSTyche is used by Immutable.js, Jest, Redwood and few more smaller projects (including my own packages).

Repo: https://github.com/tstyche/tstyche
Documentation: https://tstyche.org

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Content of jest.unit.config.js got copied here.


expect(data.propNull).type.toBeAny()

expect(data).type.not.toHaveProperty('nonExists')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.toHaveProperty() can be used. No more // @ts-expect-error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice how many dependencies are removed. The install size of TSTyche is under 200 kB.

@mrazauskas
Copy link
Contributor Author

mrazauskas commented Mar 3, 2024

By the way, TSTyche also has helpers like test() and describe() with .only and .skip run mode modifiers. Those can be added later to structure the test files. I was avoiding unnecessary noise in the diff.

{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is here to avoid global typings leaked from @types/jest and @types/node. The type tests are not executed, hence it could be very hard to catch mistakes coming from global typings. In this context, it is better to have less accidental typings around.

@mrazauskas
Copy link
Contributor Author

@LastLeaf Friendly ping. All is fine, if this does not look interesting or so. I just wanted to help.

@mrazauskas mrazauskas closed this May 27, 2024
@mrazauskas mrazauskas deleted the migrate-to-tstyche branch May 27, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant