Hello, I am currently utilizing supertest to test the functionality of my Node.js express server application.
My goal is to accomplish the following:
let request = require('supertest');
let app = require('./server.js');
request(app).get("/api").then(data=>{//*do something here*//});
However, I am encountering a 301 Moved Permanently
error.
If I launch my server on port 8008 and adjust the test like so:
let request = require('supertest');
let app = require('./server.js');
let agent = request.agent('localhost:8008');
agent.get("/api").then(data=>{//*do something here*//});
I receive the correct API responses as expected.
Is there a way to achieve a successful 200 response by using request(app)
instead of having to specify localhost:8008
?
I plan on executing these tests as part of continuous integration, however, I lack control over the testing environment which prevents me from starting a testing server each time in order to access localhost.
Thank you.