Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

chore: allow testMany args to accept glob patterns #702

Closed
wants to merge 19 commits into from

Conversation

netlify-team-account-1
Copy link
Contributor

@netlify-team-account-1 netlify-team-account-1 commented Oct 5, 2021

- Summary

(builds on #701)

This PR allows testMany variations to be passed in using patterns, and also adds a fancy recursive typescript type to give nice autocomplete to it.

- Test plan

  • clone locally, try out autocomplete
  • check if coverage stays the same

- A picture of a cute animal (not mandatory but encouraged)

@github-actions github-actions bot added the type: chore work needed to keep the product and development running smoothly label Oct 5, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 5, 2021

⏱ Benchmark results

largeDepsEsbuild: 13.5s

^  13.5s  
│   ┌──┐  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
└───┴──┴──>
     T    
Legend
  • T (current commit): 13.5s

largeDepsZisi: 1m 14.6s

^ 1m 14.6s
│   ┌──┐  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
│   |▒▒|  
└───┴──┴──>
     T    
Legend
  • T (current commit): 1m 14.6s

@netlify-team-account-1
Copy link
Contributor Author

another demo:

Screen.Recording.2021-10-05.at.12.22.39.mov

? '*' | `${Head}*` | `${Head}_${Globify<Tail>}`
: S | '*'

type Test = Globify<'foo_bar' | 'foo_bar_baz' | 'yeet'>
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not neccessarily - (I used them for verifying that the type works as expected) - but they don't really hurt either, as they'll never be shipped and are used only be the editor

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but why keep them if they're not doing anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. I've transformed them into type-level tests: https://github.com/netlify/zip-it-and-ship-it/pull/702/files/7f867da77363718059c2d449e91b8750f9926b86..3ef4abe7fa6e91e9f1657b4e18187ade118971f5

so now they work as documentation & tests :)
(since we haven't integrated our test suite with TypeScript yet, this won't do anything apart from being squiggly in the editor - but that's a start ^^)

Co-authored-by: Netlify Team Account 1 <90322326+netlify-team-account-1@users.noreply.github.com>
@netlify-team-account-1
Copy link
Contributor Author

this will likely need to be updated to support the todo: syntax introduced in #713

Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to review this! It looks great, I would just say two things:

  1. I always try to look for a solid reason to add another dependency, because that always carries a price. I understand that conditional-type-checks is being added to devDependencies, for which the price is considerably lower, but it's there nonetheless. Can you clarify why we need the functionality it introduces, since the types being asserted only exist in the context of the test suite?

  2. Can we make this PR about adding the glob capability only, and then we decide which tests to convert to globs on a per-test basis, in separate PRs?

@netlify-team-account-1
Copy link
Contributor Author

netlify-team-account-1 commented Oct 12, 2021

Can you clarify why we need the functionality it introduces, since the types being asserted only exist in the context of the test suite?

advanced typescript types are somewhat hard to understand. conditional-type-checks library gives some helper functions that allow expressing examples / test cases in-code. It's the type-level equivalent of a unit test, and acts both as a test and usage documentation. The hope is that it makes maintenance easier, and more accessible to devs that are new to TypeScript.

Can we make this PR about adding the glob capability only, and then we decide which tests to convert to globs on a per-test basis, in separate PRs?

Absolutely! done via 8660f19

@eduardoboucas
Copy link
Member

advanced typescript types are somewhat hard to understand. conditional-type-checks library gives some helper functions that allow expressing examples / test cases in-code. It's the type-level equivalent of a unit test

I understand that, and type assertions feel like something we should do since the types are part of the API we offer to people consuming our libraries. But in this case we're adding type assertions to something that only exists in the context of the test suite, which I find a bit harder to understand.

The hope is that it makes maintenance easier, and more accessible to devs that are new to TypeScript.

I think the glob patterns in testMany is a nice-to-have convenience. If the logic that makes it possible is so complex that we need an additional library and type checks or else it becomes difficult to read and maintain, I would argue that we should probably reconsider whether it's worth adding.

@netlify-team-account-1
Copy link
Contributor Author

I would argue that we should probably reconsider whether it's worth adding.

agreed!

@danez danez deleted the testmany-glob branch August 17, 2022 22:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: chore work needed to keep the product and development running smoothly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants