2015-11-16 7 views
5

मैंने अपनी स्क्रिप्ट के लिए टेस्टकेस लागू किया है और जब मैं इसे वेबस्टॉर्म में मोचा के लिए कॉन्फ़िगरेशन के साथ निष्पादित करता हूं तो यह बहुत बढ़िया चलता है।मैं एनपीएम स्क्रिप्ट के साथ मोचा कैसे चला सकता हूं?

मेरी टेस्ट स्क्रिप्ट का नाम adminTest.js है।

अब मैं बिल्ड सर्वर से कंसोल से इसे चलाने या बाद में करने के लिए एक NPM स्क्रिप्ट है पसंद है।

वजह मैं अपने package.json में एक स्क्रिप्ट प्रविष्टि बना दिया है

यहाँ पूरी फाइल है:

{ 
    "name": "cdh", 
    "version": "0.0.1", 
    "description": "CDH connector", 
    "main": "cdh.js", 
    "private" : true, 
    "dependencies": { 
    "cli-color": "^1.0.0", 
    "handlebars": "^4.0.3", 
    "sync-request": "^2.0.1", 
    "jslint": "^0.9.3", 
    "xmldom": "^0.1.19", 
    "xpath": "^0.0.9", 
    "mocha": "2.3.3 ", 
    "proxyquire": "1.7.3", 
    "mocha-sinon": "1.1.4", 
    "jasmine" : "2.3.2", 
    "chai" : "3.4.1" 
    }, 
    "devDependencies": {}, 
    "scripts": { 
    "test": "node ./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter spec" 
    }, 
    "author": "kme", 
    "license": "ISC" 
} 

जब मैं npm run test सांत्वना यह इस त्रुटि की ओर जाता है से साथ स्क्रिप्ट शुरू:

> [email protected] test C:\src\trunk\scripts\testing 
> node ./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter spec 


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" "test" 
npm ERR! node v4.2.0 
npm ERR! npm v2.14.7 
npm ERR! code ELIFECYCLE 
npm ERR! [email protected] test: `node ./node_modules/mocha/bin/mocha tests/**/*Test.js 
--reporter spec` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] test script 'node ./node_modules/mocha/bin/moch 
a tests/**/*Test.js --reporter spec'. 
npm ERR! This is most likely a problem with the cdh package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node ./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter sp 
ec 
npm ERR! You can get their info via: 
npm ERR!  npm owner ls cdh 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  C:\src\trunk\scripts\testing\npm-debug.log 

npm-debug.log फ़ाइल लगता है:

0 info it worked if it ends with ok 
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', 
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', 
1 verbose cli 'run', 
1 verbose cli 'test' ] 
2 info using [email protected] 
3 info using [email protected] 
4 verbose run-script [ 'pretest', 'test', 'posttest' ] 
5 info pretest [email protected] 
6 info test [email protected] 
7 verbose unsafe-perm in lifecycle true 
8 info [email protected] Failed to exec test script 
9 verbose stack Error: [email protected] test: `node ./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter spec` 
9 verbose stack Exit status 1 
9 verbose stack  at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:214:16) 
9 verbose stack  at emitTwo (events.js:87:13) 
9 verbose stack  at EventEmitter.emit (events.js:172:7) 
9 verbose stack  at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14) 
9 verbose stack  at emitTwo (events.js:87:13) 
9 verbose stack  at ChildProcess.emit (events.js:172:7) 
9 verbose stack  at maybeClose (internal/child_process.js:818:16) 
9 verbose stack  at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5) 
10 verbose pkgid [email protected] 
11 verbose cwd C:\src\trunk\scripts\testing 
12 error Windows_NT 6.1.7601 
13 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test" 
14 error node v4.2.0 
15 error npm v2.14.7 
16 error code ELIFECYCLE 
17 error [email protected] test: `node ./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter spec` 
17 error Exit status 1 
18 error Failed at the [email protected] test script 'node ./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter spec'. 
18 error This is most likely a problem with the cdh package, 
18 error not with npm itself. 
18 error Tell the author that this fails on your system: 
18 error  node ./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter spec 
18 error You can get their info via: 
18 error  npm owner ls cdh 
18 error There is likely additional logging output above. 
19 verbose exit [ 1, true ] 
+0

ग्लोब उदाहरण दोहरे उद्धरण चिह्नों में होना चाहिए,: "स्क्रिप्ट": आह को देखने के आप खिड़कियों पर काम कर रहे हैं, स्क्रिप्ट को बदलने के रूप में ऊपर पोस्ट में उल्लेख की कोशिश है { "परीक्षण": "./node_modules/mocha/bin/mocha \" ./ परीक्षा/यूनिट/**/* spec.js \ "--reporter मिनट" } – olefrank

उत्तर

13

आपकी स्क्रिप्ट परिभाषा node शामिल नहीं होना चाहिए:

"scripts": { 
    "test": "./node_modules/mocha/bin/mocha tests/**/*Test.js --reporter spec" 
}, 

या, यदि मोचा विश्व स्तर पर स्थापित किया गया है:

"scripts": { 
    "test": "mocha tests/**/*Test.js --reporter spec" 
}, 

यह भी देखें: Configure node npm package.json so that "npm test" works on both unix and windows

अद्यतन:

"testOnWindowsUseThis" : "node node_modules/mocha/bin/mocha" 
+0

मुझे लगता है के साथ एक समस्या यह है कि मेरी। मोचा। यह हमेशा बाहर निकलने के कोड 1 के साथ लौटाता है लेकिन कोई और त्रुटि संदेश – Kris

+0

शायद आप 'bin/mocha' स्क्रिप्ट' और/या 'lib/mocha.js' में कुछ' console.log' जोड़ सकते हैं यह देखने के लिए कि उन्हें और कैसे कहा जाता है । । – Sonata

+2

आप '/ node_modules/मोचा/bin /' जरूरत नहीं है, NPM स्क्रिप्ट के साथ 'PATH' में' node_modules/.bin' चलाने - https://docs.npmjs.com/misc/scripts#path –

संबंधित मुद्दे

 संबंधित मुद्दे