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

Commit ab78253

Browse files
committed
test: adapt e2e tests. Get coverage from e2e tests. remove unit tests
1 parent f7bca60 commit ab78253

67 files changed

Lines changed: 1114 additions & 3167 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
# tests
1010
/coverage
1111
/mocks
12-
/test/e2e/fixtures/files-watch
12+
/test/e2e/fixtures/temp
13+
/test/e2e/fixtures/mocks.config.js
1314

1415
# misc
1516
.DS_Store

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ module.exports = {
2525
},
2626

2727
// The glob patterns Jest uses to detect test files
28-
testMatch: ["<rootDir>/test/unit/**/*.spec.js"],
29-
// testMatch: ["<rootDir>/test/unit/**/Plugin.spec.js"],
28+
testMatch: ["<rootDir>/test/e2e/**/*.spec.js"],
29+
// testMatch: ["<rootDir>/test/e2e/**/legacy-behaviors-api.spec.js"],
3030

3131
// The test environment that will be used for testing
3232
testEnvironment: "node",

jest.e2e.config.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

package-lock.json

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

package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
"scripts": {
2727
"lint": "eslint *.js src test",
2828
"lint-staged": "lint-staged",
29-
"test": "jest",
30-
"test:e2e": "jest --config=jest.e2e.config.js --runInBand",
31-
"test:unit": "npm run test"
29+
"test:e2e": "jest --runInBand"
3230
},
3331
"peerDependencies": {
3432
"@mocks-server/core": ">=2.0.0"
@@ -40,21 +38,17 @@
4038
},
4139
"devDependencies": {
4240
"@mocks-server/core": "2.0.0-beta.1",
41+
"cross-fetch": "3.0.6",
4342
"eslint": "7.12.1",
4443
"eslint-plugin-no-only-tests": "2.4.0",
4544
"eslint-config-prettier": "6.15.0",
4645
"eslint-plugin-prettier": "3.1.4",
47-
"fs-extra": "9.0.1",
4846
"husky": "4.3.0",
49-
"is-promise": "4.0.0",
5047
"jest": "26.6.3",
5148
"lint-staged": "10.5.0",
5249
"prettier": "2.1.2",
53-
"request": "2.88.2",
54-
"request-promise": "4.2.6",
5550
"sinon": "9.2.0",
56-
"strip-ansi": "6.0.0",
57-
"tree-kill-sync": "1.0.0"
51+
"wait-on": "5.2.1"
5852
},
5953
"lint-staged": {
6054
"src/**/*.js": "eslint",

src/Alerts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AlertsApi {
3030
getItems: this._getCollection.bind(this),
3131
parseItem: this._parseModel.bind(this),
3232
tracer: core.tracer,
33+
finder: (context) => (item) => item.context === context,
3334
});
3435
}
3536

src/Plugin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ class Plugin {
9191
}
9292

9393
stop() {
94-
if (this._stopListeningOnChangeSettings) {
95-
this._stopListeningOnChangeSettings();
96-
}
94+
this._stopListeningOnChangeSettings();
9795
this._removeRouter();
9896
}
9997

src/support/middlewares.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ function collectionMiddleware({ name, getItems, tracer }) {
1313
};
1414
}
1515

16-
function modelMiddleware({ name, getItems, parseItem, tracer }) {
16+
function modelMiddleware({ name, getItems, parseItem, tracer, finder }) {
1717
const capitalizedName = capitalize(name);
1818
const returnItem = parseItem ? (item) => parseItem(item) : (item) => item;
19+
const finderMethod = finder ? finder : (id) => (item) => item.id === id;
1920
return function (req, res, next) {
2021
const id = req.params.id;
2122
tracer.verbose(`${PLUGIN_NAME}: Sending ${name} ${id} | ${req.id}`);
22-
const foundItem = getItems().find((item) => item.id === id);
23+
const foundItem = getItems().find(finderMethod(id));
2324
if (foundItem) {
2425
res.status(200);
2526
res.send(returnItem(foundItem));

test/e2e/about-api.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@ http://www.apache.org/licenses/LICENSE-2.0
88
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.
99
*/
1010

11-
const { startServer, stopServer, request } = require("./support/utils");
11+
const { startServer, fetch, waitForServer } = require("./support/helpers");
1212
const { version } = require("../../package.json");
1313

1414
describe("about api", () => {
1515
let server;
1616
beforeAll(async () => {
1717
server = await startServer("web-tutorial");
18+
await waitForServer();
1819
});
1920

2021
afterAll(async () => {
21-
await stopServer(server);
22+
await server.stop();
2223
});
2324

2425
describe("get /", () => {
2526
it("should return current version", async () => {
26-
const response = await request("/admin/about");
27-
expect(response).toEqual({
27+
const response = await fetch("/admin/about");
28+
expect(response.body).toEqual({
2829
version,
2930
});
3031
});

0 commit comments

Comments
 (0)