salesforce / tough-cookie

RFC6265 Cookies and CookieJar for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error running jest test

kurund opened this issue · comments

Hello,

I am getting the following error while running the test suite. UI works fine without any issues.

  ● Test suite failed to run

    Cookie has domain set to the public suffix "localhost" which is a special use domain. To allow this, configure your CookieJar with {allowSpecialUseDomain:true, rejectPublicSuffixes: false}.

      at Object.getPublicSuffix (node_modules/tough-cookie/lib/pubsuffix-psl.js:62:11)
      at permuteDomain (node_modules/tough-cookie/lib/permuteDomain.js:38:28)
      at MemoryCookieStore.findCookies (node_modules/tough-cookie/lib/memstore.js:99:21)
      at MemoryCookieStore.findCookies (node_modules/tough-cookie/node_modules/universalify/index.js:5:67)
      at CookieJar.getCookies (node_modules/tough-cookie/lib/cookie.js:1410:11)
      at CookieJar.getCookies (node_modules/tough-cookie/node_modules/universalify/index.js:5:67)
      at CookieJar.getCookieString (node_modules/tough-cookie/lib/cookie.js:1455:21)
      at CookieJar.getCookieString (node_modules/tough-cookie/node_modules/universalify/index.js:5:67)
      at CookieJar.getCookieStringSync (node_modules/tough-cookie/lib/cookie.js:1726:17)
      at DocumentImpl.get cookie [as cookie] (node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:860:28)

Any thoughts how to fix this?

As a workaround you could try to add custom testURL property to jest configuration.

Example using jest configuration in package.json
"jest": { "testURL": "https://jestjs.io" }

Example using jest configuration in package.json
"jest": { "testURL": "https://jestjs.io" }

Thank you. This fixes the test failure.

I tried without any luck (jest 27)

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
  preset: 'jest-expo',
  rootDir: '../../',
  testURL: 'http://localhost:3001',
  setupFilesAfterEnv: ['./test/jest/setup.js'], 

(also tried using https://jestjs.io just in case that does some 🪄)

Cookie has domain set to the public suffix "localhost" which is a special use domain. To allow this, configure your CookieJar with {allowSpecialUseDomain:true, rejectPublicSuffixes: false}.

      at Object.getPublicSuffix (node_modules/tough-cookie/lib/pubsuffix-psl.js:62:11)
      at permuteDomain (node_modules/tough-cookie/lib/permuteDomain.js:38:28)

testEnvironmentOptions: { url: "https://jestjs.io", },

worked for me (jest 29)

Please try with our latest release, we have updated our treatment of single word domains for localhost and invalid per RFC 6761: https://www.rfc-editor.org/rfc/rfc6761.html

This should be fixed in 4.1.2. Please let us know if you see any more issues.

Thank you. I can confirm that it's fixed for me.