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

test: enable typecheck for _config files #4954

Merged
merged 17 commits into from May 1, 2023

Conversation

antfu
Copy link
Contributor

@antfu antfu commented Apr 23, 2023

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This would be helpful for contributors to write tests, and see what is available as test options.

Currently, it only enables IDE type-checking as some of the functions are not fully type-covered. We could improve the along the way, but right now, being able to typecheck the Rollup options field options is a huge improve to me already.

@vercel
Copy link

vercel bot commented Apr 23, 2023

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

Name Status Preview Comments Updated (UTC)
rollup ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2023 5:05am

@antfu antfu changed the title chore: init test: enable typecheck for _config files Apr 23, 2023
@codecov
Copy link

codecov bot commented Apr 23, 2023

Codecov Report

Merging #4954 (fceb680) into master (4fb9778) will decrease coverage by 0.03%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #4954      +/-   ##
==========================================
- Coverage   98.99%   98.96%   -0.03%     
==========================================
  Files         222      222              
  Lines        8123     8123              
  Branches     2237     2237              
==========================================
- Hits         8041     8039       -2     
- Misses         28       29       +1     
- Partials       54       55       +1     

see 1 file with indirect coverage changes

@antfu
Copy link
Contributor Author

antfu commented Apr 23, 2023

I tried to understand what each configuration stands for in the tsdocs - feel free to directly update them if you see any improvements.

Copy link
Member

@lukastaegert lukastaegert 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 actually a great idea! One thing that could be improved, though: The different test types do not support the same fields. Many are shared, of course, like description or solo. But only function tests support exports and global and some other props, while formats I think is specific to chunking-form (would need to check). It would be nice to have this difference also in the type check. One thing that happens quite often is that a test is converted between function and form. At that point, the additional check would help to highlight if the config needs to be changed.

One idea could be to have different helpers, e.g. defineFunctionTest, defineChunkingTest, defineFormTest,... (and I do not think we need Rollup in the name to keep the names shorter).

While you would get no warning if you use the wrong global, using the wrong global would immediately turn the actual test red because each test type only injects the global for this type (or injects something that throws a more helpful error for the others).

Or maybe you have a better idea?

@antfu
Copy link
Contributor Author

antfu commented Apr 23, 2023

Interesting! I think maybe I could make it work using the same function name in different directly. Let me play with it!

@antfu
Copy link
Contributor Author

antfu commented Apr 23, 2023

Managed to make it work! Now the type of defineTest will be based on the folder. I think it would also be helpful when moving tests - the type check will tell which config entries needs to be changed.

Screenshot 2023-04-23 at 23 00 23

Screenshot 2023-04-23 at 23 02 06

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

That looks amazing! Now the only thing is that we have a million of type errors...

@antfu
Copy link
Contributor Author

antfu commented Apr 24, 2023

Maybe we could disable the typecheck for now (but we will still get the autocomplete, etc.) and opt-in by // @ts-check per file. That way we could move forward and I will try to improve them from time to time

@lukastaegert
Copy link
Member

I finalized the types for the available properties per test now and would merge this now. There are still some subtle things I am not happy about, though. Mostly, there are some issues as TypeScript does not like importing types from outside the current tsconfig file. One way to solve this could be to go back to a single tsconfig for tests and have different test helpers per test type, but maybe for another PR.

@lukastaegert lukastaegert added this pull request to the merge queue May 1, 2023
Merged via the queue into rollup:master with commit 64870c3 May 1, 2023
11 of 12 checks passed
@antfu antfu deleted the feat/typed-test-config branch May 1, 2023 15:49
@antfu
Copy link
Contributor Author

antfu commented May 1, 2023

Thanks!

@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.21.3. You can test it via npm install rollup.

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

3 participants