azz / jest-runner-tsc

🃏A Jest runner for the TypeScript compiler
MIT License
178 stars 12 forks source link

lib.d.ts not detected? #4

Open jasonkuhrt opened 6 years ago

jasonkuhrt commented 6 years ago

Project ok:

❯ npx tsc --noemit
❯ cat tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "noImplicitReturns": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "target": "es2017",
    "sourceMap": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "lib": ["esnext"]
  },
  "include": ["src/**/*.ts", "lib.d.ts"]
}
❯ cat lib.d.ts
declare module 'serverless-http'

But not when checked from within jest runner:

❯ cat jest.config.js
module.exports = {
  projects: [
    {
      transform: {
        '^.+\\.ts$': 'ts-jest',
      },
      testRegex: '.*spec.ts$',
      moduleFileExtensions: ['ts', 'js'],
      collectCoverageFrom: ['**/src/**/*.ts', '!**/build/**/*'],
    },
    {
      runner: 'jest-runner-tsc',
      displayName: 'tsc',
      moduleFileExtensions: ['ts', 'tsx'],
      testMatch: ['<rootDir>/**/*.ts'],
    },
  ],
}

❯ npm test

> orwell@0.1.0 test /Users/jasonkuhrt/projects/dialogue/orwell
> jest src plugins

 PASS   tsc  src/poetry.ts
 PASS   tsc  plugins/scribe.ts
 PASS   tsc  plugins/intercom.ts
 PASS   tsc  plugins/hollywood.ts (6.419s)
 FAIL   tsc  src/server.ts (8.77s)
Could not find a declaration file for module 'serverless-http'. '/Users/jasonkuhrt/projects/dialogue/orwell/node_modules/serverless-http/serverless-http.js' implicitly has an 'any' type.
  Try `npm install @types/serverless-http` if it exists or add a new declaration (.d.ts) file containing `declare module 'serverless-http';`
  3 | import express from 'express'
  4 | import QS from 'querystring'
> 5 | import serverless from 'serverless-http'
    |                        ^^^^^^^^^^^^^^^^^
  6 | import * as Plug from '../plugins'
  7 | import * as Config from './config'
  8 | import * as H from './helpers'
 PASS   tsc  src/config.ts (5.957s)
 PASS   tsc  src/helpers.spec.ts
 PASS   tsc  plugins/datadog.ts
 PASS   tsc  src/helpers.ts
 PASS   tsc  plugins/waldo.ts
 PASS   tsc  plugins/toktok.ts (5.651s)
 PASS   tsc  plugins/core.ts
 PASS   tsc  plugins/index.ts
 PASS  src/helpers.spec.ts

Test Suites: 1 failed, 13 passed, 14 total
Tests:       1 failed, 13 passed, 14 total
Snapshots:   0 total
Time:        19.859s
Ran all test suites matching /src|plugins/i in 2 projects.
npm ERR! Test failed.  See above for more details.
azz commented 6 years ago

The include probably isn't being respected. If you add a /// <reference path="../lib.d.ts" /> does it work?

jasonkuhrt commented 6 years ago

@azz Where exactly should I put that?

azz commented 6 years ago

At the top of src/server.ts (just temporarily to diagnose)

jasonkuhrt commented 6 years ago

Ok I'll try that, should have some time later today.

jasonkuhrt commented 6 years ago

@azz confirmed that works!

azz commented 6 years ago

Cool, confirms my suspicion. I'll try and fix it soon, but good that the workaround works :smile:.

philkeys commented 5 years ago

@azz Hey, just seeing if this has been fixed. Using the workaround (reference path) for now.

YBogomolov commented 5 years ago

Any plans on fixing this issue? As Jest had been updated to 24.x, ts-jest no longer can be used with it, and the documentation suggest using jest-runner-tsc. However, due to this issue I cannot use it either :(

sandiiarov commented 5 years ago

I solved this problem by adding typeRoots

"compilerOptions": {
  ...
  "typeRoots": ["./src/@types", "./node_modules/@types"]
}
ease-space commented 3 years ago

@azz When this issue is fixed?

ease-space commented 3 years ago

@azz I found a solution, you need to add in tsconfig.ts gain on custom types and be sure to add a subfolder. This solution worked

Снимок экрана 2021-06-26 в 17 17 06 Снимок экрана 2021-06-26 в 17 17 14 Снимок экрана 2021-06-26 в 17 17 20
Mifrill commented 2 years ago

Any plans on fixing this issue?