Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NRWL NX - Why do I get "Cannot find name 'describe'" when running "ng serve express"?

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.

like image 300
adamsfamily Avatar asked Sep 20 '25 00:09

adamsfamily


1 Answers

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.

like image 74
adamsfamily Avatar answered Sep 21 '25 13:09

adamsfamily