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(react-query): add tsd #99

Merged
merged 12 commits into from
Nov 9, 2022
Merged

test(react-query): add tsd #99

merged 12 commits into from
Nov 9, 2022

Conversation

manudeli
Copy link
Member

@manudeli manudeli commented Oct 28, 2022

ISSUE CLOSED: #86

This is continuous PR along #73 to add tsd for testing typescript type
#73 (comment)

TSD set up with some code

import { expectType } from 'tsd';
import { SuspendedUseQueryResultOnIdle, SuspendedUseQueryResultOnSuccess, useSuspendedQuery } from '../dist';

const queryKey = ['example'] as const;
const queryFn = async () => 'response';

/* eslint-disable react-hooks/rules-of-hooks */
expectType<SuspendedUseQueryResultOnSuccess<'response'>>(useSuspendedQuery(queryKey, queryFn));
expectType<SuspendedUseQueryResultOnSuccess<'response'>>(useSuspendedQuery(queryKey, queryFn, { enabled: true }));
expectType<SuspendedUseQueryResultOnIdle<undefined>>(useSuspendedQuery(queryKey, queryFn, { enabled: false }));
expectType<SuspendedUseQueryResultOnSuccess<'response'> | SuspendedUseQueryResultOnIdle<undefined>>(
  useSuspendedQuery(queryKey, queryFn, { enabled: Boolean(Math.random() > 0.5) })
);

Could you together check that tsd really require @yarnpkg/pnpify in yarn/berry please?

I think TSD need @yarnpkg/pnpify in yarn/berry environment. but I can't be confident on it

when i first setup tsd in my personal project using yarn classic, tsd worked really fine.
but if no @yarnpkg/pnpify in yarn/berry environment like @toss/slash, when I exucute yarn tsd, I met cannot find module tsd, react-query error.

after paying to find proper solution, I met this solution on issue in SamVerschueren/tsd using @yarnpkg/pnpify

PR Checklist

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

@netlify
Copy link

netlify bot commented Oct 28, 2022

👷 Deploy request for slash-libraries pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 7089f51

@@ -11,7 +15,7 @@
},
"main": "./src/index.ts",
"scripts": {
"build": "rm -rf dist esm && tsc --declaration --emitDeclarationOnly --declarationDir dist && rollup -c rollup.config.js",
"build": "rm -rf dist esm && tsc --declaration --emitDeclarationOnly --declarationDir dist && rollup -c rollup.config.js && pnpify tsd",
Copy link
Member Author

@manudeli manudeli Nov 2, 2022

Choose a reason for hiding this comment

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

I chained pnpify tsd after original build
It will make error in process of build if there is error in tsd code.

check that it is fine please

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not running tests in the test script, rather than build? We always check if the test passes before a PR is merged.

Copy link
Member Author

Choose a reason for hiding this comment

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

@raon0211
I want to split it(pnpify tsd) from yarn build too.
but cannot find any code that execute just only test before a PR is merged.
Where can i check that code?

I found only circleci using jest in .circleci/config.yml, not yarn test.
Isn't test just used as just naming, right?

Is there any setting executing yarn test not visible for me?
or Could you help me check it out please?

Copy link
Contributor

@hoseungme hoseungme Nov 7, 2022

Choose a reason for hiding this comment

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

Yes, It looks so @manudeli .

But, despite it, I think running tsd in build script is not appropriate.
We can do other better things like adding tsd test step to Circle CI config, or etc.

We will tell you about it soon, thanks!

Copy link
Member Author

@manudeli manudeli Nov 7, 2022

Choose a reason for hiding this comment

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

@hoseungjang Okay.
I removed tsd in script:build and added a script:tsd seperately in this commit fb022af.
this script:tsd is intended to be easy to use whether anyone know pnpify is required to use tsd on yarn berry project or not.

  "scripts": {
    "build": "rm -rf dist esm && tsc --declaration --emitDeclarationOnly --declarationDir dist && rollup -c rollup.config.js",
    "prepack": "yarn build",
    "test": "echo \"no test specified.\"",
    "tsd": "pnpify tsd", // added: to use tsd on yarn berry
    "typecheck": "tsc --noEmit"
  },

If anyone have used script build, it will make definition files so you can use tsd after.
How about next new Pull Request for doing better thing that you said after merging this Pull Request?

Copy link
Collaborator

@raon0211 raon0211 Nov 8, 2022

Choose a reason for hiding this comment

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

We are discussing this. Please wait a bit 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

Seperating tsd script and adding that in prepack lifecycle seems good to me.
But like you said, it would be better to do it in the new PR.
This seems fine to merge.

  "scripts": {
    "prepack": "yarn build && yarn tsd",
    "tsd": "pnpify tsd"
  },

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed scripts as what you comment in a42814c

thanks for your guide :)

const queryKey = ['example'] as const;
const queryFn = async () => 'response';

/* eslint-disable react-hooks/rules-of-hooks */
Copy link
Member Author

@manudeli manudeli Nov 2, 2022

Choose a reason for hiding this comment

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

if no eslint-disable comment, eslint emit error like below. so I added it
image

@manudeli manudeli marked this pull request as ready for review November 2, 2022 16:32
@manudeli manudeli requested review from hoseungme and raon0211 and removed request for changyoungoh, hoseungme and raon0211 November 7, 2022 14:30
@manudeli manudeli requested review from artechventure, raon0211 and hoseungme and removed request for hoseungme, artechventure and raon0211 November 8, 2022 13:00
@hoseungme hoseungme enabled auto-merge (squash) November 9, 2022 20:32
@hoseungme hoseungme merged commit 1570de0 into toss:main Nov 9, 2022
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.

[Feature] tsd setup on @toss/react-query
4 participants