简体   繁体   English

如何在 Node.js 中使用 Hapi 区分集成测试和单元测试?

[英]How do I separate between integration testing and unit testing using Hapi in Node.js?

How do I separate between integration testing and unit testing using Hapi in Node.js?如何在 Node.js 中使用 Hapi 区分集成测试和单元测试?

I am trying to reduce the testing time in our automations for every time we update a unit within our API.每当我们在 API 中更新一个单元时,我都试图减少自动化测试的时间。

I was wondering can I just create two new folders test/unit and test/int to separate the scripts and what would the update to the package.json require?我想知道我是否可以只创建两个新文件夹 test/unit 和 test/int 来分隔脚本以及 package.json 的更新需要什么?

I have the following in the package.json which runs the.labrc.js package.json我在运行 the.labrc.js package.json 的 package.json 中有以下内容

    "test": "npm run version-stamp && lab --bail -t 80 -r html -o coverage.html -r console -o stdout -r junit -o TestResult.xml -r lcov -o coverage.dat",
    "simple-test": "npm run version-stamp && lab",
    "test-int": "not sure what to put here",

labrc.js labrc.js

module.exports = {
    verbose: true,
    timeout: 7500,
    lint: true,
    paths: [
        "test/init/aws",
        "test/unit/plugins",
        "test/unit/utils",
        "test/unit/routes"
    ],

Sure your approach sounds ok.当然你的方法听起来不错。 Issue is that lab don't allow custom labrc to specify different paths for integration tests.问题是lab不允许自定义 labrc 为集成测试指定不同的路径。 but you can try to do something like this但你可以尝试做这样的事情

Separate tests in two different directories在两个不同的目录中单独测试

  • test/unit
  • test/integration

Provide an additional alternative labrc.js config file for integration tests and remove the one available in the root directory,为集成测试提供额外的替代labrc.js配置文件,并删除根目录中可用的配置文件,

You will have two different labrc.js files你将有两个不同labrc.js文件

  • test/unit/labrc.js
  • test/integration/labrc.js

The one for Unit Test should look like单元测试的应该看起来像

test/unit/labrc.js

module.exports = {
    verbose: true,
    timeout: 7500,
    lint: true,
    paths: [
        "unit/plugins",
        "unit/utils",
        "unit/routes",
    ],

For Integration Tests用于集成测试

test/unit/labrc.js

module.exports = {
    verbose: true,
    timeout: 7500,
    lint: true,
    paths: [
        "integration/aws",
    ],

In package.json在 package.json 中

{
    ... Lot of JSON config here
    "test": "npm run version-stamp && lab test/unit --bail -t 80 -r html -o coverage.html -r console -o stdout -r junit -o TestResult.xml -r lcov -o coverage.dat",
    "simple-test": "npm run version-stamp && lab test/unit",
    "test-integration": "lab test/integration", 
    ... Further JSON config here
}

Customize the parameters passed to the lab自定义传递给实验室的参数

As a Suggestion prefer integration over int It may be confusing.作为建议 prefer integration over int这可能会令人困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM