0
对于我的nodejs模块,我使用Mocha和Chai编写了几个单元测试。他们在MacOS运行良好,但未能在Windows上编译,这个编译器错误:摩卡无法在Windows上编译Typescript代码
D:\projects\antlr4-graps>npm test
> [email protected] test D:\projects\antlr4-graps
> mocha --compilers ts:ts-node/register,tsx:ts-node/register
D:\projects\antlr4-graps\node_modules\ts-node\src\index.ts:312
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset))
^
TSError: ⨯ Unable to compile TypeScript
test\test.ts (17,1): Cannot find name 'describe'. (2304)
失败编译的代码是:
describe('antlr4-graps', function() {
这是完全有效的代码(the full version of that file is on Github)。我仔细检查了mocha和chai是否安装为本地节点模块,包括它们的TS等价物(@ type/chai和@ type/mocha)。
我该如何解决编译问题?
非常好。这是缺少的一块(正如所说的,它没有在macOS上导入)。有趣的是,mocha在一次调用中运行两次我的测试。但也许这是它目前报告的错误的结果。总之,与macOS相比,这种行为有很大不同,但差异应该可以解决。谢谢。 –
我刚刚看到测试现在在vscode中运行正常,只从命令行运行它们会给我带来错误。可能是由于不同的TSC版本(我在该盒子上安装了VS 2013和VS 2015)。 –