diff --git a/.npmignore b/.npmignore index ba167c6..8e97e34 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,7 @@ .husky node_modules test +src .eslintcache .eslintrc.cjs .gitignore diff --git a/package-lock.json b/package-lock.json index 19984ff..2d5763e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mockserver-cli", - "version": "0.1.3", + "version": "0.1.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mockserver-cli", - "version": "0.1.3", + "version": "0.1.4", "license": "ISC", "dependencies": { "commander": "^11.1.0", diff --git a/package.json b/package.json index 9fb3bc8..c63da9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bednarik_radek/mockserver-cli", - "version": "0.1.3", + "version": "0.1.4", "description": "CLI utility for Mock-server client. Allows for easy creation/deletion of expectations on the Mock-server instance.", "main": "index.js", "type": "module", diff --git a/src/cli/handlers/clear.handler.ts b/src/cli/handlers/clear.handler.ts index 7471072..44ccf08 100644 --- a/src/cli/handlers/clear.handler.ts +++ b/src/cli/handlers/clear.handler.ts @@ -19,8 +19,11 @@ async function clearExpectations(client: Client, path: string) { } log.trace(`expectations cleared on the server - from path: ${path}`); + + return; } catch (error: any) { log.error("Error clearing expectations:", error); + return null; } } diff --git a/src/cli/handlers/reset.handler.ts b/src/cli/handlers/reset.handler.ts index 8664e01..06939f0 100644 --- a/src/cli/handlers/reset.handler.ts +++ b/src/cli/handlers/reset.handler.ts @@ -2,6 +2,7 @@ import type { OptionValues } from "commander"; import Client from "../../client/client.js"; import { logger } from "../../log/logger.js"; import { globalOptsHandler } from "./globalOpts.handler.js"; +import { SuccessFullRequest } from "mockserver-client/mockServerClient.js"; const log = logger.child({ module: "resetHandler" }); @@ -17,11 +18,13 @@ export async function resetHandler(options: OptionValues) { port: opts["config"]["port"], }); - await client.reset(); + const response = (await client.reset()) as SuccessFullRequest; log.trace("Mockserver reset handler done."); + + return response; } catch (error: any) { log.error(error.message); - throw error; + return null; } } diff --git a/src/cli/handlers/set.handler.ts b/src/cli/handlers/set.handler.ts index 6018e99..0f2a271 100644 --- a/src/cli/handlers/set.handler.ts +++ b/src/cli/handlers/set.handler.ts @@ -6,18 +6,18 @@ import { logger } from "../../log/logger.js"; import { resolve } from "path"; import type { OptionValues } from "commander"; import type { Expectation } from "mockserver-client"; +import { SuccessFullRequest } from "mockserver-client/mockServerClient.js"; const log = logger.child({ module: "setHandler" }); async function setExpectations(client: Client, expectations: Expectation | Expectation[]) { try { - log.trace(`will set expectations: ${JSON.stringify(expectations)}`); + const response = (await client.set(expectations)) as SuccessFullRequest; - await client.set(expectations); - - log.trace("expectations set"); + return response; } catch (error: any) { log.error("Error setting expectations:", error); + return null; } } diff --git a/src/client/client.ts b/src/client/client.ts index 03697c3..067c1fa 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -1,5 +1,10 @@ import { mockServerClient } from "mockserver-client"; -import type { MockServerClient, PathOrRequestDefinition, ClearType } from "mockserver-client/mockServerClient.js"; +import type { + MockServerClient, + PathOrRequestDefinition, + ClearType, + SuccessFullRequest, +} from "mockserver-client/mockServerClient.js"; import type { Expectation } from "mockserver-client/index.js"; import { logger } from "../log/logger.js"; @@ -33,9 +38,11 @@ export default class Client { try { log.trace(`Setting expectations: ${JSON.stringify(expectations)}`); - await this.client.mockAnyResponse(expectations); + const response = (await this.client.mockAnyResponse(expectations)) as SuccessFullRequest; - log.trace(`Expectations set: ${JSON.stringify(expectations)}`); + log.trace(`Expectations ${JSON.stringify(expectations)} set request response: ${JSON.stringify(response)}`); + + return response; } catch (error: any) { log.error(error.message); throw error; @@ -46,9 +53,15 @@ export default class Client { try { log.trace(`Clearing expectation: ${JSON.stringify({ pathOrRequestDefinition, type })}`); - await this.client.clear(pathOrRequestDefinition, type); + const response = (await this.client.clear(pathOrRequestDefinition, type)) as SuccessFullRequest; + + log.trace( + `Expectations ${JSON.stringify({ pathOrRequestDefinition, type })} clear request response: ${JSON.stringify( + response, + )}`, + ); - log.trace(`Expectations cleared: ${JSON.stringify({ pathOrRequestDefinition, type })}`); + return response; } catch (error: any) { log.error(error.message); throw error; @@ -59,11 +72,11 @@ export default class Client { try { log.trace("Resetting mockserver"); - const result = await this.client.reset(); + const response = await this.client.reset(); - log.trace("Mockserver reset."); + log.trace(`Mockserver reset request response: ${JSON.stringify(response)}`); - return result; + return response; } catch (error: any) { log.error(error.message); throw error;