• [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();
    }
  • 相关阅读:
    六个月的实习
    cookbook学习第二弹
    cookbook学习第一弹
    maketrans translate
    Python strip函数用法小结
    【翻译】How To Tango With Django 1.5.4 第一章
    os相关方法总结
    python基础(一)
    bash快捷键
    Linux基本命令
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4154472.html
Copyright © 2020-2023  润新知