I am trying to use start-server-and-test npm package and want to run test cases.
For this I first need to start a test server and then run test command.
This how my package.json script part looks like.
Now the issue is start-server-and-test is starting the test server but it's not starting the test cases.
{
...
...
"scripts": {
"test": "jest --runInBand --config jest.config.json",
"dev": "nodemon --watch 'src/**' --ext 'ts,js' --exec \"ts-node src/app.ts\"",
"start": "ts-node src/app.ts",
"test-server": "MYSQL_TABLE_PREFIX=TEST_ PORT=4001 ts-node src/app.ts",
"ci": "start-server-and-test 'yarn test-server' http://localhost:4001/ 'yarn test'"
},
...
...
}
So I figured out that the issue was my endpoint http://localhost:4001/ was not responding with 200 status code and due to this the command yarn test was not getting executed.
So then I changed the endpoint to http://localhost:4001/health which was giving a 200 status code and then the test cases were getting executed.
so now the package.json looks like this
{
...
...
"scripts": {
"test": "jest --runInBand --config jest.config.json",
"dev": "nodemon --watch 'src/**' --ext 'ts,js' --exec \"ts-node src/app.ts\"",
"start": "ts-node src/app.ts",
"test-server": "MYSQL_TABLE_PREFIX=TEST_ PORT=4001 ts-node src/app.ts",
"ci": "start-server-and-test 'yarn test-server' http://localhost:4001/health 'yarn test'"
},
...
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With