Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ninadbstack committed Nov 28, 2023
1 parent 8c65a65 commit 9fe0f67
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions packages/core/test/unit/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,8 @@ describe('Unit / Server', () => {
});

describe('#host', () => {
beforeEach(async () => {
await server.listen(9000);
server.route('get', '/test/:path', (req, res) => res.text(req.params.path));
});

it('returns the host', async () => {
expect(server.host).toEqual('0.0.0.0');

// test connection via 0.0.0.0
await expectAsync(request('/test/foo', 'GET')).toBeResolvedTo('foo');

// test connection via localhost
let { request } = await import('../helpers/request.js');
await expectAsync(request(new URL(path, 'localhost'), 'GET')).toBeResolvedTo('foo');
});

describe('with PERCY_SERVER_HOST set', () => {
Expand All @@ -46,13 +34,8 @@ describe('Unit / Server', () => {
delete process.env.PERCY_SERVER_HOST;
});

it('uses correct host', async () => {
// test connection via localhost
await expectAsync(request('/test/foo', 'GET')).toBeResolvedTo('foo');

// test connection via 0.0.0.0
let { request } = await import('../helpers/request.js');
await expectAsync(request(new URL(path, '0.0.0.0'), 'GET')).toBeRejected();
it('returns correct host', async () => {
expect(server.host).toEqual('localhost');
});
});
});
Expand Down Expand Up @@ -97,6 +80,26 @@ describe('Unit / Server', () => {
Server.createServer().listen(server.port)
).toBeRejected();
});

describe('with PERCY_SERVER_HOST set', () => {
beforeEach(() => {
process.env.PERCY_SERVER_HOST = 'localhost';
});

afterEach(() => {
delete process.env.PERCY_SERVER_HOST;
});

it('listens on correct host', async () => {
expect(server.host).toEqual('localhost');
await server.listen()

Check failure on line 95 in packages/core/test/unit/server.test.js

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
server.route('get', '/test/:path', (req, res) => res.text(req.params.path));
await expectAsync(request('/test/foo', 'GET')).toBeResolvedTo('foo');

// as we have a single network interface locally its not easy to test a negative test
// where with a separate network interface we are unable to access server
});
});
});

describe('#close()', () => {
Expand Down

0 comments on commit 9fe0f67

Please sign in to comment.