modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.15k stars 271 forks source link

Test Runner config rootPath is resolved relative to cwd, not the path of the config #2720

Open jahorton opened 2 months ago

jahorton commented 2 months ago

The rootPath used by the server, which affects paths that need manually loading during tests, is inconsistently specified. Suppose the following setup:

Suppose within my.config.js, I set rootPath: '../../ - that is, to the parent directory of both src and node_modules.

If I run web-test-runner --config my.config.js with the cwd (current working directory) = test/, the rootPath is based at repo/. I can then request /src/cat.png to fetch my resource.

If I instead run the same command with cwd = src/, the rootPath is now the parent folder of repo/, and the server's paths are now different: I have to request /repo/src/cat.png to get the same resource.

Note that there are no changes made to my.config.js - the only change is the current working directory when I run the web-test-runner command.

Current version: "@web/test-runner": "0.18.1"