【发布时间】:2020-11-28 04:39:04
【问题描述】:
我创建了一个普通的 @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 }
每当我添加一个测试文件时,例如something.test.ts:
const { server } = require('../server');
describe('TEST: /', () => {
it('Should work just fine', async () => {
// all ok
});
});
export {};
然后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.
解决这个问题的正确方法是什么?我不一定想将测试库添加为运行时依赖项,因为不应将测试文件捆绑在构建 IMO 中。
【问题讨论】:
-
它们不会捆绑在构建中。您是否尝试过它所说的并安装了类型?这些只是让 typescript 知道它们是什么的 d.ts 文件。
-
我尝试按照上面的建议执行
npm i @types/jest,但验证了tsconfig的types字段中已经存在“jest”。考虑到 Jest 自动出现在 Nrwl NX 中,我认为应该有更好的方法来做到这一点。我不想相信他们会忘记添加这个重要的依赖项。
标签: node.js typescript express nrwl-nx