jestjs 的 npm 脚本

npm scripts for jestjs

我正在尝试 运行 使用 jestjs 进行测试,但我很难做到。

当我运行这个命令时:

npm testj

npm 说我没有那个脚本:

$ npm testj

Usage: npm <command>

where <command> is one of:
    access, add-user, ....

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm faq          commonly asked questions
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:
    /Users/bli1/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@2.13.1 /usr/local/lib/node_modules/npm

我的package.json

{
  ...
  ...
  "scripts": {
   ...
   ...
   "testj": "jest"
   ...
  },
  "dependencies": {
    ...
    ...
    "react": "^0.13.1",
    "react-highlight": "^0.4.1",
    "react-router": "^0.13.2",
    "react-select": "^0.5.6",    
  },
  "devDependencies": {
    ...
    ...
    "jest-cli": "^0.4.14",
    "react-tools": "^0.13.1",
  }
  "jest": {
    "scriptPreprocessor": "<rootDir>/preprocessor.js",
    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/react"
    ]
  }
}

preprocessor.js:

var ReactTools = require('react-tools');

module.exports = {
    process: function(src) {
        return ReactTools.transform(src);
    }
};

也许你需要npm run testj

只有少数脚本具有 shorthand,例如 npm testhttps://docs.npmjs.com/misc/scripts