Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Invalid URL for test on Windows #298

Closed
MikeMcC399 opened this issue Mar 11, 2024 · 6 comments
Closed

TypeError: Invalid URL for test on Windows #298

MikeMcC399 opened this issue Mar 11, 2024 · 6 comments

Comments

@MikeMcC399
Copy link

MikeMcC399 commented Mar 11, 2024

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

> markdown-link-check@3.12.0 pretest
> eslint .


> markdown-link-check@3.12.0 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)
@MikeMcC399
Copy link
Author

MikeMcC399 commented Mar 11, 2024

It seems that npm test on Windows 11 fails due to two incompatibilities in test/markdown-link-check.test.js:

  1. not compatible with IPv6 loopback address ::1
  2. 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.

@MikeMcC399
Copy link
Author

MikeMcC399 commented Mar 11, 2024

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

> markdown-link-check@3.12.0 pretest
> eslint .


> markdown-link-check@3.12.0 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)

@dklimpel
Copy link
Contributor

Code for fixing the IPv6 part was there: https://github.com/tcort/markdown-link-check/pull/294/files

@MikeMcC399
Copy link
Author

@dklimpel

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.

@dklimpel
Copy link
Contributor

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:

markdownLinkCheck(fs.readFileSync(path.join(__dirname, 'local-file.md')).toString().replace(/%%BASE_URL%%/g, 'file://' + __dirname), {baseUrl: 'file://' + __dirname, projectBaseUrl: 'file://' + __dirname + "/..",replacementPatterns: [{ pattern: '^/', replacement: "{{env.WORKSPACE}}/"}]}, function (err, results) {

like, https://stackoverflow.com/questions/66081774/how-to-specify-in-nodejs-file-url-a-absolute-path-under-windows

@MikeMcC399
Copy link
Author

This issue is no longer reproducible in v3.12.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants