fix(application): makes get-url work in callback

`app.getUrl()` was throwing an error when `this.isListening`
was set to false. The value was set _after_ `this.httpServer.listen`
was called, now it is set _before_ to ensure that the `app.getUrl()`
can be called in the callback of `listen`. A regression test has
been added for this, and all tests related to the change are passing.

fix: #5798
This commit is contained in:
Jay McDoniel
2020-11-26 14:16:59 -08:00
parent 7c070f3bf3
commit f36cb0c729
3 changed files with 15 additions and 1 deletions

View File

@@ -37,6 +37,13 @@ describe('Get URL (Express Application)', () => {
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
await app.close();
});
it('should return 127.0.0.1 even in a callback', () => {
const app = testModule.createNestApplication(new ExpressAdapter(express()));
return app.listen(port, async () => {
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
await app.close();
});
});
it('should throw an error for calling getUrl before listen', async () => {
const app = testModule.createNestApplication(new ExpressAdapter(express()));
try {

View File

@@ -30,6 +30,13 @@ describe('Get URL (Fastify Application)', () => {
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
await app.close();
});
it('should return 127.0.0.1 even in a callback', () => {
const app = testModule.createNestApplication(new FastifyAdapter());
return app.listen(port, async () => {
expect(await app.getUrl()).to.be.eql(`http://127.0.0.1:${port}`);
await app.close();
});
});
it('should throw an error for calling getUrl before listen', async () => {
const app = testModule.createNestApplication(new FastifyAdapter());
try {