Skip to content

Commit 9736bb2

Browse files
committed
fix: swap host for base_url since it is not a host
1 parent d2ab161 commit 9736bb2

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ Tests a node server firing generated requests (using its Swagger spec) at it
44
## Usage
55
```javascript
66
import { testServer } from '@springworks/server-tester';
7-
testServer('http://locahost', 3001, swagger_spec);
7+
testServer({ base_url: 'http://locahost', port: 3001, swagger_spec });
88
```

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { constructRequests } from '@springworks/request-baker';
22
import rp from 'request-promise';
33
import path from 'path';
44

5-
export async function testServer({ host, port, swagger_spec, generateRequests }) {
5+
export async function testServer({ base_url, port, swagger_spec, generateRequests }) {
66
const getRequests = generateRequests || constructRequests;
77
const { requests } = await getRequests(swagger_spec);
88
for (const generated_request of requests) {
99
const { method, body: json, qs, headers, base_path } = generated_request;
1010
const request_path = path.join(base_path || '', generated_request.path);
11-
const base_url = `${host.replace(/\/+$/, '')}${port ? `:${port}` : ''}`;
11+
const base_url_with_port = `${base_url.replace(/\/+$/, '')}${port ? `:${port}` : ''}`;
1212
try {
13-
await rp({ uri: request_path, baseUrl: base_url, method, qs, headers, json });
13+
await rp({ uri: request_path, baseUrl: base_url_with_port, method, qs, headers, json });
1414
}
1515
catch (err) {
1616
const message = `

test/acceptance/test-server-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('test/acceptance/test-server-test.js', () => {
3838
});
3939

4040
it('should not err', () => {
41-
return testServer({ host: 'http://localhost', port: 3001, swagger_spec }).then(res => {
41+
return testServer({ base_url: 'http://localhost', port: 3001, swagger_spec }).then(res => {
4242
});
4343
});
4444

test/unit/test-server-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('test/unit/test-server-test.js', () => {
5555

5656
describe('without base path', () => {
5757
beforeEach('stub rp', () => {
58-
return testServer({ host: 'http://localhost/', port: 3001, swagger_spec: api });
58+
return testServer({ base_url: 'http://localhost/', port: 3001, swagger_spec: api });
5959
});
6060

6161
it('should invoke a request once with correct params', () => {
@@ -84,7 +84,7 @@ describe('test/unit/test-server-test.js', () => {
8484
});
8585

8686
beforeEach('stub rp', () => {
87-
return testServer({ host: 'http://localhost/', port: 3001, swagger_spec: api });
87+
return testServer({ base_url: 'http://localhost/', port: 3001, swagger_spec: api });
8888
});
8989

9090
it('should invoke a request once with correct params', () => {
@@ -107,7 +107,7 @@ describe('test/unit/test-server-test.js', () => {
107107

108108
describe('excluding port', () => {
109109
beforeEach('stub rp', () => {
110-
return testServer({ host: 'http://localhost/', swagger_spec: api });
110+
return testServer({ base_url: 'http://localhost/', swagger_spec: api });
111111
});
112112

113113
it('should invoke a request once with correct params', () => {

0 commit comments

Comments
 (0)