Skip to content

Commit 16e733d

Browse files
committed
test: fix
1 parent 644b26d commit 16e733d

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

test/server/Server.test.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { relative, sep } = require('path');
44
const http = require('http');
55
const webpack = require('webpack');
66
const sockjs = require('sockjs/lib/transport');
7-
const portfinder = require('portfinder');
87
const getFreePort = require('../../lib/Server').getFreePort;
98
// TODO(@anshumanv) - Remove this test in next major
109
const findPort = require('../../lib/utils/findPort');
@@ -417,8 +416,8 @@ describe('Server', () => {
417416
it('should returns the port when the port is specified', () => {
418417
process.env.DEFAULT_PORT_RETRY = 5;
419418

420-
return getFreePort(8082).then((port) => {
421-
expect(port).toEqual(8082);
419+
return getFreePort(8082).then((freePort) => {
420+
expect(freePort).toEqual(8082);
422421
});
423422
});
424423

@@ -429,8 +428,8 @@ describe('Server', () => {
429428

430429
return createDummyServers(retryCount)
431430
.then(() => getFreePort(null))
432-
.then((port) => {
433-
expect(port).toEqual(8080 + retryCount);
431+
.then((freePort) => {
432+
expect(freePort).toEqual(8080 + retryCount);
434433
});
435434
});
436435

@@ -443,8 +442,8 @@ describe('Server', () => {
443442
createDummyServers(retryCount)
444443
// eslint-disable-next-line no-undefined
445444
.then(() => getFreePort(undefined))
446-
.then((port) => {
447-
expect(port).toEqual(8080 + retryCount);
445+
.then((freePort) => {
446+
expect(freePort).toEqual(8080 + retryCount);
448447
})
449448
);
450449
});
@@ -456,8 +455,8 @@ describe('Server', () => {
456455

457456
return createDummyServers(retryCount)
458457
.then(() => getFreePort())
459-
.then((port) => {
460-
expect(port).toEqual(8080 + retryCount);
458+
.then((freePort) => {
459+
expect(freePort).toEqual(8080 + retryCount);
461460
});
462461
});
463462

@@ -468,8 +467,8 @@ describe('Server', () => {
468467

469468
return createDummyServers(retryCount)
470469
.then(() => getFreePort())
471-
.then((port) => {
472-
expect(port).toEqual(8080 + retryCount);
470+
.then((freePort) => {
471+
expect(freePort).toEqual(8080 + retryCount);
473472
});
474473
});
475474

@@ -481,17 +480,17 @@ describe('Server', () => {
481480

482481
return createDummyServers(busyPorts)
483482
.then(() => getFreePort())
484-
.then((port) => {
485-
expect(port).toEqual(8080 + busyPorts.length);
483+
.then((freePort) => {
484+
expect(freePort).toEqual(8080 + busyPorts.length);
486485
});
487486
});
488487

489488
it("should throws the error when the port isn't found", () => {
490489
expect.assertions(1);
491490

492-
const spy = jest
493-
.spyOn(portfinder, 'getPort')
494-
.mockImplementation((callback) => callback(new Error('busy')));
491+
jest.mock('portfinder', () => {return {
492+
getPort: (callback) => callback(new Error('busy')),
493+
}});
495494

496495
const retryCount = 1;
497496

@@ -501,16 +500,14 @@ describe('Server', () => {
501500
.then(() => getFreePort())
502501
.catch((err) => {
503502
expect(err.message).toMatchSnapshot();
504-
505-
spy.mockRestore();
506503
});
507504
});
508505

509506
it('should work with findPort util', () => {
510507
process.env.DEFAULT_PORT_RETRY = 5;
511508

512-
return findPort(8082).then((port) => {
513-
expect(port).toEqual(8082);
509+
return findPort(8082).then((freePort) => {
510+
expect(freePort).toEqual(8082);
514511
});
515512
});
516513
});

0 commit comments

Comments
 (0)