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

feat: add Hono test client (RPC) #1451

Merged
merged 2 commits into from
Sep 17, 2023
Merged

Conversation

hagishi
Copy link
Contributor

@hagishi hagishi commented Sep 13, 2023

Author should do the followings, if applicable

  • Add tests
  • Run tests
  • yarn denoify to generate files for Deno

What this PR do?

By using the hc test client, we can easily write tests. This utility enables efficient integration and unit testing by allowing manipulation of the Hono application object rather than making actual HTTP requests.

Usage Example

it('test', async() => {
  const app = new Hono().get('/search', (c) => c.jsonT({ hello: 'world' }))
  const res = await hc(app).search.$get()

  expect(await res.json()).toEqual({ hello: 'world' })
})

@hagishi hagishi changed the title feat: add test client helper feat: add Hono test client Sep 13, 2023
@hagishi hagishi changed the title feat: add Hono test client feat: add Hono test client (RPC) Sep 13, 2023
@yusukebe
Copy link
Member

Hi @hagishi!

Cool! This is one of the things we want to do with RPC-mode. Introducing the testing helper makes sense.

But, there's one thing we should consider. The function name hc might be confusing because hono/client has a function with the same name. I haven't come up with a perfect name yet, but something like appToClient() might be better. Any thoughts?

@hagishi
Copy link
Contributor Author

hagishi commented Sep 14, 2023

Hi @yusukebe,

Thank you for the review.

I agree that some parts could indeed be confusing.
Following the example of frameworks like FastAPI,
I think a clearer naming convention like testClient(app) would be better.
What do you think?"

@yusukebe
Copy link
Member

Hi @hagishi !

testClient is simple and good! Let's go with it.

@yusukebe yusukebe changed the base branch from main to next September 16, 2023 16:08
@yusukebe
Copy link
Member

Hi @hagishi

Thanks! Merging it now.

@yusukebe yusukebe merged commit 2e5e1b2 into honojs:next Sep 17, 2023
10 checks passed
@hagishi hagishi deleted the feature/testclient branch September 18, 2023 00:51
yusukebe pushed a commit that referenced this pull request Sep 20, 2023
* feat: add test client helper

* refactor:  rename from hc to testClient
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