Skip to content

Commit 0122d11

Browse files
committed
Adjust tests so that they do not rely on localhost:80 being unbound
1 parent 1a18fe8 commit 0122d11

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

test/index.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -958,57 +958,57 @@ describe('options.baseUrl', () => {
958958

959959
it('uses baseUrl option without trailing slash and uri is prefixed with a slash', async () => {
960960

961-
const promise = Wreck.request('get', '/foo', { baseUrl: 'http://localhost' });
961+
const promise = Wreck.request('get', '/foo', { baseUrl: 'http://localhost:0' });
962962
await expect(promise).to.reject();
963-
expect(promise.req._headers.host).to.equal('localhost');
963+
expect(promise.req._headers.host).to.equal('localhost:0');
964964
expect(promise.req.path).to.equal('/foo');
965965
});
966966

967967
it('uses baseUrl option with trailing slash and uri is prefixed without a slash', async () => {
968968

969-
const promise = Wreck.request('get', 'foo', { baseUrl: 'http://localhost/' });
969+
const promise = Wreck.request('get', 'foo', { baseUrl: 'http://localhost:0/' });
970970
await expect(promise).to.reject();
971-
expect(promise.req._headers.host).to.equal('localhost');
971+
expect(promise.req._headers.host).to.equal('localhost:0');
972972
expect(promise.req.path).to.equal('/foo');
973973
});
974974

975975
it('uses baseUrl option without trailing slash and uri is prefixed without a slash', async () => {
976976

977-
const promise = Wreck.request('get', 'foo', { baseUrl: 'http://localhost' });
977+
const promise = Wreck.request('get', 'foo', { baseUrl: 'http://localhost:0' });
978978
await expect(promise).to.reject();
979-
expect(promise.req._headers.host).to.equal('localhost');
979+
expect(promise.req._headers.host).to.equal('localhost:0');
980980
expect(promise.req.path).to.equal('/foo');
981981
});
982982

983983
it('uses baseUrl option when uri is an empty string', async () => {
984984

985-
const promise = Wreck.request('get', '', { baseUrl: 'http://localhost' });
985+
const promise = Wreck.request('get', '', { baseUrl: 'http://localhost:0' });
986986
await expect(promise).to.reject();
987-
expect(promise.req._headers.host).to.equal('localhost');
987+
expect(promise.req._headers.host).to.equal('localhost:0');
988988
expect(promise.req.path).to.equal('/');
989989
});
990990

991991
it('uses baseUrl option with a path', async () => {
992992

993-
const promise = Wreck.request('get', '/bar', { baseUrl: 'http://localhost/foo' });
993+
const promise = Wreck.request('get', '/bar', { baseUrl: 'http://localhost:0/foo' });
994994
await expect(promise).to.reject();
995-
expect(promise.req._headers.host).to.equal('localhost');
995+
expect(promise.req._headers.host).to.equal('localhost:0');
996996
expect(promise.req.path).to.equal('/foo/bar');
997997
});
998998

999999
it('uses baseUrl option with a path and removes extra slashes', async () => {
10001000

1001-
const promise = Wreck.request('get', '/bar', { baseUrl: 'http://localhost/foo/' });
1001+
const promise = Wreck.request('get', '/bar', { baseUrl: 'http://localhost:0/foo/' });
10021002
await expect(promise).to.reject();
1003-
expect(promise.req._headers.host).to.equal('localhost');
1003+
expect(promise.req._headers.host).to.equal('localhost:0');
10041004
expect(promise.req.path).to.equal('/foo/bar');
10051005
});
10061006

10071007
it('uses baseUrl option with a url that has a querystring', async () => {
10081008

1009-
const promise = Wreck.request('get', '/bar?test=hello', { baseUrl: 'http://localhost/foo' });
1009+
const promise = Wreck.request('get', '/bar?test=hello', { baseUrl: 'http://localhost:0/foo' });
10101010
await expect(promise).to.reject();
1011-
expect(promise.req._headers.host).to.equal('localhost');
1011+
expect(promise.req._headers.host).to.equal('localhost:0');
10121012
expect(promise.req.path).to.equal('/foo/bar?test=hello');
10131013
});
10141014
});
@@ -1800,7 +1800,7 @@ describe('Events', () => {
18001800
once = true;
18011801
});
18021802

1803-
await expect(wreck.get('http://127.0.0.1', { timeout: 10 })).to.reject();
1803+
await expect(wreck.get('http://localhost:0', { timeout: 10 })).to.reject();
18041804
expect(once).to.be.true();
18051805
});
18061806

@@ -1818,8 +1818,8 @@ describe('Events', () => {
18181818
const wreck = Wreck.defaults({ events: true });
18191819
wreck.events.on('response', handler);
18201820

1821-
await expect(wreck.get('http://127.0.0.1', { timeout: 10 })).to.reject();
1822-
await expect(wreck.get('http://127.0.0.1', { timeout: 10 })).to.reject();
1821+
await expect(wreck.get('http://localhost:0', { timeout: 10 })).to.reject();
1822+
await expect(wreck.get('http://localhost:0', { timeout: 10 })).to.reject();
18231823
expect(count).to.equal(2);
18241824
});
18251825

@@ -2014,6 +2014,12 @@ internals.server = function (handler, socket) {
20142014
req.pipe(res);
20152015
};
20162016
}
2017+
else if (handler === 'fail') {
2018+
handler = (req, res) => {
2019+
2020+
res.socket.destroy();
2021+
};
2022+
}
20172023
else if (handler === 'ok') {
20182024
handler = (req, res) => {
20192025

0 commit comments

Comments
 (0)