@ondc/automation-mock-runner 1.3.18 → 1.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { Logger } from "./utils/logger";
4
4
  import { ExecutionResult } from "./types/execution-results";
5
5
  export declare class MockRunner {
6
6
  private config;
7
- private runner;
7
+ private static sharedRunner;
8
8
  logger: Logger;
9
9
  constructor(config: MockPlaygroundConfigType, skipValidation?: boolean);
10
10
  getRunnerInstance(): BaseCodeRunner;
@@ -38,11 +38,12 @@ class MockRunner {
38
38
  }
39
39
  getRunnerInstance() {
40
40
  this.logger.debug("Getting code runner instance");
41
- if (!this.runner) {
42
- this.runner = runner_factory_1.RunnerFactory.createRunner({}, this.logger);
41
+ if (!MockRunner.sharedRunner) {
42
+ MockRunner.sharedRunner = runner_factory_1.RunnerFactory.createRunner({}, this.logger);
43
43
  }
44
- this.logger.debug("Code runner instance obtained successfully: " + this.runner.toString());
45
- return this.runner;
44
+ this.logger.debug("Code runner instance obtained successfully: " +
45
+ MockRunner.sharedRunner.toString());
46
+ return MockRunner.sharedRunner;
46
47
  }
47
48
  getConfig() {
48
49
  return this.config;
@@ -43,6 +43,31 @@ describe("MockRunner", () => {
43
43
  expect(mockRunner).toBeDefined();
44
44
  expect(mockRunner).toBeInstanceOf(MockRunner_1.MockRunner);
45
45
  });
46
+ it("should reuse the same BaseCodeRunner across MockRunner instances", async () => {
47
+ const baseConfig = {
48
+ meta: {
49
+ domain: "ONDC:TRV14",
50
+ version: "2.0.0",
51
+ flowId: "singleton-test",
52
+ },
53
+ transaction_data: {
54
+ transaction_id: "11111111-1111-1111-1111-111111111111",
55
+ latest_timestamp: "1970-01-01T00:00:00.000Z",
56
+ },
57
+ steps: [],
58
+ transaction_history: [],
59
+ validationLib: "",
60
+ helperLib: "",
61
+ };
62
+ const firstRunner = new MockRunner_1.MockRunner(baseConfig, true);
63
+ firstRunner
64
+ .getConfig()
65
+ .steps.push(firstRunner.getDefaultStep("search", "search_0"));
66
+ const optimizedConfig = await (0, configHelper_1.createOptimizedMockConfig)(firstRunner.getConfig());
67
+ const mockRunnerA = new MockRunner_1.MockRunner(optimizedConfig, true);
68
+ const mockRunnerB = new MockRunner_1.MockRunner(optimizedConfig, true);
69
+ expect(mockRunnerA.getRunnerInstance()).toBe(mockRunnerB.getRunnerInstance());
70
+ });
46
71
  });
47
72
  describe("Config Validation", () => {
48
73
  it("should validate correct config successfully", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ondc/automation-mock-runner",
3
- "version": "1.3.18",
3
+ "version": "1.3.19",
4
4
  "description": "A TypeScript library for ONDC automation mock runner",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",