如何使测试套件在每次构建之前运行?

时间:2020-09-08 06:20:07

标签: node.js reactjs npm react-scripts

目前,我的工作流程是先运行npm test,再运行npm build

有没有一种方法可以将test命令集成到build命令中,以便每次构建时都自动运行测试?

package.json:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
},

1 个答案:

答案 0 :(得分:2)

您在这里找到解决方法

"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts test && react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
}

您可以使用&&运算符将两个步骤合并为一个步骤。每次您首先运行npm build时,它将运行测试用例,然后进行构建