deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

Fix jest config in documentation for Testing

Open jpv-os opened this issue 3 years ago • 1 comments

Hello,

I have been giving the framework a try and like it very much so far. However, at least for me, the provided example for testing did not work. I figured I might open an issue to either get the example fixed on the website, or to find out if I did something wrong.

This is the documentation page I am refering to: https://deepkit.io/documentation/framework/testing

I had to make two adjustments to my package.json, compared to the documentation.

First, I had to set "resolver": "./node_modules/@deepkit/framework/resolve" in the jest config section. For some reason, my environment didn't pick up the package name without the ./node_modules/ prefix.

Second, I had to add the globals section in the jest config section to make jest use my tsconfig.json file to enable compiling with reflection. I implemented some very basic unit tests where I was playing around with the valuesOf<...>() function and couldn't get it to work. However, in my main app it worked, so it had to be a jest issue. After some experimenting, I found that ts-jest didn't pick up my config file (taken directly from the documentation website, no further modifications).

This is how my package.json ended up looking:

{
  "name": "deepkit-test",
  "scripts": {
    "postinstall": "deepkit-type-install",
    "test": "jest --coverage --coverageProvider=v8"
  },
  "dependencies": {
    "@deepkit/framework": "1.0.1-alpha.71",
    "@deepkit/orm": "1.0.1-alpha.71",
    "@deepkit/sqlite": "1.0.1-alpha.71",
    "@deepkit/type": "1.0.1-alpha.71",
    "@deepkit/type-compiler": "1.0.1-alpha.71",
    "rxjs": "6.6.7"
  },
  "devDependencies": {
    "@types/jest": "^28.1.4",
    "jest": "^28.1.2",
    "ts-jest": "^28.0.5",
    "ts-node": "^10.8.1"
  },
  "jest": {
    "transform": {
      "^.+\\.(ts|tsx)$": "ts-jest"
    },
    "testEnvironment": "node",
    "resolver": "./node_modules/@deepkit/framework/resolve",
    "testMatch": [
      "**/*.spec.ts"
    ],
    "globals": {
      "ts-jest": {
        "tsconfig": "tsconfig.json"
      }
    }
  }
}

Thanks for providing this awesome framework, best regards.

jpv-os avatar Jul 05 '22 19:07 jpv-os

@jpv-os "resolver": "./node_modules/@deepkit/framework/resolve" is not required.

marcus-sa avatar Jul 08 '22 07:07 marcus-sa