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

Commit

Permalink
test(e2e): Add v2 e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrea committed Feb 14, 2021
1 parent 6843b7d commit 4efc891
Show file tree
Hide file tree
Showing 29 changed files with 1,444 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ jobs:
run: npm run lint
- name: Test unit
run: npm run test:unit
#- name: Test E2E
#run: npm run test:e2e
#id: test-e2e
- name: Test E2E
run: npm run test:e2e
id: test-e2e
- name: Upload test results
uses: actions/upload-artifact@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
/mocks
/test/e2e/main/v1/fixtures/files-watch
/test/e2e/main/v1/fixtures/mocks.config.js
/test/e2e/main/v2/fixtures/temp
/test/e2e/main/v2/fixtures/mocks.config.js

# misc
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion jest.e2e.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
clearMocks: true,

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

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: false,
Expand Down
86 changes: 86 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@mocks-server/plugin-inquirer-cli",
"version": "1.4.1",
"description": "Plugin for Mocks server. Displays an interactive CLI",
"description": "Mocks server plugin providing an interactive CLI",
"keywords": [
"mocks-server-plugin",
"interactive",
"cli",
"inquirer",
"settings",
"administration",
"testing",
"options",
"development"
],
"author": "Javier Brea",
Expand Down Expand Up @@ -42,6 +43,7 @@
},
"devDependencies": {
"@mocks-server/core": "2.0.0-beta.1",
"cross-fetch": "3.0.6",
"cross-spawn": "7.0.3",
"eslint": "7.15.0",
"eslint-plugin-no-only-tests": "2.4.0",
Expand All @@ -57,7 +59,8 @@
"request-promise": "4.2.6",
"sinon": "9.2.2",
"strip-ansi": "6.0.0",
"tree-kill": "1.2.2"
"tree-kill": "1.2.2",
"wait-on": "5.2.1"
},
"lint-staged": {
"src/**/*.js": "eslint",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sonar.projectVersion=1.4.1

sonar.javascript.file.suffixes=.js
sonar.sourceEncoding=UTF-8
sonar.exclusions=node_modules/**,*.config.js
sonar.exclusions=node_modules/**,*.config.js,test/**/fixtures/**
sonar.test.exclusions=test/**/*
sonar.coverage.exclusions=test/**/*
sonar.cpd.exclusions=test/**
Expand Down
9 changes: 0 additions & 9 deletions test/e2e/main/v1/cli-no-behaviors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ describe("with no behaviors", () => {
await cli.kill();
});

it.skip("should display alerts", async () => {
cli = new CliRunner([BINARY_PATH, "--behavior=foo", "--pathLegacy=no-behaviors"], {
cwd: cwdPath,
});
await wait();
expect(cli.currentScreen).toEqual(expect.stringContaining("ALERTS"));
expect(cli.currentScreen).toEqual(expect.stringContaining("Warning: No behaviors found"));
});

it("should print a dash as current behavior", async () => {
cli = new CliRunner([BINARY_PATH, "--pathLegacy=no-behaviors"], {
cwd: cwdPath,
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/main/v1/interactive-cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ describe("interactive CLI", () => {
expect(newScreen).toEqual(expect.stringContaining("Current behavior: dynamic"));
});

it.skip("should have removed alert", async () => {
expect(cli.currentScreen).toEqual(expect.not.stringContaining("ALERTS"));
});

it("should serve users collection mock under the /api/users path", async () => {
const users = await request("/api/users");
expect(users).toEqual([
Expand Down
101 changes: 101 additions & 0 deletions test/e2e/main/v2/arguments.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Copyright 2019 Javier Brea
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
http://www.apache.org/licenses/LICENSE-2.0
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.
*/

const { mocksRunner, fetch, waitForServerAndCli, TimeCounter } = require("./support/helpers");

describe("command line arguments", () => {
let mocks;

afterEach(async () => {
await mocks.kill();
});

describe("path option", () => {
it("should set mocks folder", async () => {
expect.assertions(2);
mocks = mocksRunner(["--path=web-tutorial"]);
await waitForServerAndCli();
const users = await fetch("/api/users");
expect(users.body).toEqual([
{ id: 1, name: "John Doe" },
{ id: 2, name: "Jane Doe" },
]);
expect(mocks.currentScreen).toEqual(expect.stringContaining("Mocks: 3"));
});
});

describe("mock option", () => {
describe("when not provided", () => {
it("should set as current mock the first one found", async () => {
expect.assertions(2);
mocks = mocksRunner(["--path=web-tutorial"]);
await waitForServerAndCli();
const users = await fetch("/api/users/2");
expect(users.body).toEqual({ id: 1, name: "John Doe" });
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: base"));
});
});

describe("when provided and exists", () => {
it("should set current mock", async () => {
expect.assertions(2);
mocks = mocksRunner(["--path=web-tutorial", "--mock=user-2"]);
await waitForServerAndCli();
const users = await fetch("/api/users/2");
expect(users.body).toEqual({ id: 2, name: "Jane Doe" });
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: user-2"));
});
});

describe("when provided and does not exist", () => {
it("should display an alert", async () => {
mocks = mocksRunner(["--path=web-tutorial", "--mock=foo"]);
await waitForServerAndCli();
expect(mocks.currentScreen).toEqual(expect.stringContaining("ALERTS"));
expect(mocks.currentScreen).toEqual(expect.stringContaining('Mock "foo" was not found'));
});

it("should set as current behavior the first one found", async () => {
expect.assertions(3);
mocks = mocksRunner(["--path=web-tutorial", "--mock=foo"]);
await waitForServerAndCli();
const users = await fetch("/api/users/2");
expect(users.body).toEqual({ id: 1, name: "John Doe" });
expect(mocks.currentScreen).toEqual(expect.stringContaining("Using the first one found"));
expect(mocks.currentScreen).toEqual(expect.stringContaining("Current mock: base"));
});
});
});

describe("delay option", () => {
it("should set delay", async () => {
expect.assertions(3);
mocks = mocksRunner(["--path=web-tutorial", "--delay=2000"]);
await waitForServerAndCli();
const timeCounter = new TimeCounter();
const users = await fetch("/api/users");
timeCounter.stop();
expect(users.body).toEqual([
{ id: 1, name: "John Doe" },
{ id: 2, name: "Jane Doe" },
]);
expect(mocks.currentScreen).toEqual(expect.stringContaining("Delay: 2000"));
expect(timeCounter.total).toBeGreaterThan(1999);
});
});

describe("log option", () => {
it("should set log level", async () => {
mocks = mocksRunner(["--path=web-tutorial", "--log=debug"]);
await waitForServerAndCli();
expect(mocks.currentScreen).toEqual(expect.stringContaining("Log level: debug"));
});
});
});
Loading

0 comments on commit 4efc891

Please sign in to comment.