Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 仅当所有单元测试都通过-JS/Jest时才运行构建_Unit Testing_Build_Jestjs - Fatal编程技术网

Unit testing 仅当所有单元测试都通过-JS/Jest时才运行构建

Unit testing 仅当所有单元测试都通过-JS/Jest时才运行构建,unit-testing,build,jestjs,Unit Testing,Build,Jestjs,我正在尝试用单元测试构建一个JS应用程序。 因此,当我给出npm运行构建时,只有在所有Jest测试都通过的情况下,构建才应该成功。 我现在有两个npm脚本。 一个用于测试,一个用于构建生产 "scripts": { "build": "sudo webpack --mode=production", "test": "jest" } 一个适用于包括windows在内的所有环境的简单解决方案是使用&&operator附加这两个脚本 因此,创建的新脚本将类似于下面的bui

我正在尝试用单元测试构建一个JS应用程序。 因此,当我给出
npm运行构建时,只有在所有Jest测试都通过的情况下,构建才应该成功。
我现在有两个npm脚本。
一个用于测试,一个用于构建生产

  "scripts": {
    "build": "sudo webpack --mode=production",
    "test": "jest"
   }

一个适用于包括windows在内的所有环境的简单解决方案是使用&&operator附加这两个脚本

因此,创建的新脚本将类似于下面的build:test

  "scripts": {

    "build:test": "npm run test && npm run build ",

    "build": "sudo webpack --mode=production",
    "test": "jest",
   }
和&

操作员将确保只有当
npm run test
退出并返回成功代码时,才会执行
npm run build
,并且当任何测试失败时,jest负责将错误代码返回到终端