ada*_*ily 4 node.js express typescript nrwl-nx
我创建了一个@nrwl/express带有空 Web 服务器的普通项目server.ts:
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.json({status: 'OK'})
});
var server = app.listen(3000);
module.exports = { server }
Run Code Online (Sandbox Code Playgroud)
每当我添加一个测试文件时,例如something.test.ts:
const { server } = require('../server');
describe('TEST: /', () => {
it('Should work just fine', async () => {
// all ok
});
});
export {};
Run Code Online (Sandbox Code Playgroud)
然后ng serve express开始抱怨,因为它尝试处理测试文件:
TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner?
Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types
field in your tsconfig.
Run Code Online (Sandbox Code Playgroud)
解决这个问题的正确方法是什么?我不一定想添加测试库作为运行时依赖项,因为测试文件不应该捆绑在构建 IMO 中。
几天后我想通了(捂脸)
我需要编辑tsconfig.app.json并需要添加"**/*.test.ts"排除选项:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": ["node"]
},
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
Run Code Online (Sandbox Code Playgroud)
现在一切正常,警告消息消失了。
| 归档时间: |
|
| 查看次数: |
1929 次 |
| 最近记录: |