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

Commit 4efc891

Browse files
committed
test(e2e): Add v2 e2e tests
1 parent 6843b7d commit 4efc891

29 files changed

Lines changed: 1444 additions & 21 deletions

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ jobs:
4141
run: npm run lint
4242
- name: Test unit
4343
run: npm run test:unit
44-
#- name: Test E2E
45-
#run: npm run test:e2e
46-
#id: test-e2e
44+
- name: Test E2E
45+
run: npm run test:e2e
46+
id: test-e2e
4747
- name: Upload test results
4848
uses: actions/upload-artifact@v2
4949
with:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
/mocks
1212
/test/e2e/main/v1/fixtures/files-watch
1313
/test/e2e/main/v1/fixtures/mocks.config.js
14+
/test/e2e/main/v2/fixtures/temp
15+
/test/e2e/main/v2/fixtures/mocks.config.js
1416

1517
# misc
1618
.DS_Store

jest.e2e.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
clearMocks: true,
77

88
testMatch: ["<rootDir>/test/e2e/**/*.spec.js"],
9-
// testMatch: ["<rootDir>/test/e2e/main/v1/web-tutorial-files-watch.spec.js"],
9+
// testMatch: ["<rootDir>/test/e2e/main/v2/files-watch.spec.js"],
1010

1111
// Indicates whether the coverage information should be collected while executing the test
1212
collectCoverage: false,

package-lock.json

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

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "@mocks-server/plugin-inquirer-cli",
33
"version": "1.4.1",
4-
"description": "Plugin for Mocks server. Displays an interactive CLI",
4+
"description": "Mocks server plugin providing an interactive CLI",
55
"keywords": [
66
"mocks-server-plugin",
77
"interactive",
88
"cli",
99
"inquirer",
10+
"settings",
1011
"administration",
11-
"testing",
12+
"options",
1213
"development"
1314
],
1415
"author": "Javier Brea",
@@ -42,6 +43,7 @@
4243
},
4344
"devDependencies": {
4445
"@mocks-server/core": "2.0.0-beta.1",
46+
"cross-fetch": "3.0.6",
4547
"cross-spawn": "7.0.3",
4648
"eslint": "7.15.0",
4749
"eslint-plugin-no-only-tests": "2.4.0",
@@ -57,7 +59,8 @@
5759
"request-promise": "4.2.6",
5860
"sinon": "9.2.2",
5961
"strip-ansi": "6.0.0",
60-
"tree-kill": "1.2.2"
62+
"tree-kill": "1.2.2",
63+
"wait-on": "5.2.1"
6164
},
6265
"lint-staged": {
6366
"src/**/*.js": "eslint",

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sonar.projectVersion=1.4.1
44

55
sonar.javascript.file.suffixes=.js
66
sonar.sourceEncoding=UTF-8
7-
sonar.exclusions=node_modules/**,*.config.js
7+
sonar.exclusions=node_modules/**,*.config.js,test/**/fixtures/**
88
sonar.test.exclusions=test/**/*
99
sonar.coverage.exclusions=test/**/*
1010
sonar.cpd.exclusions=test/**

test/e2e/main/v1/cli-no-behaviors.spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ describe("with no behaviors", () => {
2020
await cli.kill();
2121
});
2222

23-
it.skip("should display alerts", async () => {
24-
cli = new CliRunner([BINARY_PATH, "--behavior=foo", "--pathLegacy=no-behaviors"], {
25-
cwd: cwdPath,
26-
});
27-
await wait();
28-
expect(cli.currentScreen).toEqual(expect.stringContaining("ALERTS"));
29-
expect(cli.currentScreen).toEqual(expect.stringContaining("Warning: No behaviors found"));
30-
});
31-
3223
it("should print a dash as current behavior", async () => {
3324
cli = new CliRunner([BINARY_PATH, "--pathLegacy=no-behaviors"], {
3425
cwd: cwdPath,

test/e2e/main/v1/interactive-cli.spec.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ describe("interactive CLI", () => {
7272
expect(newScreen).toEqual(expect.stringContaining("Current behavior: dynamic"));
7373
});
7474

75-
it.skip("should have removed alert", async () => {
76-
expect(cli.currentScreen).toEqual(expect.not.stringContaining("ALERTS"));
77-
});
78-
7975
it("should serve users collection mock under the /api/users path", async () => {
8076
const users = await request("/api/users");
8177
expect(users).toEqual([

test/e2e/main/v2/arguments.spec.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 { mocksRunner, fetch, waitForServerAndCli, TimeCounter } = require("./support/helpers");
12+
13+
describe("command line arguments", () => {
14+
let mocks;
15+
16+
afterEach(async () => {
17+
await mocks.kill();
18+
});
19+
20+
describe("path option", () => {
21+
it("should set mocks folder", async () => {
22+
expect.assertions(2);
23+
mocks = mocksRunner(["--path=web-tutorial"]);
24+
await waitForServerAndCli();
25+
const users = await fetch("/api/users");
26+
expect(users.body).toEqual([
27+
{ id: 1, name: "John Doe" },
28+
{ id: 2, name: "Jane Doe" },
29+
]);
30+
expect(mocks.currentScreen).toEqual(expect.stringContaining("Mocks: 3"));
31+
});
32+
});
33+
34+
describe("mock option", () => {
35+
describe("when not provided", () => {
36+
it("should set as current mock the first one found", async () => {
37+
expect.assertions(2);
38+
mocks = mocksRunner(["--path=web-tutorial"]);
39+
await waitForServerAndCli();
40+
const users = await fetch("/api/users/2");
41+
expect(users.body).toEqual({ id: 1, name: "John Doe" });
42+
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: base"));
43+
});
44+
});
45+
46+
describe("when provided and exists", () => {
47+
it("should set current mock", async () => {
48+
expect.assertions(2);
49+
mocks = mocksRunner(["--path=web-tutorial", "--mock=user-2"]);
50+
await waitForServerAndCli();
51+
const users = await fetch("/api/users/2");
52+
expect(users.body).toEqual({ id: 2, name: "Jane Doe" });
53+
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: user-2"));
54+
});
55+
});
56+
57+
describe("when provided and does not exist", () => {
58+
it("should display an alert", async () => {
59+
mocks = mocksRunner(["--path=web-tutorial", "--mock=foo"]);
60+
await waitForServerAndCli();
61+
expect(mocks.currentScreen).toEqual(expect.stringContaining("ALERTS"));
62+
expect(mocks.currentScreen).toEqual(expect.stringContaining('Mock "foo" was not found'));
63+
});
64+
65+
it("should set as current behavior the first one found", async () => {
66+
expect.assertions(3);
67+
mocks = mocksRunner(["--path=web-tutorial", "--mock=foo"]);
68+
await waitForServerAndCli();
69+
const users = await fetch("/api/users/2");
70+
expect(users.body).toEqual({ id: 1, name: "John Doe" });
71+
expect(mocks.currentScreen).toEqual(expect.stringContaining("Using the first one found"));
72+
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: base"));
73+
});
74+
});
75+
});
76+
77+
describe("delay option", () => {
78+
it("should set delay", async () => {
79+
expect.assertions(3);
80+
mocks = mocksRunner(["--path=web-tutorial", "--delay=2000"]);
81+
await waitForServerAndCli();
82+
const timeCounter = new TimeCounter();
83+
const users = await fetch("/api/users");
84+
timeCounter.stop();
85+
expect(users.body).toEqual([
86+
{ id: 1, name: "John Doe" },
87+
{ id: 2, name: "Jane Doe" },
88+
]);
89+
expect(mocks.currentScreen).toEqual(expect.stringContaining("Delay: 2000"));
90+
expect(timeCounter.total).toBeGreaterThan(1999);
91+
});
92+
});
93+
94+
describe("log option", () => {
95+
it("should set log level", async () => {
96+
mocks = mocksRunner(["--path=web-tutorial", "--log=debug"]);
97+
await waitForServerAndCli();
98+
expect(mocks.currentScreen).toEqual(expect.stringContaining("Log level: debug"));
99+
});
100+
});
101+
});

0 commit comments

Comments
 (0)