为什么 mocha 突然开始输出冗长的日志?

Why did mocha suddenly start outputting verbose logs?

我们已经 运行 本地摩卡测试套件几个月了。今天,这个测试运行器开始输出有关其执行的每个函数的超级详细信息,包括来自 axios 等 http 库的信息。如何将输出减少到只看到 console.log 和规范输出?

mocharc.json

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

单个测试的示例输出:

> 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);
    });
});

Mocha 使用 debug 包。反过来,debug 使用 DEBUG 环境变量。

要在 Mocha 中启用调试语句,我们通常使用 DEBUG=mocha*。设置 DEBUG=* 会导致 使用 debug 的任何 模块输出调试信息。

您(或某些程序)可能已设置 DEBUG=* 已通过代码启用调试语句,例如:

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

要排除环境,请在 shell 中执行 export DEBUG=,这将取消设置环境变量。否则,问题出在某处代码中。