Skip to content

Commit

Permalink
Merge pull request #3321 from nestjs/6.9.0
Browse files Browse the repository at this point in the history
chore(): 6.9.0 minor release
  • Loading branch information
kamilmysliwiec authored Nov 3, 2019
2 parents ee20664 + 101c47c commit 81b153f
Show file tree
Hide file tree
Showing 35 changed files with 2,212 additions and 56 deletions.
21 changes: 21 additions & 0 deletions integration/nest-application/get-url/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# dependencies
/node_modules

# IDE
/.idea
/.awcache
/.vscode

# misc
npm-debug.log

# example
/quick-start

# tests
/test
/coverage
/.nyc_output

# dist
/dist
50 changes: 50 additions & 0 deletions integration/nest-application/get-url/e2e/express.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ExpressAdapter } from '@nestjs/platform-express';
import { Test, TestingModule } from '@nestjs/testing';
import { expect } from 'chai';
import * as express from 'express';
import { AppModule } from '../src/app.module';
import { randomPort } from './utils';

describe('Get URL (Express Application)', () => {
let testModule: TestingModule;
let port: number;

beforeEach(async () => {
testModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
});

beforeEach(async () => {
port = await randomPort();
});

it('should be able to get the IPv6 address', async () => {
const app = testModule.createNestApplication(new ExpressAdapter(express()));
await app.listen(port);
expect(await app.getUrl()).to.be.eql(`http://[::1]:${port}`);
await app.close();
});
it('should be able to get the IPv4 address', async () => {
const app = testModule.createNestApplication(new ExpressAdapter(express()));
await app.listen(port, '127.0.0.5');
expect(await app.getUrl()).to.be.eql(`http://127.0.0.5:${port}`);
await app.close();
});
it('should return 127.0.0.1 for 0.0.0.0', async () => {
const app = testModule.createNestApplication(new ExpressAdapter(express()));
await app.listen(port, '0.0.0.0');
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 {
await app.getUrl();
} catch (err) {
expect(err).to.be.eql(
'app.listen() needs to be called before calling app.getUrl()',
);
}
});
});
43 changes: 43 additions & 0 deletions integration/nest-application/get-url/e2e/fastify.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { FastifyAdapter } from '@nestjs/platform-fastify';
import { Test, TestingModule } from '@nestjs/testing';
import { expect } from 'chai';
import { AppModule } from '../src/app.module';
import { randomPort } from './utils';

describe('Get URL (Fastify Application)', () => {
let testModule: TestingModule;
let port: number;

beforeEach(async () => {
testModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
});

beforeEach(async () => {
port = await randomPort();
});

it('should be able to get the IPv4 address', async () => {
const app = testModule.createNestApplication(new FastifyAdapter());
await app.listen(port, '127.0.0.5');
expect(await app.getUrl()).to.be.eql(`http://127.0.0.5:${port}`);
await app.close();
});
it('should return 127.0.0.1 for 0.0.0.0', async () => {
const app = testModule.createNestApplication(new FastifyAdapter());
await app.listen(port, '0.0.0.0');
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 {
await app.getUrl();
} catch (err) {
expect(err).to.be.eql(
'app.listen() needs to be called before calling app.getUrl()',
);
}
});
});
17 changes: 17 additions & 0 deletions integration/nest-application/get-url/e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as net from 'net';

export let port: number;

export async function randomPort(): Promise<number> {
const server = net.createServer();
return new Promise((resolve, reject) => {
if (port) {
resolve(port);
}
server.listen(0, () => {
port = (server.address() as net.AddressInfo).port;
server.close();
resolve(port);
});
});
}
Loading

0 comments on commit 81b153f

Please sign in to comment.