node.js 伊斯坦布尔和茉莉花设置

Posted

技术标签:

【中文标题】node.js 伊斯坦布尔和茉莉花设置【英文标题】:node.js istanbul and jasmine setup 【发布时间】:2016-02-17 21:25:29 【问题描述】:

我无法让伊斯坦布尔与茉莉花合作:

这是我的目录结构

ttm-jira
    - package.json
    - spec
          - jira-spec.js

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


  "name": "ttm-jira",
  "version": "1.0.0",
  "description": "nodeJS module to provide access to the JIRA REST API",
  "author": 
   "name": "...",
    "url" : "...."
  ,
  "main": "jira.js",
  "private": true,
  "repository": 
   "type": "git",
    "url" : "https://........git"
  ,
  "bugs": 
   "url" : "https://jira2........."
  ,
  "scripts": 
    "test"         : "npm run code-coverage && npm run unit-test",
    "unit-test"    : "jasmine-node . --autotest --captureExceptions --watch",
    "code-coverage": "istanbul cover --include-all-sources"
  ,
  "devDependencies": 
    "istanbul"    : "^0.4.0",
    "jasmine-node": "^1.14.5"
  ,
  "dependencies": 

  ,
 "engines": 
    "node": ">=0.10.24"
  

当我从 ttm-jira 文件夹运行 npm-test 时,我看到以下内容:

    > ttm-jira@1.0.0 test C:\SRM\node_modules\ttm-jira
> npm run code-coverage && npm run unit-test


> ttm-jira@1.0.0 code-coverage C:\SRM\node_modules\ttm-jira
> istanbul cover --include-all-sources

Need a filename argument for the cover command!
Try "istanbul help" for usage

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run
" "code-coverage"
npm ERR! node v4.2.1
npm ERR! npm  v2.14.7
npm ERR! code ELIFECYCLE
npm ERR! ttm-jira@1.0.0 code-coverage: `istanbul cover --include-all-sources`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ttm-jira@1.0.0 code-coverage script 'istanbul cover --include-all-sources'.
npm ERR! This is most likely a problem with the ttm-jira package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     istanbul cover --include-all-sources
npm ERR! You can get their info via:
npm ERR!     npm owner ls ttm-jira
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\SRM\node_modules\ttm-jira\npm-debug.log
npm ERR! Test failed.  See above for more details.
PS C:\SRM\node_modules\ttm-jira>

我怎样才能做到这一点?

如果我从我的 ttm-jira 目录运行以下命令:

istanbul cover ./spec/jira-spec.js jasmine-node test

我收到以下消息:

    PS C:\SRM\node_modules\ttm-jira> istanbul cover -x ./spec/jira-spec.js jasmine-node test
No coverage information was collected, exit without writing coverage information
C:\Users\SW029693\AppData\Roaming\npm\jasmine-node.CMD:1
(function (exports, require, module, __filename, __dirname)  @IF EXIST "%~dp0\node.exe" (
                                                              ^

SyntaxError: Unexpected token ILLEGAL
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Object.Module._extensions..js (module.js:442:10)
    at Object.Module._extensions.(anonymous function) [as .js] (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istan
bul\lib\hook.js:109:37)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at runFn (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:122:16)
    at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:251:17
    at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:68:16
    PS C:\SRM\node_modules\ttm-jira> istanbul cover ./spec/jira-spec.js jasmine-node test
    =============================================================================
    Writing coverage object [C:\SRM\node_modules\ttm-jira\coverage\coverage.json]
    Writing coverage reports at [C:\SRM\node_modules\ttm-jira\coverage]
    =============================================================================

    =============================== Coverage summary ===============================
    Statements   : 33.33% ( 1/3 )
    Branches     : 100% ( 0/0 )
    Functions    : 0% ( 0/2 )
    Lines        : 33.33% ( 1/3 )
    ================================================================================
    C:\SRM\node_modules\ttm-jira\spec\jira-spec.js:9
    __cov_Xe4IzZ5pgGmSS4dHihZPbQ.s['1']++;describe('A suite',function()__cov_Xe4IzZ5pgGmSS4dHihZPbQ.f['1']++;__cov_Xe4IzZ5p
    gGmSS4dHihZPbQ.s['2']++;it('contains spec with an expectation',function()__cov_Xe4IzZ5pgGmSS4dHihZPbQ.f['2']++;__cov_Xe
    4IzZ5pgGmSS4dHihZPbQ.s['3']++;expect(true).toBe(true);););
                                        ^

    ReferenceError: describe is not defined
        at Object.<anonymous> (C:\SRM\node_modules\ttm-jira\spec\jira-spec.js:9:39)
        at Module._compile (module.js:435:26)
        at Object.Module._extensions.(anonymous function) [as .js] (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istan
    bul\lib\hook.js:107:24)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:311:12)
        at Function.Module.runMain (module.js:467:10)
        at runFn (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:122:16)
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:251:17
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:68:16
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\node_modules\async\lib\async.js:52:16
    PS C:\SRM\node_modules\ttm-jira> istanbul cover --include-all-sources jasmine-node test
    No coverage information was collected, exit without writing coverage information
    C:\Users\SW029693\AppData\Roaming\npm\jasmine-node.CMD:1
    (function (exports, require, module, __filename, __dirname)  @IF EXIST "%~dp0\node.exe" (
                                                                ^

    SyntaxError: Unexpected token ILLEGAL
        at exports.runInThisContext (vm.js:53:16)
        at Module._compile (module.js:414:25)
        at Object.Module._extensions..js (module.js:442:10)
        at Object.Module._extensions.(anonymous function) [as .js] (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istan
    bul\lib\hook.js:109:37)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:311:12)
        at Function.Module.runMain (module.js:467:10)
        at runFn (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:122:16)
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:251:17
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:68:16
PS C:\SRM\node_modules\ttm-jira>

或者当我这样做时

istanbul cover ./spec/jira-spec.js

我得到以下信息:

        ReferenceError: describe is not defined
        at Object.<anonymous> (C:\SRM\node_modules\ttm-jira\spec\jira-spec.js:9:39)
        at Module._compile (module.js:435:26)
        at Object.Module._extensions.(anonymous function) [as .js] (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istan
    bul\lib\hook.js:107:24)
        at Module.load (module.js:356:32)
        at Function.Module._load (module.js:311:12)
        at Function.Module.runMain (module.js:467:10)
        at runFn (C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:122:16)
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\command\common\run-with-cover.js:251:17
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\lib\util\file-matcher.js:68:16
        at C:\Users\SW029693\AppData\Roaming\npm\node_modules\istanbul\node_modules\async\lib\async.js:52:16
    PS C:\SRM\node_modules\ttm-jira> istanbul cover --include-all-sources jasmine-node test
    No coverage information was collected, exit without writing coverage information
    C:\Users\SW029693\AppData\Roaming\npm\jasmine-node.CMD:1
    (function (exports, require, module, __filename, __dirname)  @IF EXIST "%~dp0\node.exe" (
                                                                ^

【问题讨论】:

【参考方案1】:

格式为:

istanbul cover [options] test_script [-- test-script-options]

在你的情况下:

istanbul cover --include-all-sources jasmine-node

【讨论】:

我用新的尝试更新了上面的答案,但仍然看到错误(发布在主要问题上),你能发现我在命令中做错了什么吗?

以上是关于node.js 伊斯坦布尔和茉莉花设置的主要内容,如果未能解决你的问题,请参考以下文章

如何在Node.js中对使用promises和事件发射器的函数进行单元测试?

nvm npm node.js的关系

Node.js 的设计错误

如何从终端中的谷歌测试套件获得c ++代码超额?

Node.js的安装和一些简单的使用

带你从零学Node.js