Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logs the mode and description of keploy #75

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions mock/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";
import path, { resolve } from "path";
import { ProtoGrpcType } from "../proto/services";
import Mode, { MODE_TEST } from "../src/mode";
import Mode, { MODE_TEST, MODE_RECORD } from "../src/mode";
import { createExecutionContext, getExecutionContext } from "../src/context";
import { startRecordingMocks } from "./utils";

Expand Down Expand Up @@ -61,8 +61,11 @@ export function NewContext(conf: Config) {
if (Mode.Valid(conf.Mode)) {
mode.SetMode(conf.Mode);
}
console.log("Keploy is running in " + mode.GetMode() + " mode");
modeDescription(mode.GetMode());

switch (mode.GetMode()) {
case "test":
case MODE_TEST:
if (conf.Name === "") {
console.log(
"🚨 Please enter the auto generated name to mock the dependencies using Keploy."
Expand All @@ -84,7 +87,7 @@ export function NewContext(conf: Config) {
return response;
});
break;
case "record":
case MODE_RECORD:
createExecutionContext({
mode: mode.GetMode(),
testId: conf.Name,
Expand Down Expand Up @@ -115,3 +118,23 @@ export function NewContext(conf: Config) {
conf.Name
);
}

function modeDescription(mode: string) {
switch (mode) {
case MODE_RECORD:
console.log(
"This mode will record all the API calls made to the application and store each call as a test in the keploy/tests directory as a yaml file"
);
break;
case MODE_TEST:
console.log(
"This mode will run all the tests stored in the keploy/tests directory and report the results"
);
break;
default:
console.log(
"This mode will not do anything and your application will act normal without any interference from keploy"
);
break;
}
}
25 changes: 24 additions & 1 deletion src/keploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TestCase } from "../proto/services/TestCase";
import { StrArr } from "../proto/services/StrArr";
import assert = require("assert");
import { createExecutionContext, getExecutionContext } from "./context";
import Mode, { MODE_OFF } from "./mode";
import Mode, { MODE_OFF, MODE_RECORD, MODE_TEST } from "./mode";

const PROTO_PATH = "../proto/services.proto";
const packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_PATH));
Expand Down Expand Up @@ -85,6 +85,8 @@ export default class Keploy {
this.responses = {};
this.dependencies = {};
this.mocks = {};
console.log("Keploy is running in " + this.mode.GetMode() + " mode");
this.modeDescription();
}

validateServerConfig({
Expand Down Expand Up @@ -445,4 +447,25 @@ export default class Keploy {
}
);
}

// logs the description of the mode for the user to understand about the mode their application is running in
modeDescription() {
switch (this.mode.GetMode()) {
case MODE_RECORD:
console.log(
"This mode will record all the API calls made to the application and store each call as a test in the keploy/tests directory as a yaml file"
);
break;
case MODE_TEST:
console.log(
"This mode will run all the tests stored in the keploy/tests directory and report the results"
);
break;
default:
console.log(
"This mode will not do anything and your application will act normal without any interference from keploy"
);
break;
}
}
}