0

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

重构的测试失败了,没什么大不了的,但错误似乎表明 now deletedbasic-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在这里发生吗?

4

1 回答 1

0

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

于 2019-02-21T17:19:13.407 回答