I created a plain @nrwl/express
project with an empty web server 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 }
Whenever I add one a test file such as something.test.ts
:
const { server } = require('../server');
describe('TEST: /', () => {
it('Should work just fine', async () => {
// all ok
});
});
export {};
Then ng serve express
starts complaining because it tries to process the test files:
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.
What is the correct way to solve this? I don't necessarily want to add test libraries as a runtime dependency because test files shouldn't be bundled in the build IMO.
I figured it out after a couple of days (face-palm)
I needed to edit tsconfig.app.json
and needed to add "**/*.test.ts"
in the exclude option:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": ["node"]
},
"exclude": ["**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
Everything is working fine now, warning messages are gone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With