2015-12-14 103 views
4

我是Unit Testing的新用戶,因此我今天只需瞭解JasmineKarmaKarma-jasmine沒有安裝

我安裝噶:

npm init 
npm install karma --save-dev 
npm install -g karma-cli 
npm install karma-jasmine --save-dev 
npm install karma-chrome-launcher --save-dev 
karma init 

然而,當我嘗試推出因緣開始karma.conf.js它將引發我一個錯誤:

Error: Cannot find module 'jasmine-core' 
    at Function.Module._resolveFilename (module.js:338:15) 
    at Function.require.resolve (module.js:389:19) 
    at initJasmine (/Users/appfoundry/Projects/Unit Testing/node_modules/karma-jasmine/lib/index.js:8:42) 
    at Array.invoke (/Users/appfoundry/Projects/Unit Testing/node_modules/di/lib/injector.js:75:15) 
    at get (/Users/appfoundry/Projects/Unit Testing/node_modules/di/lib/injector.js:48:43) 
    at /Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/server.js:137:20 
    at Array.forEach (native) 
    at Server._start (/Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/server.js:136:21) 
    at invoke (/Users/appfoundry/Projects/Unit Testing/node_modules/di/lib/injector.js:75:15) 
    at Server.start (/Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/server.js:101:18) 
    at Object.exports.run (/Users/appfoundry/Projects/Unit Testing/node_modules/karma/lib/cli.js:231:26) 
    at requireCliAndRun (/usr/local/lib/node_modules/karma-cli/bin/karma:44:16) 
    at /usr/local/lib/node_modules/karma-cli/bin/karma:54:12 
    at /usr/local/lib/node_modules/karma-cli/node_modules/resolve/lib/async.js:44:21 
    at ondir (/usr/local/lib/node_modules/karma-cli/node_modules/resolve/lib/async.js:187:31) 
    at /usr/local/lib/node_modules/karma-cli/node_modules/resolve/lib/async.js:153:39 

我試圖在全球範圍內安裝核心:

npm install -g jasmine-core 

但這並沒有解決它。

當我嘗試安裝​​我得到一個錯誤說:

[email protected] requires a peer of [email protected]* but none was installed. 

回答

8

https://github.com/karma-runner/karma-jasmine

Note: Since karma-jasmine 0.3.0 the jasmine library is no longer bundled with karma-jasmine and you have to install it on your own. You can simply do it by:

npm install jasmine-core --save-dev

$ npm install jasmine-core --save-dev 
$ npm install karma-jasmine --save-dev 
+0

確實做到了!謝謝。雖然我在'node-modules'文件夾中沒有看到「karma-jasmine」或「karma-chrome」文件夾,這是否正常?我現在看到'jasmine-core'文件夾和'karma start karma.conf.js'works – Greg

+1

這取決於npm如何解決依賴關係,但這可能是正常的,是的。 '''npm''' [doc](https://docs.npmjs.com/cli/help) –

1

的問題是業力在全球範圍內運行。

我的解決方案(最簡單和無痛至少對我來說)是用npm腳本test命令包裝karma start命令,以便任何命令都在本地環境中運行。

package.json,在"scripts": {}中加"test": "karma start"

"scripts": { "test": "karma start", [...] },