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

feat!: replace mlh-tsd with tsd-lite #41

Merged
merged 19 commits into from
Feb 4, 2022
Merged

feat!: replace mlh-tsd with tsd-lite #41

merged 19 commits into from
Feb 4, 2022

Conversation

mrazauskas
Copy link
Contributor

@mrazauskas mrazauskas commented Jan 4, 2022

Should unblock jestjs/jest#11142 and jestjs/jest#12198. Also this change would allow to uncomment few assertions of jestjs/jest#11949. This is a lot! That is why I though it is time for tsd-lite.

The type testing logic is the same between tsd, mlh-tsd and tsd-lite.

The aim of tsd-lite was to remove logic unrelated with type testing. For instance, tsd and mlh-tsd are making few more checks like: if .d.ts file exist, if it is included in package.json files property, etc. These checks and rules are removed in tsd-lite.

Additionally tsd-lite is returning fileText for each failed assertion. TS compiler includes file contents with each diagnostic, so runner does not have to read files again.

Another feature I like – tsd-lite is using nearest tsconfig.json to read compiler options for each test file. This is close to how tsc works. User can have configuration for the whole project, or a group of test file, or just one test file. With "extends" option that’s incredibly flexible. For comparison, vanilla tsd is only using tsconfig.json from the root of the project, it also allows to add TS compiler options to package.json and has some defaults which cannot be overridden. Hm.. Might be good for a library written in JS, but sounds complicated and unnecessary for a TS project.

All differences are documented in tsd-lite repo – https://github.com/mrazauskas/tsd-lite

Test plan

I added test to cover both JS and TS projects.

Todo

Last but not least, I have to send another PR to update Readme file.

package.json Show resolved Hide resolved
@SimenB
Copy link
Member

SimenB commented Jan 4, 2022

all of these features seems like things upstream tsd should support (turning off/skipping validation) or even straight up features (looking at closest tsconfig, which is the correct thing to do).

That said, happy to land them here now! Would you consider this a breaking change? I guess so due to the peer dep requirement (which is a good idea 👍 )

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

this is great, thanks!

Could you update the readme as well? At least mention the peer dependency

@mrazauskas
Copy link
Contributor Author

all of these features seems like things upstream tsd should support (turning off/skipping validation) or even straight up features (looking at closest tsconfig, which is the correct thing to do).

Indeed, can’t agree more.

The changes breaking. For instance, "stick": true must be set explicitly with tsd-lite. The vanilla tsd is the opposite – "stick": false must be set explicitly to disable strict checks. In a way, tsd-lite is switching defaults. That must be major release.

I will add a note on strictness to readme. Working on it.

@mrazauskas
Copy link
Contributor Author

Just fixed documentation. That’s obviously breaking change.

Also @type pragma is deprecated. It did not make sense to mention it in the readme, but perhaps it is worth to add a line to release notes.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@mrazauskas
Copy link
Contributor Author

Some more improvement. The vanilla tsd does not report if an error in tsconfig.json is encountered. Also any syntax errors found in the test files are returned together with test results. Hm.. I think in both of these case it is better to fail early. Otherwise the test result may be unpredictable.

tsd-lite now returns tsdErrors (alongside with tsdResults). So that the runner could throw Test suite failed to run if some syntax errors or issues with tsconfig.json are encountered.

Could not finish updating documentation without this improvement. Will move on with docs now.

@SimenB
Copy link
Member

SimenB commented Feb 4, 2022

@mrazauskas sorry, lost track of this. Do you think it's ready? 😀

@mrazauskas
Copy link
Contributor Author

In general it is ready. I have one more small change in tsd-lite. Will publish new version today and will bump it here.

At the same time, I was in doubt. The readme still sounds like this is a workaround. So I was fine to leave it to cool down a bit. And to ask again: does it look good? Hm.. Perhaps this is alright as a temporary solution?

Still working on what is mentioned in #32. Had to rewrite my parser completely, now only, skip and todo work as expected with describe and test. Also -t flag and watch mode (with run only failed). And much more.

I was trying to migrate some parts of Jest’s type tests to my new testing tool. Looked very promising. There are cases which do not work yet. Polishing it. Should be finished in few months. So this PR is somewhat temporary solution. At least that’s how I see it. Could be merged, but it can wait too.

Might be good idea to unblock the issues which I was mentioning in the first comment. How do you feel about it? (;

@SimenB
Copy link
Member

SimenB commented Feb 4, 2022

I'm hoping to have a burst of energy soonish to land a new major of Jest, at which point I wanna land an update of TS. So I think landing this now, while waiting for #32 makes sense - it's still an improvement over what we have today 🙂

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

LGTM, just some nits for the readme 🙂

README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@mrazauskas
Copy link
Contributor Author

@SimenB All should be fixed. Take a look, please.

Glad to hear you are think about a new major of Jest. Node 10 support also becomes more and more blocking. Time to move on?

@SimenB
Copy link
Member

SimenB commented Feb 4, 2022

Yep, dropping node 10 and 15 🙂

README.md Outdated Show resolved Hide resolved
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

thanks!

@SimenB SimenB merged commit 652d2a6 into jest-community:main Feb 4, 2022
@mrazauskas mrazauskas deleted the feat-use-tsd-lite branch February 4, 2022 09:37
@SimenB
Copy link
Member

SimenB commented Feb 4, 2022

@SimenB
Copy link
Member

SimenB commented Feb 4, 2022

Can do a quick v3 dropping node 10?

@mrazauskas
Copy link
Contributor Author

Sure. Yes, I can do. Also Renovate will be happier.

@SimenB
Copy link
Member

SimenB commented Feb 4, 2022

Would you mind sending a PR to jest updating to v2? then we'll do v3 when I land jestjs/jest#12220

@mrazauskas
Copy link
Contributor Author

Would you mind sending a PR to jest updating to v2? then we'll do v3 when I land facebook/jest#12220

Ok. Will do this.

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.

2 participants