Comparison between `lab` and `code` vs `mocha` and `chai` nodejs libraries - node.js

I am new to node.js and I have decided that I will be using hapijs for my web and API implementations.
However, I have found that the hapi community built and use lab and code for the test and assertion libraries, which are a rewrite of mocha and chai.
I am having a hard time finding the differences between those libraries.
I know there is the possibility of using them all interchangeably but I would like a more detailed comparison, as I want to define and adhere coding standards and I don't like mix and match of libraries, unless there is a valid reason.
Any feedback is appreciated

When you are planning to build web application using nodejs Hapi is more suitable for it. Writing TTD is important for developer now a days. Lab and code is node framework to help to writing unit test in nodejs. Lab comes with Hapi to cover unit case for endpoint like writing test case for route and covering different scenarios for route. Code is an assertion library. Code is used if you are asserting response code ,response body and any header parameters.

Related

node-quickbooks vs intuit-oauth

I am doing research on quickbooks online integration using node and angular 8.
The official intuit developer site provides two node packages.
one is official from intuit and one is from community.
I have glanced through both of them.
the official package is fairly universal. It essentially is just a API client to send a request to remote server and the payload is basic json format.
the community package seems a bit more specific but the documentation seems a bit confusing.
Which one would you choose to do the work and why?
I would love to hear your input.
Thanks :)
The Intuit provided library (intuit-oauth) is specifically for authenticating and getting the OAuth token you need to communicate with the Quickbooks API, the other library (node-quickbooks) is for making the actual calls against the API endpoints.
You will need both libraries, unless you are handling authentication in a different way.
Fwiw for whoever finds this useful:
I forked intuit-oauth, added typescript and fixed vulnerabilities that have been fixed in the PRs of their repo for years and never updated here: https://www.npmjs.com/package/intuit-oauth-ts
Additionally I forked node-quickbooks, updated the api to return promises rather than relying on callbacks, resolved the discovery URLs automatically, changed the format of response objects to be more sensible, and added (unfortunately only some) of the typescript definitions for it here: https://www.npmjs.com/package/qbo. I don't have enough time to add the definitions for all of the files (largey because the included ones should be completely exhaustive for every property in the QBO api, which is timeconsuming to define). If someone would like to contribute by adding more of the typescript definitions or adding all of them, I would really appreciate it.
I am interested in any example angular app using intuit-oauth
Trying to work it out but getting issues since there is no document for typescript.

Generate swagger/openapi docs from Mocha/Chai test suite

I want to use Swagger/OpenAPI to standardize documentation efforts. Most of the API's are built with NodeJS and I do integration testing with Mocha & Chai which helps tremendously with quickly making sure the API isn't broken after making changes. From what I understand, using Swagger won't replace my integration test but will make it easy for developers to know how to consume my API. If I can tie my documentation efforts into my test suite, it would make on-going documentation maintenance easier. When i add or modify test, I could update API documents in the same place.
What I was thinking about doing is using YUIDoc or JSDoc which generates API documentation from comments in source. But neither conform to OpenAPI spec. Then I found Swagger-JSdoc and figured I could just put all the comments in my test suite code since I'm already there specifying what to test in the endpoints.
Is there another way/workflow that might be more efficient for new or existing projects? How can I bring my documentation efforts closer to my test suite to improve on-going documentation maintenance?
I just published an npm module for the same. Not sure if you found an alternative, if not please feel free to give it a try.
https://github.com/LmntrX/mocha-swagger/
Install mocha-swagger globally with
npm install -g mocha-swagger
Then execute the following command:
mocha-swagger path/to/project/tests
This command will recursively parse test files in your test directory and generate a basic swagger.json file in current directory.
NB: Please note that the swagger spec generated will only contain your routes, methods and path parameters.

How do automation for web services using CuCumber?

How to do automation for web services using Cu Cumber? Please guide me on how to start it for my project on web services.
You cannot start automation testing using cucumber. Cucumber is just a BDD framework, which lets you execute test cases.
However, The most recommended option is to use ruby language with the cucumber framework. If your using ruby and if your project has rest-api's, you can use the gem called rest-client and airborne.
You can search about these, and learn how are you going to pass the request with the parameters and analyse the response and call these codes using gherkin language. All these together will constitute a framework called cucumber, which you can use to execute.
On a side note: The next time you post, please have some research already done and post what error are you facing.

unit testing for node.js

I looked into various frameworks for writing unit tests for an application developed in node.js. There exists multiple options like: nodeunit, jasmine-node, should.js library in Mocha. All seems to be pretty much capable of testing everything. I couldn't find any limitation of any of above mentioned options.
I will prefer to use nodeunit as it seems easy to use as a beginner. Any suggestion about any limitation of nodeunit would be highly helpful before I start working on this. Or any suggestion if anyone thinks that there exists a easier and better option for unit testing in node.js.
I previously used JUnit in Java and want to find similar testing framework. It was hard for me to getting started with BDD frameworks like Mocha. Finally I stoped on node unit. All advanced functions which I couldn't find in node unit was finded in expect.js. Also important testing framework in web application context is superagent(which helps to make requests, and get responce on tests), it was easy to mix with node unit, and easy to test async code. One more nice thing there is plugin for WebStorm :)

Need Testing in node.js

I'm quite new to testing in javascript, where I work, we us node.js for our projects.
I finished one of our projects, but I only used manual testing.
I need to develop my testing skill and I dont know how to improve it.
I need any testing tool to run my node.js projects, could you please tell me how to improve and learn new testing skills?
Look at Mocha test framework. I think this is the best choose for testing node.js applications at this moment.
If you are using Node to develop a web application you could use one of the headless browsers to test the user interaction (along with ajax) there are PhantomJS and Zombie for example.
Look around in Node Toolbox you'll find many frameworks and utilities to create your tests.
This is a good overview on some of the different unit test tools for Node.js:
3 Quick Tips for Writing Tests in Node.Js (after some rambling)

Resources