Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit 264a7e6

Browse files
committed
Merge with v1.2.0
2 parents 863c38b + 8f71111 commit 264a7e6

15 files changed

Lines changed: 463 additions & 82 deletions

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"parser": "flow"
1616
}
1717
],
18+
"no-undef": "error",
1819
"no-unused-vars": ["error", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }]
1920
},
2021
"extends": ["prettier"],

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
### Removed
1616

1717
## [1.2.0] - 2019-11-13
18+
### Added
19+
- Add api acceptance tests
20+
1821
### Changed
1922
- Upgrade dependencies
2023

24+
### Fixed
25+
- Catch server.listen error and reject start method promise with it when occurs.
26+
2127
## [1.1.1] - 2019-11-12
2228
### Changed
2329
- Change readme. Add links to docs website.

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ module.exports = {
2828
testEnvironment: "node",
2929

3030
// The glob patterns Jest uses to detect test files
31-
testMatch: ["**/test/unit/**/?(*.)+(spec|test).js?(x)"],
31+
testMatch: ["**/test/unit/**/?(*.)+(spec|test).js?(x)"]
3232
//testMatch: ["**/test/unit/**/options.spec.js"]
3333
};

lib/Server.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,25 @@ class Server {
127127
}
128128

129129
startServer(resolve, reject) {
130-
this._server.listen(this._options, error => {
131-
if (error) {
132-
tracer.error(`Error starting server: ${error.message}`);
133-
this._error = error;
134-
reject(error);
135-
} else {
136-
tracer.info(`Server started and listening at http://localhost:${this._options.port}`);
137-
this._error = null;
138-
resolve(this);
139-
}
140-
});
130+
try {
131+
this._server.listen(this._options, error => {
132+
if (error) {
133+
tracer.error(`Error starting server: ${error.message}`);
134+
this._serverStarting = false;
135+
this._serverStarted = false;
136+
this._error = error;
137+
reject(error);
138+
} else {
139+
tracer.info(`Server started and listening at http://localhost:${this._options.port}`);
140+
this._error = null;
141+
this._serverStarting = false;
142+
this._serverStarted = true;
143+
resolve(this);
144+
}
145+
});
146+
} catch (error) {
147+
reject(error);
148+
}
141149
}
142150

143151
get settings() {

package-lock.json

Lines changed: 41 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
"mocks-server": "./bin/mocks-server"
3131
},
3232
"scripts": {
33-
"lint": "eslint index.js lib test",
33+
"lint": "eslint index.js lib test jest.config.js jest.acceptance.config.js",
3434
"lint-staged": "lint-staged",
3535
"test": "jest",
36-
"test-acceptance": "jest --config=jest.acceptance.config.js",
36+
"test-acceptance": "jest --config=jest.acceptance.config.js --runInBand",
3737
"test-ci": "npm run test && npm run test-acceptance",
3838
"coveralls": "cat ./coverage/lcov.info | coveralls"
3939
},
@@ -64,11 +64,16 @@
6464
"jest": "24.9.0",
6565
"lint-staged": "^9.4.2",
6666
"prettier": "^1.19.1",
67+
"request": "^2.88.0",
68+
"request-promise": "^4.2.5",
6769
"sinon": "^7.5.0"
6870
},
6971
"lint-staged": {
7072
"lib/**/*.js": "eslint",
71-
"test/**/*.js": "eslint"
73+
"test/**/*.js": "eslint",
74+
"index.js": "eslint",
75+
"jest.config.js": "eslint",
76+
"jest.acceptance.config.js": "eslint"
7277
},
7378
"husky": {
7479
"hooks": {

test/.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"globals": {
3+
"jest": true,
4+
"beforeAll": true,
5+
"beforeEach": true,
6+
"afterEach": true,
7+
"afterAll": true,
8+
"describe": true,
9+
"expect": true,
10+
"it": true
11+
}
12+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Copyright 2019 Javier Brea
3+
4+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
9+
*/
10+
11+
const { startServer, stopServer, request, changeDelay, TimeCounter } = require("./utils");
12+
13+
describe("delay setting", () => {
14+
let server;
15+
16+
beforeAll(async () => {
17+
server = await startServer();
18+
});
19+
20+
afterAll(() => {
21+
stopServer(server);
22+
});
23+
24+
describe("When started", () => {
25+
it("should respond with no delay", async () => {
26+
const timeCounter = new TimeCounter();
27+
await request("/api/users");
28+
timeCounter.stop();
29+
expect(timeCounter.total).toBeLessThan(200);
30+
});
31+
});
32+
33+
describe("When delay is changed through admin-api", () => {
34+
it("should respond after defined delay", async () => {
35+
await changeDelay(1000);
36+
const timeCounter = new TimeCounter();
37+
await request("/api/users");
38+
timeCounter.stop();
39+
expect(timeCounter.total).toBeGreaterThan(999);
40+
});
41+
});
42+
});

0 commit comments

Comments
 (0)