Skip to content

[🐛 Bug]: WDIO watcher does not trigger test reruns on changes in filesToWatch app files #14685

@jasper07

Description

@jasper07

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.18.4

Node.js Version

v24.5.0

Mode

WDIO Testrunner

Which capabilities are you using?

{ 
 browsername: "google-chrome-stable",
 devcontianer: "ghcr.io/devcontainers/features/node:1:latest",
 platform: "windows11 wsl2"
}

What happened?

When using WebdriverIO's watcher feature (wdio run --watch) with the filesToWatch option configured to monitor changes in application source files, the watcher does not trigger test reruns upon changes in these app files. However, it correctly detects changes in test spec files and reruns tests as expected.

What is your expected behavior?

I expect the watcher to rerun tests based on app file changes

How to reproduce the bug.

  1. Setup a WDIO configuration (wdio.conf.js) with:
specs: ['./**/*.test.js'],
filesToWatch: ['./**/**/*.js'],  // watch for changes in app files
  1. Ensure a local web server is running to serve your app under test (e.g. via ui5 serve on port 8081).

  2. Start the test run with watcher enabled:

wdio run ./path/to/wdio.conf.js --watch
  1. Modify a test spec file (e.g., unit.test.js). Observe the tests rerun automatically.

  2. Modify an app source file matching the filesToWatch glob (e.g., a .js file in the app directory). Observe no test rerun triggered

Relevant Observation

Internally, WebdriverIO watcher converts filesToWatch globs to absolute file URIs (e.g., file:///absolute/path/**/*.js),
eg - not watched

file:///workspaces/myproject/app/app1/webapp/**/*.js 

whereas spec files are watched using filesystem paths (e.g., /absolute/path/unit.test.js).
eg is watched

/workspaces/myproject/app/app1/webapp/test/unit/unit.test.js

This difference in path format causes chokidar (the file watcher library WDIO uses) to ignore the changes in app files watched through filesToWatch.

https://github.com/webdriverio/webdriverio/blob/0c77bb179191e3432b5d3a112dee652e6827e2fd/packages/wdio-cli/src/watcher.ts#L43:L62

The watcher remains active and does not crash or stop responding; it merely does not respond to changes in app files. Still works for spec changes.

Running an external chokidar CLI watcher to manually rerun tests on app file changes is a reliable workaround.

// excerpt from package.json scripts

"serve:ui5": "ui5 serve --port 8081",
"test": "wdio run ./webapp/test/wdio.conf.js",
"test:watch": "chokidar './webapp/**/*.js' -c 'npm run test'",
"test:watch:ready": "wait-on tcp:8081 & npm run test:watch",
"tdd": "run-p serve:ui5 test:watch:ready"

i debugged chokidar-cli and can see chokidar is called with
/workspaces/myproject/app/app1/webapp/**/*.js - works

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions