0

我一直按照此处的说明使用 WebStorm 安装 Mocha:https ://www.jetbrains.com/help/webstorm/2017.1/testing-javascript-with-mocha.html#d194239e92

我已将配置设置为运行与模式匹配的文件:**/*.spec.js

node interpreter: /usr/bin/node
working directory:/home/web/app
mocha package:/home/web/app/node_modules/mocha

我正在使用转换为 ES6 的 TypeScript 编写,其输出是我正在尝试测试的内容。但是,我收到了这个我不明白的错误,所以我真的不知道从哪里开始寻找解决方案。

我不明白它为什么要寻找“ts-node”,因为它只应该寻找“spec.js”文件。除此之外,我不明白为什么它在 ts-node 中寻找的文件夹丢失了。我已经卸载然后重新安装了 ts-node 几次,但都没有产生受追捧的文件夹......我不知道如何继续,甚至不知道需要什么进一步的信息来帮助解决这个问题。

任何帮助,将不胜感激。我只是想测试我的应用程序,事实证明这是一个真正令人头疼的问题。

这是错误:

/usr/bin/node /home/web/app/node_modules/mocha/bin/_mocha --ui bdd --reporter /opt/webstorm/ws/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js * */*.spec.js TypeError: 指定路径不存在:/home/web/app/node_modules/ts-node/tests at resolveSync (/home/web/app/node_modules/ts-node/node_modules/tsconfig/ src/tsconfig.ts:72:9) 在 Object.loadSync (/home/web/app/node_modules/ts-node/node_modules/tsconfig/src/tsconfig.ts:140:16) 在 readConfig (/home/web/ app/node_modules/ts-node/src/index.ts:418:18) 在套件的 Object.register (/home/web/app/node_modules/ts-node/src/index.ts:176:18)。(/home/web/app/node_modules/ts-node/src/index.spec.ts:190:5) 在 Object.create (/home/web/app/node_modules/mocha/lib/interfaces/common.js: 114:19) 在 context.describe.context。套件中的上下文(/home/web/app/node_modules/mocha/lib/interfaces/bdd.js:44:27)。(/home/web/app/node_modules/ts-node/src/index.spec.ts:189:3) 在 Object.create (/home/web/app/node_modules/mocha/lib/interfaces/common.js: 114:19) 在 context.describe.context.context (/home/web/app/node_modules/mocha/lib/interfaces/bdd.js:44:27) 在 Object. (/home/web/app/node_modules/ts-node/src/index.spec.ts:13:1) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module .js:579:10) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.require (module.js:497:17) at require (internal/module.js:20:19) at /home/web/app/node_modules/mocha/lib/mocha.js:230:27 at Array.forEach (native)在摩卡。加载文件 (/home/web/app/node_modules/mocha/lib/mocha.js:227:14) 在 Mocha.run (/home/web/app/node_modules/mocha/lib/mocha.js:495:10) 在目的。(/home/web/app/node_modules/mocha/bin/_mocha:460:18) 在 Module._compile (module.js:570:32) 在 Object.Module._extensions..js (module.js:579:10 ) 在 Module.load (module.js:487:32) 在 tryModuleLoad (module.js:446:12) 在 Function.Module._load (module.js:438:3) 在 Module.runMain (module.js:604 :10) 在运行时 (bootstrap_node.js:390:7) 在启动时 (bootstrap_node.js:150:9) 在 bootstrap_node.js:505:3

进程以退出代码 1 结束

4

1 回答 1

0

我想通了,我的路径来自我的项目的根目录,其中包含 node_modules,因此正在测试 node_modules 目录,导致 ts-node 文件夹内的测试出错。修复是从测试模块的指定路径中排除 node_modules 目录。

于 2017-05-15T03:42:52.343 回答