refactor writeQuery fn in cli.spec.js for client-ws package
Tasks:
use regex to get pagination
use number of received pages to know when to stop waiting for more stdouts
Acceptance criteria:
tests still pass
Notes:
aim to reduce the time it takes for the tests to pass.
refactor the beneath
constwriteQuery=(c,query='Luke Skywalker')=>newPromise((resolve)=>{constoutput={results: [],error: null}c.stdin.write(`${query}\r`)c.stdout.on('data',(data)=>{consts=data.toString()constpages=s.split('\n')pages.forEach((page)=>{if(page[0]==='('){output.results.push(page)}})if(output.results.length&&pages[pages.length-1]==='What character would you like to search for? '){resolve(output)}})c.stderr.on('data',(data)=>{constp=data.toString().split('\n')// eslint-disable-next-line prefer-destructuringoutput.error=p[0]resolve(output)})})
The console should reset on completion of a search (on receipt of the last message in case of success, or on any error) to allow the user to make another search without restarting the application