Skip to content

chore: use TSTyche for type testing #2234

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mrazauskas
Copy link

Description

This PR migrates type tests to TSTyche. As it was mentioned here: #2153 (comment)

How TSTyche is better?

  • no dependencies, inspect changes in the lock file
  • by default it loads typescript package you already have installed
  • has test() and describe() with .only and .skip
  • ships with mighty CLI, run a single test file (tstyche file-name), test against specific TypeScript version (tstyche --target 5.8), range of versions (tstyche --target >=5.4) and more

Try it out (;

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

Copy link

vercel bot commented Apr 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
js-lingui ✅ Ready (Inspect) Visit Preview Apr 28, 2025 2:41pm

Copy link

github-actions bot commented Apr 17, 2025

size-limit report 📦

Path Size
packages/core/dist/index.mjs 2.91 KB (0%)
packages/detect-locale/dist/index.mjs 618 B (0%)
packages/react/dist/index.mjs 1.35 KB (0%)

@@ -72,6 +70,7 @@
"strip-ansi": "^6.0.1",
"swc-node": "^1.0.0",
"ts-jest": "^29.2.4",
"tstyche": "^4.0.0-beta.6",
Copy link
Author

Choose a reason for hiding this comment

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

Only the latest version has .toBeCallableWith() matcher. It is still in beta. Stable version will be available in month. CLI usage will not break any more.

@@ -33,19 +33,19 @@ expectAssignable<LinguiConfig>({
tsExperimentalDecorators: false,
},
fallbackLocales: {} as FallbackLocales,
format: "po",
format: "po" as const,
Copy link
Author

@mrazauskas mrazauskas Apr 17, 2025

Choose a reason for hiding this comment

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

The behaviour is the same as discussed here: https://github.com/lingui/js-lingui/pull/1622/files#r1178201302

More details in documentation: https://tstyche.org/reference/expect-api#type-widening

@@ -1,6 +1,7 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "Node16",
Copy link
Author

Choose a reason for hiding this comment

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

This was required by TypeScript.

Comment on lines -12 to -14
"scripts": {
"test:tsd": "tsd"
},
Copy link
Author

Choose a reason for hiding this comment

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

There are no type tests in this package.

@@ -72,7 +72,7 @@ jobs:
run: yarn test:ci:coverage

- name: Test Public Typings
run: yarn test:tsd
run: yarn test:types
Copy link
Author

@mrazauskas mrazauskas Apr 17, 2025

Choose a reason for hiding this comment

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

As an example, you can state that TypeScript 5.4 and above is supported and run tests like this:

Suggested change
run: yarn test:types
run: yarn test:types --target '>=5.4'

The tests will run agains each minor release, currently: 5.4, 5.5, 5.6, 5.7, 5.8. New TypeScript versions are added automatically as soon as they are published to npm.

////////////////////////
//// React useLingui()
////////////////////////
function MyComponent() {
test("useLingui", () => {
Copy link
Author

@mrazauskas mrazauskas Apr 28, 2025

Choose a reason for hiding this comment

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

Since diff looks even better, here I used the test() helper instead of that comment (just for fun).

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.

1 participant