码迷,mamicode.com
首页 > Web开发 > 详细

[Node.js] Configuring npm package.json scripts

时间:2014-12-10 00:30:55      阅读:349      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   ar   color   os   sp   

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 checkVersion

npm 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

标签:des   style   blog   http   io   ar   color   os   sp   

原文地址:http://www.cnblogs.com/Answer1215/p/4154472.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!