zoukankan      html  css  js  c++  java
  • [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 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();
    }
  • 相关阅读:
    C++ Low level performance optimize
    简单find命令的实现
    数据结构学习之栈
    随机数的生成
    数据结构学习(一)
    C复习---动态内存分配
    (转)虚拟文件系统(VFS)浅析
    (转) 中断处理程序&中断服务例程
    Gradle系列教程之依赖管理
    Gradle系列教程之依赖管理
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4154472.html
Copyright © 2011-2022 走看看