textlint-rule / textlint-rule-no-dead-link

textlint rule to check if all links are alive.
30 stars 11 forks source link

Tests failed #138

Open massongit opened 2 years ago

massongit commented 2 years ago

The following tests failed:

$ npm test
...
  6 failing

  1) no-dead-link
       should treat 301 https://httpstat.us/301:

      AssertionError [ERR_ASSERTION]: "message should be "https://httpstat.us/301 is redirected to https://httpstat.us/. (301 Moved Permanently)"
      + expected - actual

      -https://httpstat.us/301 is dead. (301 Moved Permanently)
      +https://httpstat.us/301 is redirected to https://httpstat.us/. (301 Moved Permanently)

      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/test-util.ts:121:24
      at Array.forEach (<anonymous>)
      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/test-util.ts:91:16
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

  2) no-dead-link
       Fixer: should treat 301 https://httpstat.us/301:

      AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ 'should treat 301 https://httpstat.us/301'
- 'should treat 301 https://httpstat.us/'
      + expected - actual

      -should treat 301 https://httpstat.us/301
      +should treat 301 https://httpstat.us/

      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/textlint-tester.ts:239:28
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

  3) no-dead-link
       should treat 301 [link](https://httpstat.us/301):

      AssertionError [ERR_ASSERTION]: "message should be "https://httpstat.us/301 is redirected to https://httpstat.us/. (301 Moved Permanently)"
      + expected - actual

      -https://httpstat.us/301 is dead. (301 Moved Permanently)
      +https://httpstat.us/301 is redirected to https://httpstat.us/. (301 Moved Permanently)

      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/test-util.ts:121:24
      at Array.forEach (<anonymous>)
      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/test-util.ts:91:16
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

  4) no-dead-link
       Fixer: should treat 301 [link](https://httpstat.us/301):

      AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ 'should treat 301 [link](https://httpstat.us/301)'
- 'should treat 301 [link](https://httpstat.us/)'
      + expected - actual

      -should treat 301 [link](https://httpstat.us/301)
      +should treat 301 [link](https://httpstat.us/)

      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/textlint-tester.ts:239:28
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

  5) no-dead-link
       should treat 302 [link](https://httpstat.us/302):

      AssertionError [ERR_ASSERTION]: "message should be "https://httpstat.us/302 is redirected to https://httpstat.us/. (302 Found)"
      + expected - actual

      -https://httpstat.us/302 is dead. (302 Found)
      +https://httpstat.us/302 is redirected to https://httpstat.us/. (302 Found)

      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/test-util.ts:121:24
      at Array.forEach (<anonymous>)
      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/test-util.ts:91:16
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

  6) no-dead-link
       Fixer: should treat 302 [link](https://httpstat.us/302):

      AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected

+ 'should treat 302 [link](https://httpstat.us/302)'
- 'should treat 302 [link](https://httpstat.us/)'
      + expected - actual

      -should treat 302 [link](https://httpstat.us/302)
      +should treat 302 [link](https://httpstat.us/)

      at /path/to/textlint-rule-no-dead-link/node_modules/textlint-tester/src/textlint-tester.ts:239:28
      at processTicksAndRejections (node:internal/process/task_queues:96:5)

ERROR: "unittest" exited with 6.
azu commented 2 years ago

It looks taht httpstat behavior is changed.

azu commented 2 years ago

When request with {redirect: 'follow'} option, httpstat return dead link.

First HEAD Request is succuss, but second redirect:follow request is failed. https://github.com/textlint-rule/textlint-rule-no-dead-link/blob/6c723f6249573a7154d25cc80a104ffc00ad270a/src/no-dead-link.js#L171-L174

I'm not faimilar with {redirect: follow} works.

azu commented 2 years ago

reproduce code. HEAD with follow is broken.

await fetch("https://httpstat.us", { method: "HEAD", redirect: "follow"})
// [HTTP/1.1 405 Method Not Allowed 144ms]
// Response { type: "basic", url: "https://httpstat.us/", redirected: false, status: 405, ok: false, statusText: "Method Not Allowed", headers: Headers, body: ReadableStream, bodyUsed: false }
azu commented 2 years ago
await fetch("https://httpstat.us", { method: "HEAD" })

It looks like that https://httpstat.us/ top page does not allow HEAD request. I do not know that this is expected behavior. Probably, It is reguression bug.

azu commented 2 years ago

https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/138#issuecomment-1019400545 This finalRes line does not donsider to treat the request error. It may be a bug.

Workaround: We can also use altenerive site like https://httpbin.org/ as workaround.