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

Most upvoted comments

@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.

import test from 'ava';

test('sync test', (t) => {
  t.pass();
});

test('async test', async (t) => {
  const bar = Promise.resolve('bar');
  t.is(await bar, 'bar');
});
>nvm use v16
Now using node v16.14.2 (npm v8.5.0)
>npx ava test/sanity.js 

  ✔ sync test
  ✔ async test
  ─

  2 tests passed
>nvm use v14
Now using node v14.19.1 (npm v6.14.16)
>npx ava test/sanity.js 
npx: installed 167 in 4.025s

  Uncaught exception in test/sanity.js

  AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

    assert(refs.runnerChain)


  ✖ test/sanity.js exited with a non-zero exit code: 1
  ─

  1 uncaught exception

It’s environment, for sure:

>nvm use v14
Now using node v14.19.1 (npm v6.14.16)
>npm install --save-dev ava

+ ava@4.1.0
added 167 packages from 87 contributors and audited 168 packages in 4.506s

>npx ava test/sanity.js 

  ✔ sync test
  ✔ async test
  ─

  2 tests passed

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:

- package.json
  - devDependencies: ava
- node_modules
  - ava
- packages
  - packageA
    - package.json
      - devDependencies: ava
    - node_modules
      - ava
  - packageB
    - package.json
      - devDependencies: ava
    - node_modules
      - ava

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 of ava (eg from (root)/packages/packageA/node_modules/ava/. refs.runnerChain is a global state in each copy of ava, so with different copies being imported, refs.runnerChain was set in one copy but not the other, hence the error.

@AlencarGabriel lovely! Would you want to open a PR to change the recommended configuration?

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 and args keys instead of runtimeExecutable and runtimeArgs, which are apparently different.

See the diff of the new file here:

image

@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 am also encountering this error. Unfortunately, the only option that I have at this point is to stop using ava. I did try completely clearing the node module cache, after rebooting, and it didn’t change a thing.

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.

(Though it runs through all files, but that’s probably intended.)

You can provide a specific test file as an argument.

I know nothing about the internals of AVA but I did find this assert, and the refs it is importing is initialized as null in state.cjs. I don’t see it being overwritten/changed in the code around it. Might that be something?

It is the problem, but under normal execution it is supposed to be assigned. The question is why is that not happening.