jest-runner-tsc
jest-runner-tsc copied to clipboard
lib.d.ts not detected?
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
> [email protected] 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.
The include probably isn't being respected. If you add a /// <reference path="../lib.d.ts" /> does it work?
@azz Where exactly should I put that?
At the top of src/server.ts (just temporarily to diagnose)
Ok I'll try that, should have some time later today.
@azz confirmed that works!
Cool, confirms my suspicion. I'll try and fix it soon, but good that the workaround works :smile:.
@azz Hey, just seeing if this has been fixed. Using the workaround (reference path) for now.
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 :(
I solved this problem by adding typeRoots
"compilerOptions": {
...
"typeRoots": ["./src/@types", "./node_modules/@types"]
}
@azz When this issue is fixed?
@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

Any plans on fixing this issue?