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的更多相关文章

  1. node.js 中的package.json文件怎么创建?

    最近在用webstorm和nodejs做一些东西,老是各种混乱,今天上午创建一个新的项目,结果发现,npm init之后,并没有出现package.json,并没有太明确他的功能的小姑娘表示十分的惊慌 ...

  2. Node.js NPM Package.json

    章节 Node.js NPM 介绍 Node.js NPM 作用 Node.js NPM 包(Package) Node.js NPM 管理包 Node.js NPM Package.json Nod ...

  3. node.js的npm安装

    我不打算引进node.js的npm安装,但发现node.js通过管理一些包npm实现,或给一个简短的npm. 1.npm什么        npm是一个node包管理和分发工具,已经成为了非官方的公布 ...

  4. Angular Npm Package.Json文件详解

    Angular7 Npm Package.Json文件详解   近期时间比较充裕,正好想了解下Angular Project相关内容.于是将Npm官网上关于Package.json的官方说明文档进行了 ...

  5. 安装node.js 和 npm 的完整步骤

    vue 生命周期 1,beforeCreate 组件刚刚被创建 2,created 组件创建完成 3,beforeMount 挂载之前 4,mounted 挂载之后 5,beforeDestory 组 ...

  6. 关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用

    关于node.js和npm,cnpm的安装记录以及gulp自动构建工具的使用   工作环境:window下 在一切的最开始,安装node.js (中文站,更新比较慢http://nodejs.cn/) ...

  7. node.js的npm详解

    一.什么是npm呢 npm(Node Package Manager,node包管理器)是node的包管理器,他允许开发人员在node.js应用程序中创建,共享并重用模块.模块就是可以在不同的项目中重 ...

  8. how to updating Node.js and npm

    how to updating  Node.js and npm 1 Installing Node.js and updating npm How do I update Node.js ? Not ...

  9. [web 前端] Npm package.json与package-lock.json文件的作用

    本文链接:https://blog.csdn.net/u013992330/article/details/81110018 最新版nodejs中,多了一个package-lock.json文件,刚开 ...

随机推荐

  1. 【开源项目之路】jquery的build问题

    在刚开始clone了jquery到本地build的时候,就遇到了问题. “ENORESTARGET No tag found that was able to satisfy ...” 提示为bowe ...

  2. [WebService]之TCPMon的使用

    TCPMon是apache下的一个项目,下载地址:http://ws.apache.org/commons/tcpmon/download.cgi (1)功能: TCPMon可以拦截客户与服务之间的H ...

  3. Who is the best at Dataset X?

    推荐一个关于分类.目标检测.姿态估计的数据集收藏的网页. Did you ever want to quickly learn?which paper provides the best result ...

  4. openstack neutron 各节点网络配置

  5. 第三百五十五天 how can I 坚持

    快一年了,三百五十五天了,等写个程序算算时间,看看日期和天数能不能对的上,哈哈. 计划还是未制定,天气预报还是没有写完,立马行动,发完这个博客,立马行动. 计划:设计模式1个月,三大框架3个月,计算机 ...

  6. 第二百一十四天 how can I 坚持

    今天肯定有需要记录的东西. html表格. table tr rd colspan rowspan, 还有呢.没了. 睡觉,明天石洋要来泛华. 睡觉.

  7. Sharding & IDs at Instagram(转)

    英文原文:http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram 译文:http://ww ...

  8. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

  9. JSF 2 button and commandButton example

    In JSF 2.0, both <h:button /> and <h:commandButton /> tags are used to render HTML input ...

  10. ucos创建任务的一般方法

    一般说来,任务可在OSStart()启动任务调度之前来创建,也可在任务中创建,但是UC/OS有个规定:在调用OSStart()启动任务调度之前,必须创建了至少一个任务.因此一般习惯上,在OSStart ...