I am new on developing in Node.js, I would like to know if there's a way to have ElasticSearch embedded in a Node.js application for testing purposes or if there's another way to test interaction with ElasticSearch without having an ElasticSearch running instance (mock ?)
There are no existing mock libraries for Elasticsearch and Node at the moment. If you know exactly what queries you are going to be performing, you could use a mocking library to mock the entire ES client and assert simple behaviors.
What I'd recommend, however, is actually running ES in a development environment for testing. I find that mocking external services is a pretty tricky thing to do in general, and your tests will likely be much more robust / trustworthy if running against an actual instance of the server.
Related
I want to set up a CI/CD workflow which includes testing my server as a whole.
Using node I have a couple options such as
Jest,
Mocha,
Chai
or a different approach such as Postman/Newman.
I have tried out Jest and found it very difficult to adjust my databases such as Postgres and Redis to the mock environment. In fact, I didn't get it to work at all, presumably because of all the technologies involved.
Is there is a tool, maybe one of the others mentioned, that takes the server as it is, without any additional configuration, calls the endpoints of the Server and gives me results, which I can then use to further take action (push/rollback/discard changes)?
If use Ruby on Rails framework, we can run the test in a easy way. It can create a test database, and we can make some fake data. After all the test finished, the test database will be cleaned.
Now want to do the same test with Node.js, Express framework and ElasticSearch. If create index data in the real ES server, maybe not the good way(Think ES as development environment used). Is there a better way to do it as RoR above?
I have researched from internet, but didn't find good example.
I'm using jenkins to automate the testing of my node js application? How do I test the queries to the database? How does Jenkins know to build the mongo db database first? How does automated testing work with database?
I don't use Jenkins for CI, I tend to use TeamCity, but I think your questions can be answered independently of which CI technology you use.
There is no definite answer to your questions, it all depends:
If you are looking to implement full integration tests, including querying a real database, then I would suggest creating a separate database just for testing like - mydb-test. You would have to configure your tests to use this database via config etc. In case you want to isolate your tests from the data access layer, then you need to mock the data access. This can be done by using a mock library, this will be easier to use depending on how well architected is your application code, where dependency injection IMHO is really important on this matter.
Anyone know of a way to spin up a neo4j instance for testing?
We're using Nodejs + Neo4j, with minimal unit tests which I'd like to change.
NosqlUnit looks promising but its dependant on JUint to run.
The Neo4j class com.lordofthejars.nosqlunit.neo4j.InMemoryNeo4j sounds fantastic. But I cant find any info on Google or Stackoverflow. Could this potentially be invoked by Java or Scala while running my tests in Nodejs?
Any help hints tips or tricks welcomed.
Update
I think using nodejs & sails-memory is a good option. As the main concern is testing the application layer. Using the waterline orm will allow me to swap databases for testing purposes.
I want to write one web application with node.js and MongoDB and I have got task to even test it. I would like to know if there are any tools like JMeter or anything else for load/stress testing of Node.js?
EDIT
My application is going to be information extraction kind of application and client expects extraction should not take more than 10 seconds for one document. Currently I have same application written in C# but its not scaling upto client's expectations. Then I came across this beautiful and fast Node.js. I think Node.js can help me alot.
Please enlighten !!!
Try nodeload: it's a collection of node.js modules for load testing HTTP services.
As a developer, you should be able to write load tests and get
informative reports without having to learn another framework. You
should be able to build by example and selectively use the parts of a
tool that fit your task. Being a library means that you can use as
much or as little of nodeload as makes sense, and you can create load
tests with the power of a full programming language. For example, if
you need to execute some function at a given rate, just use the
'nodeload/loop' module, and write the rest yourself
Just found out that this package is no longer under development so here are some active forks:
https://github.com/gamechanger/nodeload
https://github.com/Samuel29/NodeStressSuite
Why couldn't you test a node server with JMeter? For most load tests it doesn't matter what language your server is, you're just hitting it with a bunch of requests.
In any case, you could try loadtest which is implement in node.
Runs a load test on the selected HTTP or WebSockets URL. The API allows for easy integration in your own tests.
Edit:
This answer provides more options:
NodeJs stress testing tools/methods [closed]
Try artillery. Here are its features, the description of which is taken from the documentation:
Multiple protocols: Load test HTTP, WebSocket, Socket.io, Kinesis, HLS and more.
Scenarios: Support for complex scenarios to test multi-step interactions in your API or web app (great for ecommerce, transactional APIs, game servers etc).
Load testing & Functional testing: reuse the same scenario definitions to run performance tests or functional tests on your API or backend.
Performance metrics: get detailed performance metrics (latency, requests per second, concurrency, throughput).
Scriptable: write custom logic in JS, using any of the thousands of useful npm modules.
Integrations: statsd support out of the box for real-time reporting (integrate with Datadog, Librato, InfluxDB etc).
Extensible: write custom reporters, custom plugins, custom protocol engines etc.
and more! HTML reports, nice CLI, parameterization with CSV files.