specmatic 0.70.0 → 0.70.1

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.
package/README.md CHANGED
@@ -58,14 +58,14 @@ import {
58
58
  } from 'specmatic';
59
59
  ```
60
60
 
61
- `startStub(host?: string, port?: string, stubDir?: string) : Promise<ChildProcess>` <br />
62
- Start the stub server
61
+ `startStub(host?: string, port?: string, args?: (string | number)[]) : Promise<ChildProcess>` <br />
62
+ Start the stub server. Argument `args` values are passed directly to specmatic jar executable.
63
63
 
64
64
  `stopStub(process: ChildProcess)` <br />
65
65
  Stop the stub server
66
66
 
67
- `test(host?: string, port?: string, specs?: string): Promise<boolean>` <br />
68
- Run tests
67
+ `test(host?: string, port?: string, contractPath?: string, args?: (string | number)[]): Promise<boolean>` <br />
68
+ Run tests. Argument `args` values are passed directly to specmatic jar executable.
69
69
 
70
70
  `setExpectations(stubPath: string, stubServerBaseUrl?: string): Promise<boolean>` <br />
71
71
  Set stub expectiona. Stub should be running before invoking this method.
package/dist/lib/index.js CHANGED
@@ -11,12 +11,11 @@ var _fs = _interopRequireDefault(require("fs"));
11
11
  var _logger = _interopRequireDefault(require("../common/logger"));
12
12
  var _runner = _interopRequireDefault(require("../common/runner"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- var startStub = (host, port, stubDir) => {
15
- var stubs = _path.default.resolve(stubDir + '');
14
+ var startStub = (host, port, args) => {
16
15
  var cmd = "stub";
17
- if (stubDir) cmd += " --data=".concat(stubs);
18
16
  if (host) cmd += " --host=".concat(host);
19
17
  if (port) cmd += " --port=".concat(port);
18
+ if (args) cmd += ' ' + args.join(' ');
20
19
  _logger.default.info('Stub: Starting server');
21
20
  _logger.default.debug("Stub: Executing \"".concat(cmd, "\""));
22
21
  return new Promise((resolve, reject) => {
@@ -52,13 +51,14 @@ var stopStub = javaProcess => {
52
51
  _logger.default.info('Stopped stub server');
53
52
  };
54
53
  exports.stopStub = stopStub;
55
- var test = (host, port, specs) => {
56
- var specsPath = _path.default.resolve(specs + '');
54
+ var test = (host, port, contractPath, args) => {
55
+ var specsPath = _path.default.resolve(contractPath + '');
57
56
  var cmd = "test";
58
- if (specs) cmd += " ".concat(specsPath);
57
+ if (contractPath) cmd += " ".concat(specsPath);
59
58
  cmd += ' --junitReportDir=dist/test-report';
60
59
  if (host) cmd += " --host=".concat(host);
61
60
  if (port) cmd += " --port=".concat(port);
61
+ if (args) cmd += ' ' + args.join(' ');
62
62
  _logger.default.info('Test: Running');
63
63
  _logger.default.debug("Test: Executing \"".concat(cmd, "\""));
64
64
  var reportDir = _path.default.resolve('dist/test-report');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "specmatic",
3
- "version": "0.70.0",
3
+ "version": "0.70.1",
4
4
  "description": "Node wrapper for Specmatic",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -18,7 +18,7 @@ const fetchMock = fetch as unknown as jest.Mock;
18
18
 
19
19
  const SPECMATIC_JAR_PATH = path.resolve(__dirname, '..', '..', '..', specmaticJarName);
20
20
  const STUB_PATH = 'test-resources/sample-mock-stub.json';
21
- const CONTRACT_YAML_FILE_PATH = './contracts';
21
+ const CONTRACT_FILE_PATH = './contracts';
22
22
  const STUB_DIR_PATH = './data';
23
23
  const HOST = 'localhost';
24
24
  const PORT = '8000';
@@ -39,11 +39,11 @@ test('startStub method starts the specmatic stub server', async () => {
39
39
  execSh.mockReturnValue(javaProcessMock);
40
40
  setTimeout(() => readableMock.on.mock.calls[0][1]('Stub server is running'), 0);
41
41
 
42
- await expect(specmatic.startStub(HOST, PORT, STUB_DIR_PATH)).resolves.toBe(javaProcessMock);
42
+ await expect(specmatic.startStub(HOST, PORT)).resolves.toBe(javaProcessMock);
43
43
 
44
44
  expect(execSh).toHaveBeenCalledTimes(1);
45
45
  expect(execSh.mock.calls[0][0]).toBe(
46
- `java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --data=${path.resolve(STUB_DIR_PATH)} --host=${HOST} --port=${PORT}`
46
+ `java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --host=${HOST} --port=${PORT}`
47
47
  );
48
48
  });
49
49
 
@@ -51,32 +51,42 @@ test('startStub method notifies when start fails due to port not available', asy
51
51
  execSh.mockReturnValue(javaProcessMock);
52
52
  setTimeout(() => readableMock.on.mock.calls[0][1]('Address already in use'), 0);
53
53
 
54
- await expect(specmatic.startStub(HOST, PORT, STUB_DIR_PATH)).toReject();
54
+ await expect(specmatic.startStub(HOST, PORT)).toReject();
55
55
 
56
56
  expect(execSh).toHaveBeenCalledTimes(1);
57
57
  expect(execSh.mock.calls[0][0]).toBe(
58
- `java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --data=${path.resolve(STUB_DIR_PATH)} --host=${HOST} --port=${PORT}`
58
+ `java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --host=${HOST} --port=${PORT}`
59
59
  );
60
60
  });
61
61
 
62
- test('startStub method stubDir is optional', async () => {
62
+ test('startStub method host and port are optional', async () => {
63
63
  execSh.mockReturnValue(javaProcessMock);
64
64
  setTimeout(() => readableMock.on.mock.calls[0][1]('Stub server is running'), 0);
65
65
 
66
- await expect(specmatic.startStub(HOST, PORT)).resolves.toBe(javaProcessMock);
66
+ await expect(specmatic.startStub()).resolves.toBe(javaProcessMock);
67
67
 
68
68
  expect(execSh).toHaveBeenCalledTimes(1);
69
- expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --host=${HOST} --port=${PORT}`);
69
+ expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub`);
70
70
  });
71
71
 
72
- test('startStub method host and port are optional', async () => {
72
+ test('startStub method takes additional pass through arguments', async () => {
73
73
  execSh.mockReturnValue(javaProcessMock);
74
74
  setTimeout(() => readableMock.on.mock.calls[0][1]('Stub server is running'), 0);
75
75
 
76
- await expect(specmatic.startStub()).resolves.toBe(javaProcessMock);
76
+ await expect(specmatic.startStub(HOST, PORT, ['p1', 'p2'])).resolves.toBe(javaProcessMock);
77
77
 
78
78
  expect(execSh).toHaveBeenCalledTimes(1);
79
- expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub`);
79
+ expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --host=${HOST} --port=${PORT} p1 p2`);
80
+ });
81
+
82
+ test('startStub method takes additional pass through arguments can be string or number', async () => {
83
+ execSh.mockReturnValue(javaProcessMock);
84
+ setTimeout(() => readableMock.on.mock.calls[0][1]('Stub server is running'), 0);
85
+
86
+ await expect(specmatic.startStub(HOST, PORT, ['p1', 123])).resolves.toBe(javaProcessMock);
87
+
88
+ expect(execSh).toHaveBeenCalledTimes(1);
89
+ expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --host=${HOST} --port=${PORT} p1 123`);
80
90
  });
81
91
 
82
92
  test('stopStub method stops any running stub server', () => {
@@ -94,16 +104,50 @@ test('test runs the contract tests', async function () {
94
104
  execSh.mock.calls[0][2]();
95
105
  }, 0);
96
106
 
97
- await expect(specmatic.test(HOST, PORT, CONTRACT_YAML_FILE_PATH)).resolves.toBeTruthy();
107
+ await expect(specmatic.test(HOST, PORT, CONTRACT_FILE_PATH)).resolves.toBeTruthy();
98
108
 
99
109
  expect(execSh).toHaveBeenCalledTimes(1);
100
110
  expect(execSh.mock.calls[0][0]).toBe(
101
111
  `java -jar ${path.resolve(SPECMATIC_JAR_PATH)} test ${path.resolve(
102
- CONTRACT_YAML_FILE_PATH
112
+ CONTRACT_FILE_PATH
103
113
  )} --junitReportDir=dist/test-report --host=${HOST} --port=${PORT}`
104
114
  );
105
115
  });
106
116
 
117
+ test('test takes additional pass through arguments', async () => {
118
+ execSh.mockReturnValue(javaProcessMock);
119
+ setTimeout(() => {
120
+ copyReportFile();
121
+ execSh.mock.calls[0][2]();
122
+ }, 0);
123
+
124
+ await expect(specmatic.test(HOST, PORT, CONTRACT_FILE_PATH, ['P1', 'P2'])).resolves.toBeTruthy();
125
+
126
+ expect(execSh).toHaveBeenCalledTimes(1);
127
+ expect(execSh.mock.calls[0][0]).toBe(
128
+ `java -jar ${path.resolve(SPECMATIC_JAR_PATH)} test ${path.resolve(
129
+ CONTRACT_FILE_PATH
130
+ )} --junitReportDir=dist/test-report --host=${HOST} --port=${PORT} P1 P2`
131
+ );
132
+ });
133
+
134
+ test('test takes additional pass through arguments can be string or number', async () => {
135
+ execSh.mockReturnValue(javaProcessMock);
136
+ setTimeout(() => {
137
+ copyReportFile();
138
+ execSh.mock.calls[0][2]();
139
+ }, 0);
140
+
141
+ await expect(specmatic.test(HOST, PORT, CONTRACT_FILE_PATH, ['P1', 123])).resolves.toBeTruthy();
142
+
143
+ expect(execSh).toHaveBeenCalledTimes(1);
144
+ expect(execSh.mock.calls[0][0]).toBe(
145
+ `java -jar ${path.resolve(SPECMATIC_JAR_PATH)} test ${path.resolve(
146
+ CONTRACT_FILE_PATH
147
+ )} --junitReportDir=dist/test-report --host=${HOST} --port=${PORT} P1 123`
148
+ );
149
+ });
150
+
107
151
  test('test runs the contract tests with host and port optional', async function () {
108
152
  execSh.mockReturnValue(javaProcessMock);
109
153
  setTimeout(() => {
package/src/lib/index.ts CHANGED
@@ -6,13 +6,11 @@ import fs from 'fs';
6
6
  import logger from '../common/logger';
7
7
  import callSpecmatic from '../common/runner';
8
8
 
9
- const startStub = (host?: string, port?: string, stubDir?: string): Promise<ChildProcess> => {
10
- const stubs = path.resolve(stubDir + '');
11
-
9
+ const startStub = (host?: string, port?: string, args?: (string | number)[]): Promise<ChildProcess> => {
12
10
  var cmd = `stub`;
13
- if (stubDir) cmd += ` --data=${stubs}`;
14
11
  if (host) cmd += ` --host=${host}`;
15
12
  if (port) cmd += ` --port=${port}`;
13
+ if (args) cmd += ' ' + args.join(' ');
16
14
 
17
15
  logger.info('Stub: Starting server');
18
16
  logger.debug(`Stub: Executing "${cmd}"`);
@@ -53,14 +51,15 @@ const stopStub = (javaProcess: ChildProcess) => {
53
51
  logger.info('Stopped stub server');
54
52
  };
55
53
 
56
- const test = (host?: string, port?: string, specs?: string): Promise<{ [k: string]: number } | undefined> => {
57
- const specsPath = path.resolve(specs + '');
54
+ const test = (host?: string, port?: string, contractPath?: string, args?: (string|number)[]): Promise<{ [k: string]: number } | undefined> => {
55
+ const specsPath = path.resolve(contractPath + '');
58
56
 
59
57
  var cmd = `test`;
60
- if (specs) cmd += ` ${specsPath}`;
58
+ if (contractPath) cmd += ` ${specsPath}`;
61
59
  cmd += ' --junitReportDir=dist/test-report';
62
60
  if (host) cmd += ` --host=${host}`;
63
61
  if (port) cmd += ` --port=${port}`;
62
+ if (args) cmd += ' ' + args.join(' ');
64
63
 
65
64
  logger.info('Test: Running');
66
65
  logger.debug(`Test: Executing "${cmd}"`);