Mocha根据已删除的规范运行测试

时间:2019-02-21 12:23:38

标签: node.js mocha ts-node

我正在在Visual Studio Code的节点项目上使用mocha运行测试。在一些重构过程中,我将测试规范之一从basic-heating-rule-spec.ts重命名为rule-config-spec.ts

重构的测试失败了,没什么大不了的,但是错误似乎表明现在删除的basic-heating-rule-spec.ts仍在运行:

  49 passing (98ms)
  1 failing

  1) RuleConfig
       should load with valid data:
     Error: Config validation, cannot find timeOfDayConfig:hour and no default value supplied
      at getValue (src\config-validation.ts:52:15)
      at Function.getNumber (src\config-validation.ts:13:16)
      at new TimeOfDay (src\configuration\time-of-day.ts:32:53)
      at new RuleConfig (src\configuration\rule-config.ts:38:28)
      at Context.it (test\configuration\rule\basic-heating-rule-spec.ts:12:29)

似乎旧规范正在缓存在某个地方。我尝试重新启动VSCode并重新启动计算机,但是不存在的测试文件继续运行。有谁知道文件在哪里缓存以及如何清除它?

我使用npm run test执行测试,并且package.json包含以下内容:

"scripts": {
    "clean": "rimraf lib",
    "lint": "tslint --force --format verbose \"src/**/*.ts\"",
    "build": "npm run clean && npm run lint && echo Using TypeScript && tsc --version && tsc --pretty",
    "test": "npm run build && mocha --require ts-node/register --recursive \"test/**/*-spec.ts\""
},

我的tsconfig.json看起来像这样:

{
    "compilerOptions": {
        "target": "es6",
        "lib": ["es6"],
        "module": "commonjs",
        "moduleResolution": "node",
        "noImplicitAny": true,
        "removeComments": true,
        "outDir": "./lib",
        "rootDir": ".",
        "preserveConstEnums": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "declaration": true
    },
    "include": ["index.ts", "src/**/*.ts", "test/**/*-spec.ts"],
}

甚至更奇怪:重构的rule-config-spec.ts包含describe("RuleConfig"() =>...),它显示在上面的消息中。如果我将其更改为describe("RuleXXXConfig"() =>...),那么我将得到一个引用正确文件的错误:

  49 passing (130ms)
  1 failing

  1) RuleXXXConfig
       should load with valid data:
     Error: Config validation, cannot find timeOfDayConfig:hour and no default value supplied
      at getValue (src\config-validation.ts:52:15)
      at Function.getNumber (src\config-validation.ts:13:16)
      at new TimeOfDay (src\configuration\time-of-day.ts:32:53)
      at new RuleConfig (src\configuration\rule-config.ts:38:28)
      at Context.it (test\configuration\rule\rule-config-spec.ts:12:29)

如果我将其更改回describe("RuleConfig"() =>...),则会收到旧消息,该消息再次引用了不存在的测试文件:

  49 passing (102ms)
  1 failing

  1) RuleConfig
       should load with valid data:
     Error: Config validation, cannot find timeOfDayConfig:hour and no default value supplied
      at getValue (src\config-validation.ts:52:15)
      at Function.getNumber (src\config-validation.ts:13:16)
      at new TimeOfDay (src\configuration\time-of-day.ts:32:53)
      at new RuleConfig (src\configuration\rule-config.ts:38:28)
      at Context.it (test\configuration\rule\basic-heating-rule-spec.ts:12:29)

到现在为止,我已经完全处于真正的深度:有人知道WTF正在这里吗?

1 个答案:

答案 0 :(得分:0)

是否已尝试删除节点模块文件夹,然后运行npm install。另外,请尝试使用终端而不是VS代码集成终端。