Closed sculpt0r closed 2 years ago
- I found that it should be useful to additionally install
source-map-support
- so I did it
AVA enables the source map support built into Node.js so this shouldn't be necessary.
- also the
compile
is set totsc
, but if I try to run tests withcompile
set onfalse
and thebuild
directory already contains js files - I receive the same results as in the screenshot above
Yea, when set to tsc
AVA first does a build, and then runs the tests.
The generated JS code uses ESM syntax:
import test from 'ava';
test('some name', t => {
t.pass();
});
function someTsSyntax() {
console.log('anything');
}
//# sourceMappingURL=test.js.map
However this is a test.js
file, and there is no "type": "module"
in your package.json
, which means that AVA will require()
it. The file is treated as CommonJS and you cannot use ESM syntax then.
You need to configure TypeScript to output to the CommonJS module syntax, or switch to ESM properly.
Thank you for your explanation ❤️ I'll try to make a proper setup :)
Thank you again:
"type": "module"
in package.json
"module": "CommonJS"
in tsconfig.json
Also, I removed the source-map-support
Time to move to bigger project 🤞
Looks like precompiling tests help a lot with time out and speed of tests. Can't confirm 100% - but the only thing that stops me is https://github.com/microsoft/TypeScript/issues/26722#issuecomment-516935532
Overall - it feels like this issue could be closed?
Edit: 100% - precompiled tests works like a charm 👍
Can you help me look at my configuration here? It looks like something went wrong. 🙏 cc @novemberborn
@liby It is hard to look at your config if you do not share it ;)
It is hard to look at your config if you do not share it ;)
Oh, sorry, I forgot to attach the link
You use old AVA version - is there any reason why you can't upgrade? Also, you use cfg for the old way of supporting TS. Anyway, we need you to be more informative ;)
What is wrong with your config? Are there any errors? What steps did you try already?
You use old AVA version - is there any reason why you can't upgrade?
I am using the latest version@4.3.3, are you reading it wrong?
Anyway, we need you to be more informative ;)
I got the Timed out while running tests
error in CI/CD. By searching, I found two solutions:
compile: false
and precompile
What is wrong with your config? Are there any errors? What steps did you try already?
To fix the Timed out while running tests
error, I made the following changes:
But CI/CD started complaining even before the Timed out while running tests
error appeared:
✖ Unexpected duplicate extensions in options: ’ts’.
Error: Process completed with exit code 1.
So I wonder if I've written my configuration wrong.
@liby I think you got your config wrong, from the link you shared I see that you have
"typescript": {
"rewritePaths": {
"src/": "build/"
},
"compile": false
}
But your file structure does not match your rewritePaths
. Imagine you have your tests at root directory under tests
and your TypeScript outDir
is set to dist
. This would mean that your transpiled tests would be at dist/tests
your-app/
├─ dist/
│ ├─ tests/
│ │ ├─ myTest.js
├─ tests/
│ ├─ myTest.ts
├─ package.json
Then your rewrites would have to be
"typescript": {
"rewritePaths": {
"tests/": "dist/tests"
},
"compile": "tsc"
}
Note that is required that the value of compile
is set to tsc
Looking at your repo you have your tests under __test__
, since tsc artifacts are not tracked on Git I don't know the name of your outDir
, your configuration would have to be something like
"typescript": {
"rewritePaths": {
"__test__": <your-outDir-path-to-tests>
},
"compile": "tsc"
}
Note that is required that the value of
compile
is set totsc
Is this something that has to be done? I disabled it because @novemberborn mentioned that it said “Would be interesting to try with compile: false and precompile” and wanted to try it out.
After testing, I feel that tsc
is not suitable for use in my repo.
With it set to false you need to run tsc yourself before running tests.
With it set to false you need to run tsc yourself before running tests.
Thanks for the reminder. So when I get an Timed out while running tests
error in CI/CD, is setting compile
to false
the only solution? Setting timeout to 80s can solve this issue temporarily, but it will lead to too long job time.
Typically from what I've seen, compilation through loader extensions can take so long, or fails quietly, that AVA gives up. I always precompile so that the tests are run with JavaScript.
Looking at the code, the time taken by compile: 'tsc'
also counts towards AVAs timeout threshold.
I always precompile so that the tests are run with JavaScript.
Because I've been using @swc-node/register
to compile.
I also tried to switch to using tsc
before, but I encountered a lot of issues not knowing how to solve them, can you show me your config?
After looking at it, I think there is still a difference between my repo and get-port
. My repo works mainly in the node
environment. If migrate to tsc
and use precompile, I will have to change a lot of config like tsconfig
.
There may be some other problems in this process, so I may continue to use [@swc-node/register](https://github.com/swc-project/swc-node/tree/master/packages/register?rgh-link-date=2022-09-04T14%3A12%3A01Z#ava)
.
Please provide details about:
Please share relevant sample code. Or better yet, provide a link to a minimal reproducible example.
We'll also need your AVA configuration (in
package.json
orava.config.*
configuration files) and how you're invoking AVA. Share the installed AVA version (get it by runningnpx ava --version
) and@ava/babel
version (from yourpackage.json
file).I try to setup AVA 4 with TS for a bigger project. But to simplify things I reduce the problem to a simply project: https://github.com/sculpt0r/AVAwithTS
Now I try to run
npm run test
. The results is:I tried to follow the documentation of AVA & this plugin:
AVA
(4.3.0
)@ava/typescript
(3.0.1
)source-map-support
- so I did it and in cfg file I added:.tsconfig
theoutDir
is set to the same directory (build
) as in AVA config rewrite pathscompile
is set totsc
, but if I try to run tests withcompile
set onfalse
and thebuild
directory already contains js files - I receive the same results as in the screenshot aboveI assume I'm missing something - but I'm not sure what? Is it possible to take a look at the sample project: https://github.com/sculpt0r/AVAwithTS, then run
npm i
and thennpm run test
.