question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest -> ts-jest + Typescript does not appear to be working

See original GitHub issue

🐛 Bug Report

In Fastify-Autoload 1.x jest tests + typescript worked with fastify-autoload with seemingly no issue as long as the includeTypescript: true configuration was passed. With the new version it appears that has been removed in favor of automatically supporting ts-node. I don’t 100% know everything about ts-jest but I do not believe it uses ts-node and yet it worked before. It seems like this should still work.

To Reproduce

Steps to reproduce the behavior:

clone this repo - https://github.com/wolfejw86/fastify-typescript-starter

run npm install run npm run test

see that fasitify-autoload is working correctly in https://github.com/wolfejw86/fastify-typescript-starter/blob/master/src/app.ts

In the same repo - upgrade fastify-swagger, fastify, fastify-plugin, and fastify-autoload all to the latest version by switching to the branch in progress(the 3.0 migration for fastify + typescript). git checkout fastify-upgrade npm install npm run test

Notice fastify-autoload will no longer load any plugins.

fastify-autoload cannot import plugin at '/Users/johnwolfe/Desktop/repositories/fastify-typescript-starter/src/plugins/globalErrorHandler.ts'. To fix this error compile TypeScript to JavaScript or use 'ts-node' to run your app.

      at findPlugins (node_modules/fastify-autoload/index.js:87:15)
      at fastifyAutoload (node_modules/fastify-autoload/index.js:19:19)

Edit: Additionally if I hardcode this line: image

~It mostly works, but doesn’t load an index.ts file in the services folder from:~ EDIT: it works fine - I did not correctly understand the new behavior of how autoload plugin handles nested folders ~I am waiting for fastify.ready() but it seems like it’s firing before the second call to the autoload plugin has finished resolving or something.~ EDIT: It loads all modules correctly according to how Autoload uses nested folders as pathnames now.

Any help is appreciated 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wolfejw86commented, Jul 15, 2020

yes i’ll be happy to. i have kind of a crazy week but will knock it out over the weekend if that’s okay 😃

0reactions
mcollinacommented, Oct 30, 2020

There should be no real difference between the two.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest is not recognized by typescript - Stack Overflow
What I always do when I have to test my projects is the following. I will try to explain step by step. 1-...
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . Make sure it is installed in your project. The configuration also can be ...
Read more >
Presets | ts-jest - GitHub Pages
If you are using custom transform config, please remove preset from your Jest config to avoid issues that Jest doesn't transform files correctly ......
Read more >
[SOLVED] Cannot Find Name 'it' Jest TypeScript Error
To fix the “cannot find name 'it'” Jest error, install the type definitions for Jest with npm i -D @types/jest and add them...
Read more >
[Sovled] Jest error Cannot find name 'it' in TypeScript
If the error is still not resolved, make sure that TypeScript is picking up the directory ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found