Search code examples
node.jsnightwatch.js

In NightwatchJS how do I make a synchronous DB call and make Nightwatch wait for the response before moving on


I have a NightwatchJS test that requires a MSSQL Db call to complete before moving on to then verify the results of that db call. The test is 2 parts.

Part 1 fills out a form and submits it into our website and verifies via API in our CMS that the form successfully posted and saves the Guid in a table in another db specifically for Nightwatch testing for verification later.

Part 2 runs later in the day to allow another internal process to 'ingest' that form into a different department's db and return the ingestion results into our CMS for that form. Part 2 then needs to do a Db lookup into the Nightwatch db and get all Guids that happened in the last 24 hours and hit another API endpoint in our CMS to verify ingestion of that form occurred into that other department by checking a field that the other department's process updates on ingestion.

I had the same issue of waiting-to-complete with the API calls where I needed NightwatchJS to wait for the API call to complete in order to use the results in the assertion. To solve that, I used a synchronous http library called 'sync-request'. So, that part works fine.

However, I cannot seem to find a synchronous Db library that works in Nightwatch's world.

I am currently using 'tedious' as my Db library but there is no mechanism for awaiting. I tried promises and async/await to no avail since the async stuff is wrapped inside the library.

I tried Co-mssql but I keep getting an error

TypeError: co(...) is not a function

using their exact example code...

Any ideas or suggestions?

Any other synchronous MSSQL libraries that work in NightwatchJS?

Any way of using 'tedious' is a fashiopn that ensures await-ability?


Solution

  • I found a library called sync-request that blocks the thread which is what i need.