Import problems within test files #3249
Unanswered
dustsucker
asked this question in
Q&A
Replies: 1 comment
-
It’s not clear to me how these tests ever worked. The TypeScript support in AVA is meant for test files written in TypeScript. Converting the test files is probably the most consistent approach, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I just found an inactive NPM module that I wanted to use and tested it out, it worked but had some stuff that's missing for me. So I tried cloning it and getting it to run locally, so I can add the features I want. I bumped the dependence versions, got it to compile again, moved to ESLint from TSLint and tried running the tests. The tests didn't work, all local dependencies were not recognized, so I began to experiment. The tests are written in JS, the lib itself is written in ts. The test imported the ts files directly from source, so for example: '../src/docker' that gave me a:
Uncaught exception in test/docker.js
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '~/node-docker-api/src/docker' imported from ~/node-docker-api/test/docker.js
so I changed it to '../src/docker.ts'':
Uncaught exception in test/docker.js
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for ~/node-docker-api/src/docker.ts
then I thought maybe I need to import from the compiled lib folder, so I moved on to '../lib/docker'':
Uncaught exception in test/docker.js
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '~/node-docker-api/lib/docker' imported from ~/node-docker-api/test/docker.js
than to '../lib/docker.js':
Uncaught exception in test/docker.js
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '~/node-docker-api/lib/container' imported from ~/node-docker-api/lib/docker.js
and finally '../lib/docker.ts'
Uncaught exception in test/docker.js
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '~/node-docker-api/lib/docker.ts' imported from ~/node-docker-api/test/docker.js
So it didn't work
then I tried fixing the problem with AVA typescript with the configuration:
"ava": {
"files": ["test/**/*.js"],
"typescript": {
"extensions": [
"ts",
"tsx"
],
"rewritePaths": {
"src/": "lib/"
},
"compile": "tsc"
}
},
Didn't work I changed the ts config module option from commonjs to ESNext didn't work either.
A now I don't know anything I can try to get it working.
I just need it to import the classes from the lib, that's all.
Sample code:
It's not quite a minimal example, but it's quite small: https://github.com/dustsucker/node-docker-api any changes I made are reflected int that fork of the NPM module.
As for AVA version, I use 5.3.1.
I hope you can help me :)
Beta Was this translation helpful? Give feedback.
All reactions