hapijs / hapi

The Simple, Secure Framework Developers Trust
https://hapi.dev
Other
14.63k stars 1.34k forks source link

How do I separate between integration testing and unit testing using Hapi in Node.js? #4406

Open dcrays08 opened 1 year ago

dcrays08 commented 1 year ago

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

I am trying to reduce the testing time in our automations for every time we update a unit within our 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?

I have the following in the package.json which runs the .labrc.js 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

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

I believe last time we had a discussion regarding testing we advocated for integration tests through server.inject rather than unit testing.

Regarding the way you'd structure the separation is up to you to be honest. Whatever makes sense for your project, maybe that would be test/integration and test/unit. To only run the integration test, you can use the -g, --grep command line option for lab IIRC. I haven't tested it, I just read documentation.