Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why did mocha suddenly start outputting verbose logs?

We've been running a mocha test suite locally for a few months. Today this test runner started to output super verbose information about every function its executing, including from http libraries like axios. How do i reduce the output to only see console.log and spec output?

mocharc.json

{
    "diff": true,
    "exit": true,
    "reporter": "spec",
    "timeout": 60000,
    "require": ["mocha-steps"]
}

Example output for a single test:

> NODE_PRESERVE_SYMLINKS=1 mocha ---config=test/mocharc.json -r ts-node/register test/**/*.spec.ts "--grep" "ServiceAssignment"
 
  mocha:suite bail undefined +0ms
  mocha:suite enableTimeouts true +1ms
  mocha:suite timeout 60000 +3ms
  mocha:suite bail undefined +0ms
  mocha:suite timeout 60000 +196ms
  mocha:suite retries -1 +0ms
  mocha:suite enableTimeouts true +0ms
  mocha:suite slow 75 +0ms
  mocha:suite bail undefined +0ms
  mocha:suite timeout 60000 +0ms
  mocha:suite retries -1 +0ms
  mocha:suite enableTimeouts true +0ms
  mocha:suite slow 75 +1ms
  mocha:suite bail undefined +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:suite timeout 60000 +69ms
  mocha:suite retries -1 +0ms
  mocha:suite enableTimeouts true +0ms
  mocha:suite slow 75 +0ms
  mocha:suite bail undefined +0ms
  mocha:runnable timeout 60000 +70ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:suite timeout 60000 +14ms
  mocha:suite retries -1 +0ms
  mocha:suite enableTimeouts true +0ms
  mocha:suite slow 75 +0ms
  mocha:suite bail undefined +0ms
  mocha:runnable timeout 60000 +13ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runnable timeout 60000 +0ms
  mocha:runnable enableTimeouts true +0ms
  mocha:runnable slow 75 +0ms
  mocha:runner grep /.*/ +0ms
  mocha:runner globals ["global","clearInterval","clearTimeout","setInterval","setTimeout","queueMicrotask","clearImmediate","setImmediate","step","xstep","before","after","beforeEach","afterEach","run","context","describe","xcontext","xdescribe","specify","it","xspecify","xit","XMLHttpRequest","Date","errno"] +2ms
  mocha:runner grep /ServiceAssignment/ +0ms
  mocha:runner globals [] +0ms
  mocha:runner start +0ms
 
  mocha:runner run suite  +1ms
 
  mocha:runner run suite Sequential +4ms
  mocha:runner run suite Dockerode +0ms
  mocha:runner run suite ServiceAssignment +0ms
  ServiceAssignment
  follow-redirects options {
  protocol: 'http:',
  maxRedirects: 21,
  maxBodyLength: 10485760,
  path: '/networks/',
  method: 'get',
  headers: {
    Accept: 'application/json, text/plain, */*',
    'User-Agent': 'axios/0.18.1'
  },
  agent: undefined,
  auth: undefined,
  hostname: '127.0.0.1',
  port: '4960',
  nativeProtocols: {
    'http:': {
      _connectionListener: [Function: connectionListener],
      METHODS: [Array],
      STATUS_CODES: [Object],
      Agent: [Function],
      ClientRequest: [Function: ClientRequest],
      IncomingMessage: [Function: IncomingMessage],
      OutgoingMessage: [Function: OutgoingMessage],
      Server: [Function: Server],
      ServerResponse: [Function: ServerResponse],
      createServer: [Function: createServer],
      validateHeaderName: [Function: hidden],
      validateHeaderValue: [Function: hidden],
      get: [Function: get],
      request: [Function: request],
      maxHeaderSize: [Getter],
      globalAgent: [Getter/Setter]
    },
    'https:': {
      Agent: [Function: Agent],
      globalAgent: [Agent],
      Server: [Function: Server],
      createServer: [Function: createServer],
      get: [Function: get],
      request: [Function: request]
    }
  }
} +0ms
    ✓ should get the networks from the host
 
  mocha:runner finished running +24ms
 
  1 passing (28ms)
 
  mocha:runner end +0ms
import 'reflect-metadata';
import {expect} from 'chai';
import axios, {AxiosResponse} from "axios";


describe('ServiceAssignment', () => {
    let newServices: ScubaService[] = [];

    before(async () => {
        let count =  5;
        while (newServices.length < count) {
            const index: number = newServices.length;
            let service: ScubaService = ScubaService.factory();
            service.index = index;
            service.type = ServiceTemplateTypes.MODEL_RUNNER;
            service.jobconfig = {
                index: index,
                contentUrl: `https://jsonplaceholder.typicode.com/posts/${index}`,
                imageUrl: `https://picsum.photos/id/${index}/200/300`
            };
            newServices.push(service);
        }
    });

    step('should get the networks from the host', async function () {
        let url: string = `http://127.0.0.1:4960/networks/`;
        let response: AxiosResponse = await axios.get(url);
        const status = response.status
        expect(response.status).to.eq(200);
    });
});
like image 796
Jack Murphy Avatar asked Nov 27 '25 10:11

Jack Murphy


1 Answers

Mocha uses the debug package. In turn, debug uses the DEBUG environment variable.

To enable debug statements in Mocha, we typically use DEBUG=mocha*. Setting DEBUG=* would cause any module using debug to output debug info.

It's likely you (or some program) has set DEBUG=* or has enabled debug statements via code, e.g.,:

// equivalent to `DEBUG=*`
require('debug').enable('*')

To rule out the environment, execute export DEBUG= in your shell, which will unset the environment variable. Otherwise, the problem is in code somewhere.

like image 123
boneskull Avatar answered Nov 29 '25 00:11

boneskull



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!