hotscript icon indicating copy to clipboard operation
hotscript copied to clipboard

refactor: use vitest for tests

Open tmm opened this issue 2 years ago • 2 comments

  • Swaps out custom test utilities for Vitest typechecking. image
  • Adds GitHub Action workflow for test, build, typecheck
  • Deps: Adds Vitest, removes Jest, switches to pnpm (happy to switch back to npm, just lmk)

tmm avatar Feb 12 '23 23:02 tmm

@gvergnaud let me know if you want to head in this direction and I can resolve the conflicts.

If not, feel free to close this PR so it doesn’t grow too stale and I can stop watching it.

tmm avatar Feb 13 '23 15:02 tmm

I see you use assertType<X>(Y) to assert the type, any particular reason?

assertType is ok for checking value type, but not great to compare 2 types

for example you can do something like this

image

and it will not error

because as for value, all we care is whether we can assign it to something(to variable, argument, property etc)

which mean as long as the value type is sub type of the required type, then it is ok. It doesnt need to be exactly the same type

which is why assertType<number>(2 as const) does not trigger any error, because 2 is a sub type of number

But type level programming is about creating all kind of utility types, we need to make sure the output are exactly the same type as the expected type, so it is better to use type equality check here

I also saw you use expectTypeOf<X>().toEqualTypeOf<Y>(), this is correct because this is type equality check, just a bit lengthy

or is there anything I don't know about?

tylim88 avatar Feb 14 '23 03:02 tylim88