2017-12-04 4 views
0

私はNode.js TypeScriptコードをテストするためにMocha(およびChai)を使用しようとしています。WebStormのMocha実行コンフィギュレーションでエラーが発生しました。コマンドラインに

は、私はWebStormのモカ実行構成を使用する場合には、次のコマンドを実行し、私はそれが正常に動作し、コマンドラインからまったく同じコマンドを実行する場合は、エラーに

/usr/local/bin/node /Users/george.pai/Workspace/fd/fd-lambdas/node_modules/mocha/bin/_mocha --require ts-node/register --ui bdd --reporter "/Users/george.pai/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/173.3727.108/WebStorm.app/Contents/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js" /Users/george.pai/Workspace/fd/fd-lambdas/src/test/slack.handler.spec.ts --grep "slack\.handler " 

をスローします。ここで

私の実行構成(プライバシーのために難読化され、いくつかのディレクトリ名) Mocha Run Config

"dependencies": { 
    "aws-lambda": "0.1.2", 
    "json2csv": "^3.11.5", 
    "request": "^2.83.0", 
    "request-promise-native": "^1.0.5", 
    "uuid": "^3.1.0" 
    }, 
    "devDependencies": { 
    "@types/aws-lambda": "0.0.19", 
    "@types/chai": "^4.0.7", 
    "@types/mocha": "^2.2.44", 
    "@types/node": "^8.0.53", 
    "@types/request": "^2.0.8", 
    "@types/request-promise-native": "^1.0.10", 
    "@types/uuid": "^3.4.3", 
    "chai": "^4.1.2", 
    "mocha": "^4.0.1", 
    "mocha-typescript": "^1.1.12", 
    "serverless-offline": "^3.16.0", 
    "serverless-webpack": "^3.0.0", 
    "ts-loader": "^2.3.7", 
    "ts-node": "^3.3.0", 
    "tslint": "^5.8.0", 
    "tslint-config-standard": "^7.0.0", 
    "typescript": "^2.5.2", 
    "webpack": "^3.6.0" 
    } 

マイpackage.jsonの依存マイtsconfig.json

{ 
    "compilerOptions": { 
    "module": "commonjs", 
    "target": "es6", 
    "lib": [ 
     "es6", 
     "dom" 
    ], 
    "moduleResolution": "node", 
    "rootDir": "./src", 
    "sourceMap": true, 
    "inlineSources": true, 
    "allowJs": true, 
    "noImplicitAny": true, 
    "noUnusedLocals": true, 
    "noImplicitThis": true, 
    "strictNullChecks": true, 
    "noImplicitReturns": true, 
    "preserveConstEnums": true, 
    "suppressImplicitAnyIndexErrors": true, 
    "forceConsistentCasingInFileNames": true 
    }, 
    "exclude": [ 
    "node_modules", 
    "build", 
    "webpack" 
    ], 
    "types": [ 
    "aws-sdk", 
    "chai", 
    "mocha", 
    "node", 
    "request", 
    "request-promise-native", 
    "typePatches", 
    "uuid" 
    ] 
} 

はこちらですエラーの完全な出力

/usr/local/bin/node /Users/george.pai/Workspace/fd/fd-lambdas/node_modules/mocha/bin/_mocha --require ts-node/register --ui bdd --reporter "/Users/george.pai/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/173.3727.108/WebStorm.app/Contents/plugins/NodeJS/js/mocha-intellij/lib/mochaIntellijReporter.js" /Users/george.pai/Workspace/fd/fd-lambdas/src/test/slack.handler.spec.ts --grep "slack\.handler " 

/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:307 
     throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset)) 
      ^
TSError: ⨯ Unable to compile TypeScript 
fd-lambdas/src/main/node/slack/slack.handler.ts (57,18): 'Promise' only refers to a type, but is being used as a value here. (2693) 
fd-lambdas/src/main/node/slack/slack.handler.ts (69,12): 'Promise' only refers to a type, but is being used as a value here. (2693) 
fd-lambdas/src/main/node/slack/slack.handler.ts (199,14): 'Promise' only refers to a type, but is being used as a value here. (2693) 
fd-lambdas/src/main/node/slack/slack.handler.ts (202,14): 'Promise' only refers to a type, but is being used as a value here. (2693) 
fd-lambdas/src/main/node/slack/slack.handler.ts (230,16): 'Promise' only refers to a type, but is being used as a value here. (2693) 
    at getOutput (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:307:15) 
    at /Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:336:16 
    at Object.compile (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:498:11) 
    at Module.m._compile (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:392:43) 
    at Module._extensions..js (module.js:623:10) 
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:395:12) 
    at Module.load (module.js:531:32) 
    at tryModuleLoad (module.js:494:12) 
    at Function.Module._load (module.js:486:3) 
    at Module.require (module.js:556:17) 
    at require (internal/module.js:11:18) 
    at Object.<anonymous> (/Users/george.pai/Workspace/fd/fd-lambdas/src/test/slack.handler.spec.ts:4:1) 
    at Module._compile (module.js:612:30) 
    at Module.m._compile (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:392:23) 
    at Module._extensions..js (module.js:623:10) 
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/ts-node/src/index.ts:395:12) 
    at Module.load (module.js:531:32) 
    at tryModuleLoad (module.js:494:12) 
    at Function.Module._load (module.js:486:3) 
    at Module.require (module.js:556:17) 
    at require (internal/module.js:11:18) 
    at /Users/george.pai/Workspace/fd/fd-lambdas/node_modules/mocha/lib/mocha.js:231:27 
    at Array.forEach (<anonymous>) 
    at Mocha.loadFiles (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/mocha/lib/mocha.js:228:14) 
    at Mocha.run (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/mocha/lib/mocha.js:514:10) 
    at Object.<anonymous> (/Users/george.pai/Workspace/fd/fd-lambdas/node_modules/mocha/bin/_mocha:484:18) 
    at Module._compile (module.js:612:30) 
    at Object.Module._extensions..js (module.js:623:10) 
    at Module.load (module.js:531:32) 
    at tryModuleLoad (module.js:494:12) 
    at Function.Module._load (module.js:486:3) 
    at Function.Module.runMain (module.js:653:10) 
    at startup (bootstrap_node.js:187:16) 
    at bootstrap_node.js:608:3 

Process finished with exit code 1 
+0

エラーはtsnodeから発生します。あなたのtsconfig.jsonを使用しない理由はわかりませんが、IDEの問題のようには見えません – lena

答えて

0

難読化はおそらく解決策を見つけるのを妨げています。 Mocha Run Configurationの作業ディレクトリ/Users/george.pai/Workspace/fdは、プロジェクトのルートですが、ノードプロジェクトのルートはありませんでした。/Users/george.pai/Workspace/fd/fd-lambdas

作業ディレクトリを適切なディレクトリに変更すると、これが解決されました。私の端末はすでに適切なディレクトリ/Users/george.pai/Workspace/fd/fd-lambdasに入っていたので、それはうまくいきました。

関連する問題