Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Ipfs-http-client throws an error when running jest/jsdom unit tests #3238

@lukaw3d

Description

@lukaw3d
  • Version:

ipfs-http-client@46.0.0

  • Platform:
node@12.18.3
──┬ jest@26.4.1
  └─┬ @jest/core@26.4.1
    └─┬ jest-config@26.4.1
      └─┬ jest-environment-jsdom@26.3.0
        └── jsdom@16.4.0 
  • Subsystem:

Severity:

Medium

Description:

  • What you did:
    Updated a dependency and tried to run unit tests with default jest configuration. Subdependency ipfs-http-client@40.1.0 updated to ipfs-http-client@46.0.0 and was imported require('ipfs-http-client') but not instantiated in tests.

    jest --env=node works as a workaround, if you don't need DOM

  • What happened:
    Tests crash on initialization. Global XMLHttpRequest is defined (so it uses ipfs-utils/src/http/fetch-browser.js), but global Request isn't (throws ReferenceError).

  • What you expected to happen
    Expected ipfs-http-client to continue working with jest/jsdom

Steps to reproduce the error:

newfolder
npm init -y
npm i ipfs-http-client@46.0.0
npm i jest
echo "require('ipfs-http-client'); test('a', () => {});" > a.test.js

npx jest   # [--env=jsdom] 
#> ReferenceError: Request is not defined
#  ipfs-utils/src/http/fetch-browser.js:95

npx jest --env=node
#> Success

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions