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

Missing types for test helpers in 'fastify-cli/helper', cannot use it with import statement #601

Open
2 tasks done
shwarcu opened this issue Mar 17, 2023 · 3 comments
Open
2 tasks done

Comments

@shwarcu
Copy link

shwarcu commented Mar 17, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.7.1

Plugin version

No response

Node.js version

v18.15.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

13.2.1 (22D68)

Description

I am setting up tests for Fastify application. Our codebase and tests are in TypeScript.
I try to follow documentation here
https://github.com/fastify/fastify-cli#test-helpers but there's no declaration file for fastify-cli
I get error
Could not find a declaration file for module 'fastify-cli/helper'.
or
Could not find a declaration file for module 'fastify-cli'. if I try to import anything from the package.

Steps to Reproduce

  1. Setup TypeScript project
  2. Setup some tests in TypeScript for example https://node-tap.org/docs/getting-started
  3. Try to apply guide from https://github.com/fastify/fastify-cli#test-helpers in typescript setup
import { build } from 'fastify-cli/helper';
import tap from 'tap';

tap.test('Responds', (test) => {
  test.end();
});

Expected Behavior

I would like to be able to use test helpers in TypeScript tests by importing it with import statement and have correct typings for it.

I've seen your workaround from here https://github.com/fastify/fastify-cli/pull/554/files
but using require doesn't solve the root problem.

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@g0di
Copy link

g0di commented Apr 27, 2023

Just ended up here as I was looking for the exact same issue. I would like to make a PR but Im unsure on how to properly add the typings definitions into the project as I'm used to write Typescript directly or typings for external libraries.

Should I:

  • Add a helper.d.ts file next to helper.js file?
  • Add typings into a dedicated types folder?
  • Add types directly into the helper.js file using JSDoc and TSC to emit declaration file automatically?
  • Add typings in DefinitivelyTyped repository?

Let me know your preference and I'll take care of this

@segevfiner
Copy link
Contributor

It seems like there are types now, but they are incomplete, saying that build returns any instead of a FastifyInstance.

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 a pull request may close this issue.

4 participants