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

No resolver for typescript with ts-jest #387

Closed
cojack opened this issue Nov 19, 2020 · 4 comments · Fixed by #388
Closed

No resolver for typescript with ts-jest #387

cojack opened this issue Nov 19, 2020 · 4 comments · Fixed by #388

Comments

@cojack
Copy link

cojack commented Nov 19, 2020

Version: 3.0.0-beta.8
Storage: SequelizeStorage
Sequelize: 6.1.1
Node: 15.0.1
Dev setup: Typescript@3.9.6

When I try to run test with jest with preset: ts-jest I've got a error back:

No resolver specified for file /home/cojack/Projects/xxx/xxx-sequelize/src/__tests__/migrations/1589746665497-example.ts. You can use the default resolver with typescript files by adding `ts-node` as a dependency and calling `require('ts-node/register')` at the program entrypoint before running migrations. See docs for guidance on how to write a custom resolver.

So I have no clue, how this should working. Any advice? I've tried to add a require('ts-node/register'); at the top of the entry point, where it was a jest.config.js file, also I tried to run jest with configuration like:

node -r ts-node/register ./node_modules/.bin/jest ...

without success, also tried to add this require into the test file, also without success, same thing happen.

Also repository doesn't provide any example of tests that works that way, only README with hidden section explains how it should works, but it doesn't.

So my question is: does it works? And if so, how I should configure it to works that way.

Regards.

@cojack
Copy link
Author

cojack commented Nov 19, 2020

Related to the ts-jest kulshekhar/ts-jest#2144

@mmkal
Copy link
Contributor

mmkal commented Nov 19, 2020

@cojack thanks for the report. Just to check, do your migrations work ok when running normally (i.e. outside of jest)?

Either way, it shouldn't be too hard to find a workaround which detects ts-jest and lets you require typescript from that environment too. Will add a test for this use case as well.

In the meantime did you try adding a custom resolver that works like the default one but skips file extension validation? It'd be something like:

migrations: {
  glob: 'a/b/*.ts',
  resolve: params => ({ ...params, ...require(params.path!) }),
}

@mmkal mmkal changed the title No resolver for typescript No resolver for typescript with ts-jest Nov 19, 2020
@mmkal
Copy link
Contributor

mmkal commented Nov 19, 2020

@cojack fix released in 3.0.0-beta.9 (npm install umzug@beta), let me know if you have problems with it.

@cojack
Copy link
Author

cojack commented Nov 23, 2020

@mmkal yes, now it works, thanks!

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.

2 participants