bikk-uk / jest-mock-express

A lightweight Jest mock for unit testing Express
MIT License
49 stars 7 forks source link

type errors in v2.0.0 #80

Closed leoschweizer closed 2 years ago

leoschweizer commented 2 years ago

The following minimal setup does not build without type errors for me.

index.ts

import { getMockReq, getMockRes } from '@jest-mock/express'

getMockReq()

tsconfig.json

{
    "compilerOptions": {
      "allowSyntheticDefaultImports": true,
      "lib": ["es2021"],
      "module": "es2020",
      "moduleResolution": "node",
      "target": "es2021"
    }
}

package.json

{
  "name": "foo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "tsc": "tsc -p ."
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@jest-mock/express": "^1.4.5",
    "@types/express": "^4.17.13",
    "@types/jest": "^28.1.4",
    "jest": "^28.1.2",
    "typescript": "^4.7.4"
  },
  "dependencies": {}
}

results in:

node_modules/@jest-mock/express/dist/src/request/index.d.ts:7:40 - error TS2307: Cannot find module 'src' or its corresponding type declarations.

7 import type { EventEventEmitter } from 'src';
                                         ~~~~~

node_modules/@jest-mock/express/dist/src/request/request.d.ts:6:117 - error TS2304: Cannot find name 'ParsedQs'.

6 export declare const getMockReq: <T extends Request<import("express-serve-static-core").ParamsDictionary, any, any, ParsedQs, Record<string, any>>>(values?: MockRequest) => T;
                                                                                                                      ~~~~~~~~

node_modules/@jest-mock/express/dist/src/response/index.d.ts:7:40 - error TS2307: Cannot find module 'src' or its corresponding type declarations.

7 import type { EventEventEmitter } from 'src';
                                         ~~~~~

Found 3 errors in 3 files.

Errors  Files
     1  node_modules/@jest-mock/express/dist/src/request/index.d.ts:7
     1  node_modules/@jest-mock/express/dist/src/request/request.d.ts:6
     1  node_modules/@jest-mock/express/dist/src/response/index.d.ts:7

Not sure what I'm missing here but the pathes to 'src' really seem off?

The problem does not occur with v1.4.5

theBrianCui commented 2 years ago

+1, I am experiencing this exact error as well on "typescript": "^4.7.4" after updating to v2.0.0.

aboyce commented 2 years ago

Hello @leoschweizer,

Apologies about this, thank you for providing some example files to replicate the issue, very helpful 😃

I believe this is now resolved and published as v2.0.1. I have tested it with your example that I was using to replicate the problem and tested it in a sandbox. I'm not sure how TypeScript is successfully generating invalid files so I'll add that as something to look into to avoid this in the future.

Please open another issue if you continue to have issues.

Thanks 😃