Ava: --match when debugging does not filter tests to only matched items

Created on 17 Mar 2020  Â·  7Comments  Â·  Source: avajs/ava

Not sure if this is possible or supposed to be working currently, will close if it's not a target for development.

Passing --match to ava debug should allow the user to debug a single test in a test file with many tests.

Not available/working on current 3.6.0 version.

EDIT:

The issue is that --match seems to be ignored and all tests in a file are still running, regardless of the --match statement.

This can be tested by adding 2 tests to a file, adding debugger statements to both tests, and then attempting to match the second test when running the ava debug command.

Expected: Only matched test hits its breakpoint.
Actual: All tests hit breakpoints, in order of execution (running with --serial makes this more predictable/testable) regardless of --match

(I am using VSCode and ava 3.6.0)

question

Most helpful comment

VSCode reads this as the complete argument when viewing debug console:

C:\<REDACTED>/node_modules/.bin/ava.CMD debug c:\<REDACTED>\test\int\file.test.js --verbose '--match "Filter for 1 or more GroupIDs"' --break --serial

Did you notice how --match is enclosed in quotes? '--match "Filter for 1 or more GroupIDs"'.

Try this instead:

 {
   "type": "node",
   "request": "launch",
   "name": "Debug AVA test file",
   "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
   "runtimeArgs": [
       "debug",
       "${file}",
       "--verbose",
       "--break",
       "--serial",
-      "--match \"bar\""
+      "--match=\"bar\""
   ],
   "port": 9229,
   "outputCapture": "std",
   "skipFiles": [
       "<node_internals>/**/*.js"
   ]
 }

All 7 comments

Yes this ought to work.

Does --match work without debug?

When you use it with debug, what behavior are you seeing?

Can you debug without --match?

@novemberborn Thanks for the speedy response.

Match works without debug exactly as expected.
Using it with debug seems to just ignore it entirely.
Debugging works as expected without match.

I can't reproduce this:

const test = require('ava')

test('foo', t => {
  debugger
  t.pass()
})

test('bar', t => {
  debugger
  t.pass()
})
npx ava -v --match 'foo'

  ✔ foo

  1 test passed
npx ava debug -v --match 'foo'

Debugger listening on ws://127.0.0.1:9229/4306d07f-0c8b-49d8-9043-60a21d1f1fd0
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
  ✔ foo (3.4s)
Waiting for the debugger to disconnect...

  1 test passed

The debugger only kicked in for the foo test. (There's only a test.js file in this project so there was no need to specify the file path for ava debug.)

I can't think of any reason this wouldn't work, so if you could share a reproduction that'd be great.

For now, I'm closing this issue for housekeeping purposes, but happy to re-open of course.

@novemberborn Thank you for your time and quick reply, sorry it has taken me so long to get back to you;

TL;DR

The issue is not that debugging is not working at all, it is. The issue is that when debugging (with debugger statement or VSCode debug) 2 items in the same file, the first item is always debugged first.

This leads me to the belief that even if I only set 1 break point in a file, all tests will be run through anyway, until they get to the breakpoint, even when using match. This of course is not desired functionality as when not debugging, the only item that is tested is the one that matches the statement.

I have allot of time, so i'm reading...

I'm still experiencing the issue even when playing around with the settings some more, with a fresh mind. Here are some extended details on my environment:

Enviroment structure

I have created a fresh test project structure like the following:

- node_modules
- test
-- int
--- file.test.js

Code

Within integration.test.js i have code like the following:

const test = require('ava')

test('foo', (t) => {
    debugger
    t.pass()
    // ... tests ...
})

test('bar', (t) => {
    debugger
    t.pass()
    // ... tests ...
})

launch.json

I'm using VSCode debugger mode, so it is handling the 'debugger' statements.
VSCode launch.json is set up in the following way:

        {
            "type": "node",
            "request": "launch",
            "name": "Debug AVA test file",
            "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
            "runtimeArgs": [
                "debug",
                "${file}",
                "--verbose",
                "--break",
                "--serial",
                "--match \"bar\""
            ],
            "port": 9229,
            "outputCapture": "std",
            "skipFiles": [
                "<node_internals>/**/*.js"
            ]
        }

RuntimeArgs

The debugging behavior is exactly the same when the --match... line is commented out. The debugger pauses on the first test always.

I have tried a mixture of all the runtimeArgs you see there, (with, without, changed order.)

Command output

VSCode reads this as the complete argument when viewing debug console:

C:\<REDACTED>/node_modules/.bin/ava.CMD debug c:\<REDACTED>\test\int\file.test.js --verbose '--match "Filter for 1 or more GroupIDs"' --break --serial 

Extra

In order to debug with VSCode i must pass in break so any of my breakpoints are effective.

PS. I have redacted parts of this post and changed certain names for security reasons, i've tried to include as much useful information as possible, if there's something i'm missing, please let me know.

I've updated the title to better reflect the issue, and my original post.

VSCode reads this as the complete argument when viewing debug console:

C:\<REDACTED>/node_modules/.bin/ava.CMD debug c:\<REDACTED>\test\int\file.test.js --verbose '--match "Filter for 1 or more GroupIDs"' --break --serial

Did you notice how --match is enclosed in quotes? '--match "Filter for 1 or more GroupIDs"'.

Try this instead:

 {
   "type": "node",
   "request": "launch",
   "name": "Debug AVA test file",
   "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava",
   "runtimeArgs": [
       "debug",
       "${file}",
       "--verbose",
       "--break",
       "--serial",
-      "--match \"bar\""
+      "--match=\"bar\""
   ],
   "port": 9229,
   "outputCapture": "std",
   "skipFiles": [
       "<node_internals>/**/*.js"
   ]
 }

@novemberborn

Works perfectly, thankyou

Was this page helpful?
0 / 5 - 0 ratings