I have two files:
Simple Express app: app.js
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
and an app.test.js
import axios from 'axios';
beforeAll( () => {
// Probably here I should start the server, but how?
});
test("test-my-api", async () => {
const response = await axios.get("http://localhost:3000")
expect(response.data).toBe("Hello World!")
}")
How can I run the app before testing the requests to the app in a secure manner? How is it done professionally?