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: setup TypeScript settings #824

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

test: setup TypeScript settings #824

wants to merge 5 commits into from

Conversation

koba04
Copy link
Member

@koba04 koba04 commented May 10, 2022

This migrates test files to TypeScript. This is not necessary, but it's useful to test the TypeScript definition.

@koba04 koba04 marked this pull request as ready for review May 11, 2022 14:51
@koba04 koba04 requested a review from eps1lon May 11, 2022 14:54
@@ -1,12 +1,7 @@
let React;
let ChildMapping;
import React from 'react';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really a fan of TypeScript in runtime tests precisely because runtime tests are annoying to type. The previous test did work differently by clearing modules for each test. A static import is not the same.

If you want to test the types, we should have separate test files for them.

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous test did work differently by clearing modules for each test. A static import is not the same.

Yeah, but this seems not to be necessary because the tests don't mock anything or mutate modules. I prefer not to mock or mutate modules as possible. So it would be nice to use static imports as default.

If you want to test the types, we should have separate test files for them.

That is a valid opinion, but I'd like to write tests in TypeScript. If typing test code is annoying, we can use any or type casting in that places.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer not to mock or mutate modules as possible. So it would be nice to use static imports as default.

We're doing neither here. We're resetting the module which is not yet supported with Jest and ESM. So until then, we need to re-require.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you, I have two questions.

  • Why do we need to reset the module even though we haven't used mock or mutating modules?
  • Can't we reset modules with Jest even if we transpile ESM to CJS by tsc?

@@ -32,102 +27,102 @@ describe('ChildMapping', () => {

it('should support mergeChildMappings for adding keys', () => {
let prev = {
one: true,
two: true,
one: 'one',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like runtime behavior changed. But the PR title says it's only about test. Could you clarify why this change here is necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

The type is ReactChild, which doesn't accept boolean, so I've changed the test data to String.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure but that's not a reason to change runtime behavior, no? So far this looks like a breaking change just so that our tests are type-checked?

Copy link
Member Author

Choose a reason for hiding this comment

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

What does "runtime behavior" mean? This doesn't change any runtime behavior. The TypeScript migration causes this change. Do you mean that we shouldn't do any incompatible changes with DefinitelyTyped?

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

2 participants