首页 > 代码库 > [Node.js] Configuring npm package.json scripts
[Node.js] Configuring npm package.json scripts
With a node package manager‘s (npm) package.json script
property, you can preconfigure common tasks like running unit tests with npm $SCRIPT_NAME.
package.json:
{ "name": "commonJSBroswerfiy", "version": "0.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "checkVersion": "mocha --version", "fnTest": "mocha app" }, "author": "", "license": "MIT", "dependencies": { "underscore": "^1.7.0" }, "devDependencies": { "bower": "^1.3.12", "chai": "^1.10.0", "mocha": "^2.0.1" }}
If you run ‘npm test‘, it will go to the scripts tag to run test script.
$ npm test
echo "Error: no test specified" && exit 1
You can set up you own test:
"checkVersion": "mocha --version","fnTest": "mocha app"
run:
npm run checkVersionnpm run fnTest
See more:
mocha,
chai
app.js:
var up = require(‘./dep‘), chai = require(‘chai‘), expect = chai.expect, assert = chai.assert;var should = require(‘chai‘).should();describe(‘my file‘, function () { xit(‘should convert strings to upper case‘, function () { expect(up(‘hello‘)).to.equal(‘HELLO‘); }); xit(‘should be a string‘, function() { var one = up(‘one‘); //assert.typeOf(one, ‘Array‘); //false assert.typeOf(one, ‘String‘); //true }); it(‘string string length should be 10‘, function() { var loveMessage = up(‘I love you‘); loveMessage.should.have.length(10); });});
dep.js:
module.exports = function (str) { return str.toUpperCase();}
[Node.js] Configuring npm package.json scripts
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。