wheresrhys / fetch-mock-jest

Jest wrapper for fetch-mock, a comprehensive stub for fetch
http://www.wheresrhys.co.uk/fetch-mock/
MIT License
60 stars 11 forks source link

Move node-fetch from devDependencies to dependencies. #20

Closed jaybeeuu closed 4 years ago

jaybeeuu commented 4 years ago

I got an error copied below while trying to use v1.3.0 this library. It turns out that node-fetch is currently only a devDependency in package.json. I'm using pnpm and it's strictness meant node-fetch wasn't available when fetch-mock (which has it as a peer dependency) required it. Moving the reference into dependencies in fetch-mock-jest fixes the issue (I have verified (and worked around) that with a pnpmfile.js entry) and I thought you might like a quick PR. :)

Many thanks for the library!

   Cannot find module 'node-fetch' from '../../node_modules/.pnpm/fetch-mock@9.10.7/node_modules/fetch-mock/cjs/server.js'       

    Require stack:
      C:/dev/src/bickleywallace-site/node_modules/.pnpm/fetch-mock@9.10.7/node_modules/fetch-mock/cjs/server.js
      C:/dev/src/bickleywallace-site/node_modules/.pnpm/fetch-mock-jest@1.3.0_jest@26.4.2/node_modules/fetch-mock-jest/server.js  
      src/utils/request.spec.ts

      at Resolver.resolveModule (../../node_modules/.pnpm/jest-resolve@26.4.0_jest-resolve@26.4.0/node_modules/jest-resolve/build/index.js:307:11)
      at Object.<anonymous> (../../node_modules/.pnpm/fetch-mock@9.10.7/node_modules/fetch-mock/cjs/server.js:9:10)
wheresrhys commented 4 years ago

It's deliberate - see fetch-mock docs here: http://www.wheresrhys.co.uk/fetch-mock/#usagerequirements

I will copy those docs to fetch-mock-jest's readme though

jaybeeuu commented 4 years ago

Ahh right. I 'm with you. Thanks for pointing out the docs. Should fetch-mock-jest declare node-fetch as a peerDependency in that case?

If i install as it stands without also installing node-fetch the first you know about it is a runtime error but If i monkey patch the package.json to add node-fetch as a peerdependency then i at least get a warning at install time.

wheresrhys commented 4 years ago

fetch-mock already declares it as a peer dependency - do you not get any warnings when installing? I would've thought that peer dependency warnings get bubbled up to the end user no matter how deep the dependency, but have never actually checked

jaybeeuu commented 4 years ago

Hmm.. intuitively that would make sense. It might be a pnpm thing. I'll see what happens in a repro package with yarn & npm.