avajs/ava

Ava fails to run in watch mode via CLI

rglover opened this issue · 2 comments

Please provide details about:

  • What you're trying to do

Run ava with the --watch flag via the CLI. I'm using child_process.exec() to trigger the CLI. Tested against the latest 6.0.1 release and 5.3.1 running on Node v21, v20, v18, and v16. Tests run fine in both standalone (no watch) mode and watch (only the initial run).

  • What happened

Ava runs tests, but exits abruptly due to error about evt.files being undefined in the watcher:

TypeError: Cannot read properties of undefined (reading 'changedFiles')
    at file:///Users/rglover/projects/cheatcode/joystick-1.0/blah/node_modules/ava/lib/watcher.js:91:35
    at file:///Users/rglover/projects/cheatcode/joystick-1.0/blah/node_modules/emittery/index.js:365:13
    at Array.map (<anonymous>)
    at RunStatus.emit (file:///Users/rglover/projects/cheatcode/joystick-1.0/blah/node_modules/emittery/index.js:363:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  • What you expected to happen

Tests run and then watch mode waits for changes.

// ava test config (ava_config.js)

const ava_config = {
  files: [`tests/**/*.test.js`],
  concurrency: 1,
  cache: false,
};

export default ava_config;

// call to run CLI via child_process

const ava_path = `${process.cwd()}/node_modules/.bin/ava`;
child_process.exec(`${ava_path} --config ${run_tests_options?.__dirname}/ava_config.js ${run_tests_options?.watch ? '--watch' : ''}`, {
  stdio: 'inherit',
  env: {
    ...(process.env),
    databases: process.databases,
    FORCE_COLOR: "1"
  }
});

Appears to have been resolved. Didn't change any of the code above so I'm guessing it was due to some of my test cases failing. Running fine w/ ava@6.0.1 against Node v16, v20, and v21.

I'm guessing it was due to some of my test cases failing

Yes, I found a code path where this may occur.