ava: AssertionError when debugging in VS Code
Hey I’ve been using the VS Code debugger launch configuration from here for quite a while now, but since updating to V4 I cannot get it to work anymore. Whenever I run it, I run into this error on any of the test files:
Uncaught exception in tests\temp.tests.ts
AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
assert(refs.runnerChain)
× tests\temp.tests.ts exited with a non-zero exit code: 1
─
1 uncaught exception
The example test file used (the error occurs on any test file though):
import test from "ava";
test("ava test", t =>
{
t.pass();
});
The VS Code launch.json
(exact copy from the linked docs):
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug AVA test file",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
"runtimeArgs": [
"${file}"
],
"outputCapture": "std",
"skipFiles": [
"<node_internals>/**/*.js"
]
}
]
}
AVA configuration in package.json
:
"ava": {
"extensions": [
"ts"
],
"files": [
"tests/**/*.tests.ts"
],
"require": [
"./tests/_setup.js",
"ts-node/register"
],
"verbose": true
}
Running npx ava --version
reports 0.1.0? I have 4.0.1 installed according to the package.json
and the node_modules/ava
folder and both npm install
and npm update
do not change that.
AVA debugging still works in another project running 3.15
This sounds like a bug right?
Thank you for your time!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 30 (15 by maintainers)
Commits related to this issue
- Fix #2946 — committed to AlencarGabriel/ava by AlencarGabriel 2 years ago
- fix(ava): AssertionError assert(refs.runnerChain) evaluated to a falsy value - suspect this is due to some sort of ava instance mismatch. see https://github.com/avajs/ava/issues/2946#issuecomment-171... — committed to agoric-labs/ag-power-tools by 0xpatrickdev 6 months ago
- fix(ava): AssertionError assert(refs.runnerChain) evaluated to a falsy value - suspect this is due to some sort of ava instance mismatch. see https://github.com/avajs/ava/issues/2946#issuecomment-171... — committed to agoric-labs/ag-power-tools by 0xpatrickdev 6 months ago
@ctjlewis please understand that I maintain AVA as a hobby — I have plenty of work obligations and non-computer stuff to get on with. I’d appreciate it if you’d bring a constructive and positive attitude to your comments here, rather than dismissing my efforts. Sometimes it can be better not to press that “Comment” button.
It’s environment, for sure:
I ran into this issue even using the configuration recommend in this thread, and wanted to share the problem and solution for other Googlers.
TL;DR
Different copies of
ava
were being used/imported. To fix, remove the copies or ensure you’re importing the same copy (as in, the same files on disk/memory) that was used to run the tests.Long answer
My project has nested package.json files (and nested node_modules), and each package specified
ava
as a dev dependency, like this:So there were multiple copies of
ava
installed in the project. My launch.json file was running(root)/node_modules/ava/entrypoints/cli.mjs
(as recommended in this thread), but the test files were importing their own copy ofava
(eg from(root)/packages/packageA/node_modules/ava/
.refs.runnerChain
is a global state in each copy ofava
, so with different copies being imported,refs.runnerChain
was set in one copy but not the other, hence the error.Done. Glad I could help!
@AlencarGabriel @novemberborn Your launch.json works for me as well! I can debug in VS Code again! 🥳
Another difference is that it’s using
program
andargs
keys instead ofruntimeExecutable
andruntimeArgs
, which are apparently different.See the diff of the new file here:
@TheBrenny it’s assigned here:
https://github.com/avajs/ava/blob/c5d2b53de8992abd36afd2387e45ed35db79a7e6/lib/worker/base.js#L68
This is the code that is managed by AVA. By the time the test file is loaded, which ends up loading
lib/worker/main.cjs
when it imports'ava'
, the chain should be set. Something’s really gone wrong if that assertion fails, as we’ve seen in this discussion. But it’s not something I’d expect to happen unless the environment has been tampered with.It’s not surprising that you couldn’t reproduce it because it’s a nondeterministic bug.
Closing this issue is inappropriate but you’re free to do it, though that would mean this software is no longer being actively maintained.
I just ran into it again a few minutes ago.
It’s a caching issue of some kind.
rm -rf node_modules/ava && yarn add -D ava
got me back to working state.You can provide a specific test file as an argument.
It is the problem, but under normal execution it is supposed to be assigned. The question is why is that not happening.