TypeError: Invalid URL for test on Windows
Issue
Running the test suite npm test on Microsoft Windows 11 results in TypeError: Invalid URL for 7 of the tests.
Repro steps
markdown-link-checkv3.12.0
Windows 11
Node.js v20.11.1 (LTS)
git clone https://github.com/tcort/markdown-link-check
cd markdown-link-check
npm ci
npm test
Logs
$ npm test
> [email protected] pretest
> eslint .
> [email protected] test
> mocha -R spec --exit
markdown-link-check
1) should check the links in sample.md
2) should check the links in file.md
3) should check the links in local-file.md
4) should handle thousands of links (this test takes up to a minute)
5) should handle links with parens
6) should enrich http headers with environment variables
7) should enrich pattern replacement strings with environment variables
✔ should correctly resolve special replacement patterns
- check hash links
1 passing (2s)
1 pending
7 failing
1) markdown-link-check
should check the links in sample.md:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\markdown-link-check\index.js:117:9
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:90:9)
at process.processImmediate (node:internal/timers:478:21)
2) markdown-link-check
should check the links in file.md:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\markdown-link-check\index.js:117:9
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:175:9)
at process.processImmediate (node:internal/timers:478:21)
3) markdown-link-check
should check the links in local-file.md:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\markdown-link-check\index.js:117:9
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:197:9)
at process.processImmediate (node:internal/timers:478:21)
4) markdown-link-check
should handle thousands of links (this test takes up to a minute):
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\markdown-link-check\index.js:117:9
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:229:9)
at process.processImmediate (node:internal/timers:478:21)
5) markdown-link-check
should handle links with parens:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\markdown-link-check\index.js:117:9
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:244:9)
at process.processImmediate (node:internal/timers:478:21)
6) markdown-link-check
should enrich http headers with environment variables:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\markdown-link-check\index.js:117:9
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:256:9)
at process.processImmediate (node:internal/timers:478:21)
7) markdown-link-check
should enrich pattern replacement strings with environment variables:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\markdown-link-check\index.js:117:9
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:278:9)
at process.processImmediate (node:internal/timers:478:21)
- I noticed this issue when looking at https://github.com/tcort/markdown-link-check/issues/291
It seems that npm test on Windows 11 fails due to two incompatibilities in test/markdown-link-check.test.js:
- not compatible with IPv6 loopback address
::1 - not compatible with Windows file paths (I didn't investigate this part in depth. I may be wrong.)
It's possible to work around the IPv6 issue by setting the environment variable NODE_OPTIONS to --dns-result-order=ipv4first, however that doesn't work around the suspected file path issue.
Logs with workaround for IPv6 problem added. In this case, instead of 7 test failing, the number of failed tests is reduced to 3.
$ NODE_OPTIONS='--dns-result-order=ipv4first' npm test
> [email protected] pretest
> eslint .
> [email protected] test
> mocha -R spec --exit
markdown-link-check
✔ should check the links in sample.md (2664ms)
1) should check the links in file.md
2) should check the links in local-file.md
✔ should handle thousands of links (this test takes up to a minute) (18924ms)
✔ should handle links with parens
✔ should enrich http headers with environment variables (2581ms)
3) should enrich pattern replacement strings with environment variables
✔ should correctly resolve special replacement patterns
- check hash links
5 passing (24s)
1 pending
3 failing
1) markdown-link-check
should check the links in file.md:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\tmp\markdown-link-check\index.js:117:9
at D:\github2\tmp\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\tmp\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:175:9)
at process.processImmediate (node:internal/timers:478:21)
2) markdown-link-check
should check the links in local-file.md:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\tmp\markdown-link-check\index.js:117:9
at D:\github2\tmp\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\tmp\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:197:9)
at process.processImmediate (node:internal/timers:478:21)
3) markdown-link-check
should enrich pattern replacement strings with environment variables:
TypeError: Invalid URL
at new URL (node:internal/url:775:36)
at linkCheck (node_modules\link-check\index.js:21:47)
at D:\github2\tmp\markdown-link-check\index.js:117:9
at D:\github2\tmp\markdown-link-check\node_modules\async\dist\async.js:247:13
at replenish (node_modules\async\dist\async.js:448:21)
at D:\github2\tmp\markdown-link-check\node_modules\async\dist\async.js:453:13
at _asyncMap (node_modules\async\dist\async.js:245:16)
at Object.mapLimit (node_modules\async\dist\async.js:2093:16)
at Object.awaitable [as mapLimit] (node_modules\async\dist\async.js:212:32)
at markdownLinkCheck (index.js:74:11)
at Context.<anonymous> (test\markdown-link-check.test.js:278:9)
at process.processImmediate (node:internal/timers:478:21)
Code for fixing the IPv6 part was there: https://github.com/tcort/markdown-link-check/pull/294/files
@dklimpel
- Code for fixing the IPv6 part was there: https://github.com/tcort/markdown-link-check/pull/294
Perhaps this PR should be reactivated? That would however only be an advantage if the other Windows issues are going to be addressed.
I checked locally on Ubuntu 22.04 with a default network setup and there were no problems running npm test. I don't have macOS available, so I don't know how the test behaves on that operating system.
- PR https://github.com/tcort/markdown-link-check/pull/296 is only a workaround for GitHub. This was good to do as it was a quick and low-risk change.
It looks like an "upstream" issue with the windows path, there:
https://github.com/tcort/link-check/blob/cefe9ccf2db982a93d53261d9481415e567b5635/index.js#L21
const url = link.startsWith('#') ? link : new URL(link, opts.baseUrl);
or a wrong path in tests:
https://github.com/tcort/markdown-link-check/blob/2b0095f27070092435ed8a1c0f60d78c1103c6e3/test/markdown-link-check.test.js#L278
like, https://stackoverflow.com/questions/66081774/how-to-specify-in-nodejs-file-url-a-absolute-path-under-windows
This issue is no longer reproducible in v3.12.2.