kulshekhar / ts-jest

A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
https://kulshekhar.github.io/ts-jest
MIT License
6.97k stars 453 forks source link

failed to load type definition #464

Closed joey-he8x closed 6 years ago

joey-he8x commented 6 years ago

run with jest, got error :Cannot find module 'web3/types' from 'main.ts'

● Test suite failed to run

    Cannot find module 'web3/types' from 'main.ts'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (src/main.ts:20:17)

if i remove decorator from main.ts, then no errors.

if i add 'd.ts' into moduleFileExtensions,

● Test suite failed to run

    /Users/moge/Workspace/exercise/ts-jest-issue/node_modules/ts-jest/dist/install.d.ts:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export declare function install(filePath: string, fileContent: string): any;
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316:17)

checkout https://github.com/joey-he8x/ts-jest-issue npm run test

GeeWee commented 6 years ago

Please provide a debug log.

joey-he8x commented 6 years ago

do u mean adding --debug?

{
  "configs": [
    {
      "automock": false,
      "browser": false,
      "cache": true,
      "cacheDirectory": "/var/folders/p5/75zf43bs7t7fm06y4nbcgpnh0000gq/T/jest_dz",
      "clearMocks": false,
      "coveragePathIgnorePatterns": [
        "/node_modules/"
      ],
      "detectLeaks": false,
      "forceCoverageMatch": [],
      "globals": {
        "ts-jest": {
          "tsConfigFile": "tsconfig.json"
        }
      },
      "haste": {
        "providesModuleNodeModules": []
      },
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleFileExtensions": [
        "ts",
        "js",
        "node",
        "json"
      ],
      "moduleNameMapper": {},
      "modulePathIgnorePatterns": [],
      "name": "71a650be7f2368588dd22dc01c974b15",
      "resetMocks": false,
      "resetModules": false,
      "restoreMocks": false,
      "rootDir": "/Users/moge/ts-jest-issue",
      "roots": [
        "/Users/ts-jest-issue"
      ],
      "runner": "jest-runner",
      "setupFiles": [],
      "snapshotSerializers": [],
      "testEnvironment": "/Users/moge/ts-jest-issue/node_modules/jest-environment-node/build/index.js",
      "testEnvironmentOptions": {},
      "testLocationInResults": false,
      "testMatch": [
        "**/test/**/*.test.(ts|js)"
      ],
      "testPathIgnorePatterns": [
        "/node_modules/"
      ],
      "testRegex": "",
      "testRunner": "/Users/moge/ts-jest-issue/node_modules/jest-jasmine2/build/index.js",
      "testURL": "about:blank",
      "timers": "real",
      "transform": [
        [
          "^.+\\.(ts|tsx)$",
          "/Users/moge/ts-jest-issue/node_modules/ts-jest/preprocessor.js"
        ]
      ],
      "transformIgnorePatterns": [
        "/node_modules/"
      ],
      "watchPathIgnorePatterns": []
    }
  ],
  "globalConfig": {
    "bail": false,
    "changedFilesWithAncestor": false,
    "coverageDirectory": "/Users/moge/ts-jest-issue/coverage",
    "coverageReporters": [
      "json",
      "text",
      "lcov",
      "clover"
    ],
    "detectLeaks": false,
    "expand": false,
    "globalSetup": null,
    "globalTeardown": null,
    "listTests": false,
    "maxWorkers": 3,
    "noStackTrace": false,
    "nonFlagArgs": [],
    "notify": false,
    "notifyMode": "always",
    "passWithNoTests": false,
    "rootDir": "/Users/moge/ts-jest-issue",
    "runTestsByPath": false,
    "testFailureExitCode": 1,
    "testPathPattern": "",
    "testResultsProcessor": null,
    "updateSnapshot": "new",
    "useStderr": false,
    "verbose": null,
    "watch": false,
    "watchman": true
  },
  "version": "22.4.2"
}
 FAIL  test/main.test.ts
  ● Test suite failed to run

    Cannot find module 'web3/types' from 'main.ts'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (src/main.ts:20:17)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.694s
Ran all test suites.
kulshekhar commented 6 years ago

@joey-he8x removing "emitDecoratorMetadata": true, from tsconfig fixes this. Does that work for you?

joey-he8x commented 6 years ago

but i use inversify.js which requires emitDecoratorMetadata to be true.

kulshekhar commented 6 years ago

You can extends tsconfig, override this field and use that tsconfig for testing

kulshekhar commented 6 years ago

@joey-he8x does extending tsconfig work for you?

pyoner commented 6 years ago

Hi, same error! Here my repo https://github.com/pyoner/vue-firebase-plugin Output log

➜  vue-firebase-plugin git:(master) npm run test

> vue-firebase-plugin@0.0.0-development test /home/jungle/repo/vue-firebase-plugin
> jest --debug

{
  "configs": [
    {
      "automock": false,
      "browser": false,
      "cache": true,
      "cacheDirectory": "/tmp/jungle/jest_rs",
      "clearMocks": false,
      "coveragePathIgnorePatterns": [
        "/node_modules/",
        "/test/"
      ],
      "detectLeaks": false,
      "forceCoverageMatch": [],
      "globals": {
        "ts-jest": {
          "tsConfigFile": "tsconfig.jest.json"
        }
      },
      "haste": {
        "providesModuleNodeModules": []
      },
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
      ],
      "moduleNameMapper": {},
      "modulePathIgnorePatterns": [],
      "name": "1783d1d0b16c3cb9fb9c25becff38ac8",
      "resetMocks": false,
      "resetModules": false,
      "restoreMocks": false,
      "rootDir": "/home/jungle/repo/vue-firebase-plugin",
      "roots": [
        "/home/jungle/repo/vue-firebase-plugin"
      ],
      "runner": "jest-runner",
      "setupFiles": [],
      "snapshotSerializers": [],
      "testEnvironment": "jest-environment-jsdom",
      "testEnvironmentOptions": {},
      "testLocationInResults": false,
      "testMatch": [],
      "testPathIgnorePatterns": [
        "/node_modules/"
      ],
      "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
      "testRunner": "/home/jungle/repo/vue-firebase-plugin/node_modules/jest/node_modules/jest-jasmine2/build/index.js",
      "testURL": "about:blank",
      "timers": "real",
      "transform": [
        [
          "^.+\\.tsx?$",
          "/home/jungle/repo/vue-firebase-plugin/node_modules/ts-jest/index.js"
        ]
      ],
      "transformIgnorePatterns": [
        "/node_modules/"
      ],
      "watchPathIgnorePatterns": []
    }
  ],
  "globalConfig": {
    "bail": false,
    "changedFilesWithAncestor": false,
    "collectCoverage": true,
    "coverageDirectory": "/home/jungle/repo/vue-firebase-plugin/coverage",
    "coverageReporters": [
      "json",
      "text",
      "lcov",
      "clover"
    ],
    "coverageThreshold": {
      "global": {
        "branches": 90,
        "functions": 95,
        "lines": 95,
        "statements": 95
      }
    },
    "detectLeaks": false,
    "expand": false,
    "globalSetup": null,
    "globalTeardown": null,
    "listTests": false,
    "maxWorkers": 3,
    "noStackTrace": false,
    "nonFlagArgs": [],
    "notify": false,
    "notifyMode": "always",
    "passWithNoTests": false,
    "rootDir": "/home/jungle/repo/vue-firebase-plugin",
    "runTestsByPath": false,
    "testFailureExitCode": 1,
    "testPathPattern": "",
    "testResultsProcessor": null,
    "updateSnapshot": "new",
    "useStderr": false,
    "verbose": null,
    "watch": false,
    "watchman": true
  },
  "version": "22.4.2"
}
 FAIL  test/vue-firebase-plugin.test.ts
  ● Test suite failed to run

    Cannot find module '@firebase/firestore-types' from 'Firestore.ts'

      17 |   StartEnd,
      18 |   CreateRef
    > 19 | } from '../utils'
      20 | 
      21 | interface Inner {
      22 |   unsubscribe?: () => void

      at Resolver.resolveModule (node_modules/jest/node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (src/components/Firestore.ts:19:49)

 FAIL  test/Firestore.test.ts
  ● Test suite failed to run

    Cannot find module '@firebase/firestore-types' from 'Firestore.ts'

      17 |   StartEnd,
      18 |   CreateRef
    > 19 | } from '../utils'
      20 | 
      21 | interface Inner {
      22 |   unsubscribe?: () => void

      at Resolver.resolveModule (node_modules/jest/node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (src/components/Firestore.ts:19:49)

 FAIL  test/utils.test.ts
  ● Test suite failed to run

    Cannot find module '@firebase/firestore-types' from 'utils.ts'

      88 |     return value.toDate()
      89 |   }
    > 90 | 
      91 |   if (value instanceof GeoPoint) {
      92 |     return {
      93 |       latitude: value.latitude,

      at Resolver.resolveModule (node_modules/jest/node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (src/utils.ts:90:284)

----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|
Jest: Coverage data for global was not found.
Test Suites: 3 failed, 3 total
Tests:       0 total
Snapshots:   0 total
Time:        4.429s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! vue-firebase-plugin@0.0.0-development test: `jest --debug`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the vue-firebase-plugin@0.0.0-development test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jungle/.npm/_logs/2018-05-22T09_52_22_848Z-debug.log
GeeWee commented 6 years ago

Please open a new issue and link to the old one :)