fastify-cli icon indicating copy to clipboard operation
fastify-cli copied to clipboard

test helper in TS template

Open Eomm opened this issue 3 years ago • 2 comments

Add the require('fastify-cli/helper') utility to the TS template. Now it exports the old interface.

The test was failing during the implementation:

templates/app-ts/test/routes/example.test.ts 2> TSError: ⨯ Unable to compile TypeScript:
templates/app-ts/test/routes/example.test.ts 2> templates/app-ts/test/helper.ts(3,23): error TS7016: Could not find a declaration file
for module 'fastify-cli/helper'. '/Users/mspigolon/workspace/fastify-cli/node_modules/fastify-cli/helper.js' implicitly has an 'any'
type.

Originally posted by @Eomm in https://github.com/fastify/fastify-cli/issues/446#issuecomment-1012562061

Eomm avatar Jan 20 '22 06:01 Eomm

If I generate the default Typescript template with npx fastify-cli generate app --lang=ts, the default tests are structured like this: ─ test ├── plugins │ └── support.test.ts ├── routes │ ├── example.test.ts │ └── root.test.ts └── helper.ts └── tsconfig.json

Inside the tests, the helper is imported as import { build } from '../helper'. Using require, this becomes const { build } = require('../helper'). Running npm run test confirms that the tests are working. Hope this helps.

braekevelt avatar Feb 04 '22 15:02 braekevelt

Add the require('fastify-cli/helper') utility to the TS template. Now it exports the old interface.

The test was failing during the implementation:

templates/app-ts/test/routes/example.test.ts 2> TSError: ⨯ Unable to compile TypeScript:
templates/app-ts/test/routes/example.test.ts 2> templates/app-ts/test/helper.ts(3,23): error TS7016: Could not find a declaration file
for module 'fastify-cli/helper'. '/Users/mspigolon/workspace/fastify-cli/node_modules/fastify-cli/helper.js' implicitly has an 'any'
type.

Originally posted by @Eomm in #446 (comment)

I was trying to reproduce the failing test, but it seems that any change made to templates/app-ts/test/routes/example.test.ts does not trigger any error.

avanelli avatar Aug 12 '22 18:08 avanelli

To replicate the issue you need to restore this commit: https://github.com/fastify/fastify-cli/pull/446/commits/56dcb64020e5a39820c9d8f826859949de880edc

The scope of this issue is to use fastify-cli/helper instead of other stuff.

If it is working now, it would be nice if you could submit a PR to update the ts template

Eomm avatar Sep 04 '22 09:09 Eomm

I've experimented a bit with this issue, and I've managed to use fastify-cli/helper interface in the TypeScript template, although I couldn't use import, probably because of missing types and other TypeScript related configurations. So, I've attempted doing minimal changes to get the helper working.

All the tests are passing, if you wish to see the changes and experiment with them, you can find them at this commit, https://github.com/nooreldeensalah/fastify-cli/commit/f43553768419f3d0da8b158960750ca8062fa722

If the changes are satisfactory enough, I'll open a PR

nooreldeensalah avatar Sep 05 '22 23:09 nooreldeensalah