specmatic 2.12.0 → 2.13.2
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/.github/workflows/test.yml +2 -1
- package/README.md +2 -39
- package/dist/bin/command.line.d.ts +1 -1
- package/dist/bin/command.line.js +4 -48
- package/dist/common/runner.d.ts +2 -4
- package/dist/common/runner.js +17 -17
- package/dist/config.d.ts +0 -2
- package/dist/config.js +2 -4
- package/dist/core/index.js +22 -12
- package/dist/index.d.ts +0 -2
- package/dist/index.js +1 -75
- package/package.json +3 -6
- package/specmatic.jar +0 -0
- package/src/bin/__tests__/command.line.ts +5 -83
- package/src/bin/command.line.ts +5 -34
- package/src/common/runner.ts +12 -23
- package/src/config.ts +0 -2
- package/src/core/__tests__/print.jar.version.ts +2 -2
- package/src/core/__tests__/stub.ts +38 -46
- package/src/core/__tests__/test.ts +10 -10
- package/src/core/index.ts +16 -16
- package/src/index.ts +0 -16
- package/dist/graphql/index.d.ts +0 -11
- package/dist/graphql/index.js +0 -126
- package/dist/kafka/index.d.ts +0 -13
- package/dist/kafka/index.js +0 -152
- package/src/graphql/index.ts +0 -114
- package/src/kafka/__tests__/kafkaStub.ts +0 -62
- package/src/kafka/index.ts +0 -140
package/src/bin/command.line.ts
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
import logger from '../common/logger'
|
|
2
|
-
import {
|
|
3
|
-
import yargs from 'yargs/yargs';
|
|
4
|
-
import { hideBin } from 'yargs/helpers';
|
|
2
|
+
import { callCore} from '../common/runner'
|
|
5
3
|
|
|
6
|
-
const callSpecmaticCli = (
|
|
7
|
-
args =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
'boolean-negation': false,
|
|
11
|
-
'parse-numbers': false,
|
|
12
|
-
'dot-notation': false,
|
|
13
|
-
'short-option-groups': false
|
|
14
|
-
}).parseSync();
|
|
15
|
-
const { _, $0, ...namedArgs } = argv;
|
|
16
|
-
const fn = getJarFunction(_);
|
|
17
|
-
const command = (_.join(' ') + ' ' + Object.entries(namedArgs).map(([key, value]) => `--${key}="${String(value)}"`).join(' ')).trim();
|
|
18
|
-
logger.info(`CLI: Running with args "${command}"`);
|
|
19
|
-
fn(
|
|
20
|
-
command,
|
|
4
|
+
const callSpecmaticCli = (argsv?: string[]) => {
|
|
5
|
+
const args = argsv || process.argv.slice(2);
|
|
6
|
+
callCore(
|
|
7
|
+
args,
|
|
21
8
|
(err?: any) => {
|
|
22
9
|
if (err) {
|
|
23
10
|
logger.info('CLI: Finished with non zero exit code: ', err.code)
|
|
@@ -33,20 +20,4 @@ const callSpecmaticCli = (args?: string[]) => {
|
|
|
33
20
|
);
|
|
34
21
|
}
|
|
35
22
|
|
|
36
|
-
function getJarFunction(operation: any[]) {
|
|
37
|
-
if(operation.length > 0) {
|
|
38
|
-
switch (String(operation[0])) {
|
|
39
|
-
case 'kafka':
|
|
40
|
-
operation.splice(0,1);
|
|
41
|
-
return callKafka
|
|
42
|
-
case 'graphql':
|
|
43
|
-
operation.splice(0,1);
|
|
44
|
-
return callGraphQl
|
|
45
|
-
default:
|
|
46
|
-
return callCore
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return callCore
|
|
50
|
-
}
|
|
51
|
-
|
|
52
23
|
export default callSpecmaticCli
|
package/src/common/runner.ts
CHANGED
|
@@ -1,37 +1,26 @@
|
|
|
1
1
|
import execSh from 'exec-sh';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { specmaticCoreJarName
|
|
3
|
+
import { specmaticCoreJarName } from '../config';
|
|
4
4
|
import logger from '../common/logger';
|
|
5
|
-
import { ChildProcess, spawn, SpawnOptions } from 'child_process';
|
|
5
|
+
import { ChildProcess, exec, spawn, SpawnOptions } from 'child_process';
|
|
6
6
|
|
|
7
|
-
const callCore = (args: string, done: (error: any) => void, onOutput: (message: string, error: boolean) => void): ChildProcess => {
|
|
7
|
+
const callCore = (args: (string | number)[], done: (error: any) => void, onOutput: (message: string, error: boolean) => void): ChildProcess => {
|
|
8
8
|
const rootPath = path.resolve(__dirname, '..', '..');
|
|
9
9
|
const specmaticJarPath = path.resolve(rootPath, specmaticCoreJarName);
|
|
10
|
-
logger.debug(`CLI: Specmatic jar path: ${specmaticJarPath}`);
|
|
11
10
|
return callJar(specmaticJarPath, args, done, onOutput);
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const specmaticJarPath = path.resolve(rootPath, specmaticKafkaJarName);
|
|
17
|
-
logger.debug(`CLI: Specmatic jar path: ${specmaticJarPath}`);
|
|
18
|
-
return callJar(specmaticJarPath, args, done, onOutput);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const callGraphQl = (args: string, done: (error: any) => void, onOutput: (message: string, error: boolean) => void): ChildProcess => {
|
|
22
|
-
const rootPath = path.resolve(__dirname, '..', '..', '..', 'specmatic-commercial', 'graphql');
|
|
23
|
-
const specmaticJarPath = path.resolve(rootPath, specmaticGraphQlJarName);
|
|
24
|
-
logger.debug(`CLI: Specmatic jar path: ${specmaticJarPath}`);
|
|
25
|
-
return callJar(specmaticJarPath, args, done, onOutput);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function callJar(jarPath: string, args: string, done: (error: any) => void, onOutput: (message: string, error: boolean) => void) {
|
|
29
|
-
let argsList = [];
|
|
13
|
+
function callJar(jarPath: string, args: (string | number)[], done: (error: any) => void, onOutput: (message: string, error: boolean) => void) {
|
|
14
|
+
const argsList: string[] = [];
|
|
30
15
|
if (process.env['endpointsAPI']) {
|
|
31
16
|
argsList.push(`-DendpointsAPI="${process.env['endpointsAPI']}"`);
|
|
32
17
|
}
|
|
33
|
-
argsList
|
|
34
|
-
|
|
18
|
+
argsList.push(...['-jar', jarPath]);
|
|
19
|
+
argsList.push(...args.map(arg => String(arg)));
|
|
20
|
+
const prettyPrintedCLIArgs = [`java`, ...argsList].map(arg => JSON.stringify(arg)).join(' ');
|
|
21
|
+
|
|
22
|
+
logger.info(`CLI: Running command: ${prettyPrintedCLIArgs}`);
|
|
23
|
+
const javaProcess: ChildProcess = spawn('java', argsList, { stdio: 'pipe', stderr: 'pipe', shell: false, env: process.env } as SpawnOptions);
|
|
35
24
|
javaProcess.stdout?.on('data', function (data: String) {
|
|
36
25
|
onOutput(`${data}`, false);
|
|
37
26
|
});
|
|
@@ -48,4 +37,4 @@ function callJar(jarPath: string, args: string, done: (error: any) => void, onOu
|
|
|
48
37
|
return javaProcess;
|
|
49
38
|
}
|
|
50
39
|
|
|
51
|
-
export { callCore
|
|
40
|
+
export { callCore };
|
package/src/config.ts
CHANGED
|
@@ -23,6 +23,6 @@ test('prints bundled jar version', () => {
|
|
|
23
23
|
|
|
24
24
|
specmatic.printJarVersion();
|
|
25
25
|
|
|
26
|
-
expect(spawn.mock.calls[0][
|
|
27
|
-
expect(spawn.mock.calls[0][1]
|
|
26
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
27
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), `--version`]);
|
|
28
28
|
});
|
|
@@ -40,8 +40,8 @@ test('should be able to parse stub port on random assignment', async () => {
|
|
|
40
40
|
|
|
41
41
|
await expect(specmatic.startStub()).resolves.toStrictEqual(new Stub(HOST, 1234, `http://${HOST}:1234`, javaProcessMock));
|
|
42
42
|
|
|
43
|
-
expect(spawn.mock.calls[0][
|
|
44
|
-
expect(spawn.mock.calls[0][1]
|
|
43
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
44
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub"]);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
|
|
@@ -55,8 +55,8 @@ test('should stick to random port assignment even if later logs contradict it',
|
|
|
55
55
|
|
|
56
56
|
await expect(specmatic.startStub()).resolves.toStrictEqual(new Stub(HOST, 1234, `http://${HOST}:1234`, javaProcessMock));
|
|
57
57
|
|
|
58
|
-
expect(spawn.mock.calls[0][
|
|
59
|
-
expect(spawn.mock.calls[0][1]
|
|
58
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
59
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub"]);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
|
|
@@ -70,8 +70,8 @@ test('should stick to passed port assignment even if final log contradicts it',
|
|
|
70
70
|
|
|
71
71
|
await expect(specmatic.startStub(HOST, 1234)).resolves.toStrictEqual(new Stub(HOST, 1234, `http://${HOST}:1234`, javaProcessMock));
|
|
72
72
|
|
|
73
|
-
expect(spawn.mock.calls[0][
|
|
74
|
-
expect(spawn.mock.calls[0][1]
|
|
73
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
74
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=1234`]);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
test('should be able to parse stub port even if the multi base url has postfix paths', async () => {
|
|
@@ -83,8 +83,8 @@ test('should be able to parse stub port even if the multi base url has postfix p
|
|
|
83
83
|
|
|
84
84
|
await expect(specmatic.startStub(HOST, 1234)).resolves.toStrictEqual(new Stub(HOST, 1234, `http://${HOST}:1234/api`, javaProcessMock));
|
|
85
85
|
|
|
86
|
-
expect(spawn.mock.calls[0][
|
|
87
|
-
expect(spawn.mock.calls[0][1]
|
|
86
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
87
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=1234`]);
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
|
|
@@ -97,8 +97,8 @@ test('should be able to parse stub port even if the multi base url has postfix p
|
|
|
97
97
|
|
|
98
98
|
await expect(specmatic.startStub(HOST, 1234)).resolves.toStrictEqual(new Stub(HOST, 1234, `http://${HOST}:1234/api`, javaProcessMock));
|
|
99
99
|
|
|
100
|
-
expect(spawn.mock.calls[0][
|
|
101
|
-
expect(spawn.mock.calls[0][1]
|
|
100
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
101
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=1234`]);
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
test('should use the default http or https port when no port is specified in the multi base url logs', async () => {
|
|
@@ -110,8 +110,8 @@ test('should use the default http or https port when no port is specified in the
|
|
|
110
110
|
|
|
111
111
|
await expect(specmatic.startStub(HOST)).resolves.toStrictEqual(new Stub(HOST, 80, `http://${HOST}:80/api`, javaProcessMock));
|
|
112
112
|
|
|
113
|
-
expect(spawn.mock.calls[0][
|
|
114
|
-
expect(spawn.mock.calls[0][1]
|
|
113
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
114
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`]);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
test('should fail if specified port in logs is out of valid range', async () => {
|
|
@@ -138,16 +138,16 @@ test('should pick the first port when multi-port stub is being used', async () =
|
|
|
138
138
|
" 1. ./simple9002.yaml",
|
|
139
139
|
" 2. ./simple9002Second.yaml"
|
|
140
140
|
];
|
|
141
|
-
|
|
141
|
+
|
|
142
142
|
setTimeout(() => {
|
|
143
143
|
const messageCallback = readableMock.on.mock.calls[0][1];
|
|
144
144
|
messages.forEach(messageCallback);
|
|
145
|
-
}, 0);
|
|
145
|
+
}, 0);
|
|
146
146
|
|
|
147
147
|
await expect(specmatic.startStub()).resolves.toStrictEqual(new Stub(HOST, 1234, `http://${HOST}:1234`, javaProcessMock));
|
|
148
148
|
|
|
149
|
-
expect(spawn.mock.calls[0][
|
|
150
|
-
expect(spawn.mock.calls[0][1]
|
|
149
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
150
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub"]);
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
test('test with multi port stub and random port assignment', async () => {
|
|
@@ -161,16 +161,16 @@ test('test with multi port stub and random port assignment', async () => {
|
|
|
161
161
|
"!@! http://localhost:9001 serving endpoints from specs #$!",
|
|
162
162
|
" 1. ./simple9001.yaml",
|
|
163
163
|
];
|
|
164
|
-
|
|
164
|
+
|
|
165
165
|
setTimeout(() => {
|
|
166
166
|
const messageCallback = readableMock.on.mock.calls[0][1];
|
|
167
167
|
messages.forEach(messageCallback);
|
|
168
|
-
}, 0);
|
|
168
|
+
}, 0);
|
|
169
169
|
|
|
170
170
|
await expect(specmatic.startStub()).resolves.toStrictEqual(new Stub(HOST, 1234, `http://${HOST}:1234`, javaProcessMock));
|
|
171
171
|
|
|
172
|
-
expect(spawn.mock.calls[0][
|
|
173
|
-
expect(spawn.mock.calls[0][1]
|
|
172
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
173
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), "stub"]);
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
test('starts the specmatic stub server', async () => {
|
|
@@ -179,8 +179,8 @@ test('starts the specmatic stub server', async () => {
|
|
|
179
179
|
|
|
180
180
|
await expect(specmatic.startStub(HOST, PORT)).resolves.toStrictEqual(stub);
|
|
181
181
|
|
|
182
|
-
expect(spawn.mock.calls[0][
|
|
183
|
-
expect(spawn.mock.calls[0][1]
|
|
182
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
183
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=${PORT}`]);
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
test('starts the specmatic stub server with leading and trailing garbage values', async () => {
|
|
@@ -189,8 +189,8 @@ test('starts the specmatic stub server with leading and trailing garbage values'
|
|
|
189
189
|
|
|
190
190
|
await expect(specmatic.startStub(HOST, PORT)).resolves.toStrictEqual(stub);
|
|
191
191
|
|
|
192
|
-
expect(spawn.mock.calls[0][
|
|
193
|
-
expect(spawn.mock.calls[0][1]
|
|
192
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
193
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=${PORT}`]);
|
|
194
194
|
});
|
|
195
195
|
|
|
196
196
|
test('notifies when start fails due to port not available', async () => {
|
|
@@ -199,8 +199,8 @@ test('notifies when start fails due to port not available', async () => {
|
|
|
199
199
|
|
|
200
200
|
await expect(specmatic.startStub(HOST, PORT)).toReject();
|
|
201
201
|
|
|
202
|
-
expect(spawn.mock.calls[0][
|
|
203
|
-
expect(spawn.mock.calls[0][1]
|
|
202
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
203
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=${PORT}`]);
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
test('returns host, port and stub url', async () => {
|
|
@@ -215,8 +215,8 @@ test('returns host, port and stub url', async () => {
|
|
|
215
215
|
|
|
216
216
|
await expect(specmatic.startStub(HOST, PORT)).resolves.toStrictEqual(stub);
|
|
217
217
|
|
|
218
|
-
expect(spawn.mock.calls[0][
|
|
219
|
-
expect(spawn.mock.calls[0][1]
|
|
218
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
219
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=${PORT}`]);
|
|
220
220
|
});
|
|
221
221
|
|
|
222
222
|
test('fails if stub url is not available in start up message', async () => {
|
|
@@ -225,8 +225,9 @@ test('fails if stub url is not available in start up message', async () => {
|
|
|
225
225
|
|
|
226
226
|
await expect(specmatic.startStub(HOST, PORT)).toReject();
|
|
227
227
|
|
|
228
|
-
expect(spawn.mock.calls[0][
|
|
229
|
-
expect(spawn.mock.calls[0][1]
|
|
228
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
229
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=${PORT}`]);
|
|
230
|
+
|
|
230
231
|
});
|
|
231
232
|
|
|
232
233
|
test('fails if host info is not available in start up message', async () => {
|
|
@@ -236,8 +237,8 @@ test('fails if host info is not available in start up message', async () => {
|
|
|
236
237
|
|
|
237
238
|
await expect(specmatic.startStub(HOST, PORT)).toReject();
|
|
238
239
|
|
|
239
|
-
expect(spawn.mock.calls[0][
|
|
240
|
-
expect(spawn.mock.calls[0][1]
|
|
240
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
241
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=${PORT}`]);
|
|
241
242
|
});
|
|
242
243
|
|
|
243
244
|
test('host and port are optional', async () => {
|
|
@@ -246,18 +247,8 @@ test('host and port are optional', async () => {
|
|
|
246
247
|
|
|
247
248
|
await expect(specmatic.startStub()).resolves.toStrictEqual(stub);
|
|
248
249
|
|
|
249
|
-
expect(spawn.mock.calls[0][
|
|
250
|
-
expect(spawn.mock.calls[0][1]
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test('takes additional pass through arguments', async () => {
|
|
254
|
-
spawn.mockReturnValue(javaProcessMock);
|
|
255
|
-
setTimeout(() => readableMock.on.mock.calls[0][1](`- ${stubUrl} serving endpoints from specs:`), 0);
|
|
256
|
-
|
|
257
|
-
await expect(specmatic.startStub(HOST, PORT, ['p1', 'p2'])).resolves.toStrictEqual(stub);
|
|
258
|
-
|
|
259
|
-
expect(spawn.mock.calls[0][1][1]).toBe(`"${path.resolve(SPECMATIC_JAR_PATH)}"`);
|
|
260
|
-
expect(spawn.mock.calls[0][1][2]).toBe(`stub --host=${HOST} --port=${PORT} p1 p2`);
|
|
250
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
251
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub"]);
|
|
261
252
|
});
|
|
262
253
|
|
|
263
254
|
test('additional pass through arguments can be string or number', async () => {
|
|
@@ -266,8 +257,9 @@ test('additional pass through arguments can be string or number', async () => {
|
|
|
266
257
|
|
|
267
258
|
await expect(specmatic.startStub(HOST, PORT, ['p1', 123])).resolves.toStrictEqual(stub);
|
|
268
259
|
|
|
269
|
-
|
|
270
|
-
expect(spawn.mock.calls[0][
|
|
260
|
+
|
|
261
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
262
|
+
expect(spawn.mock.calls[0][1]).toEqual(['-jar', path.resolve(SPECMATIC_JAR_PATH), "stub", `--host=${HOST}`, `--port=${PORT}`, "p1", "123"]);
|
|
271
263
|
});
|
|
272
264
|
|
|
273
265
|
test('stopStub method stops any running stub server', async () => {
|
|
@@ -34,8 +34,8 @@ test('runs the contract tests', async function () {
|
|
|
34
34
|
|
|
35
35
|
await expect(specmatic.test(HOST, PORT, CONTRACT_FILE_PATH)).resolves.toBeTruthy();
|
|
36
36
|
|
|
37
|
-
expect(spawn.mock.calls[0][
|
|
38
|
-
expect(spawn.mock.calls[0][1]
|
|
37
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
38
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), 'test', path.resolve(CONTRACT_FILE_PATH), '--junitReportDir=dist/test-report', `--host=${HOST}`, `--port=${PORT}`]);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
test('takes additional pass through arguments', async () => {
|
|
@@ -47,8 +47,8 @@ test('takes additional pass through arguments', async () => {
|
|
|
47
47
|
|
|
48
48
|
await expect(specmatic.test(HOST, PORT, CONTRACT_FILE_PATH, ['P1', 'P2'])).resolves.toBeTruthy();
|
|
49
49
|
|
|
50
|
-
expect(spawn.mock.calls[0][
|
|
51
|
-
expect(spawn.mock.calls[0][1]
|
|
50
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
51
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), 'test', path.resolve(CONTRACT_FILE_PATH), '--junitReportDir=dist/test-report', `--host=${HOST}`, `--port=${PORT}`, 'P1', 'P2']);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
test('additional pass through arguments can be string or number', async () => {
|
|
@@ -60,8 +60,8 @@ test('additional pass through arguments can be string or number', async () => {
|
|
|
60
60
|
|
|
61
61
|
await expect(specmatic.test(HOST, PORT, CONTRACT_FILE_PATH, ['P1', 123])).resolves.toBeTruthy();
|
|
62
62
|
|
|
63
|
-
expect(spawn.mock.calls[0][
|
|
64
|
-
expect(spawn.mock.calls[0][1]
|
|
63
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
64
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), 'test', path.resolve(CONTRACT_FILE_PATH), '--junitReportDir=dist/test-report', `--host=${HOST}`, `--port=${PORT}`, 'P1', '123']);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
test('runs the contract tests with host and port optional', async function () {
|
|
@@ -73,8 +73,8 @@ test('runs the contract tests with host and port optional', async function () {
|
|
|
73
73
|
|
|
74
74
|
await expect(specmatic.test()).resolves.toBeTruthy();
|
|
75
75
|
|
|
76
|
-
expect(spawn.mock.calls[0][
|
|
77
|
-
expect(spawn.mock.calls[0][1]
|
|
76
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
77
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), 'test', '--junitReportDir=dist/test-report']);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
test('runs the contract tests with contracts path optional', async function () {
|
|
@@ -86,8 +86,8 @@ test('runs the contract tests with contracts path optional', async function () {
|
|
|
86
86
|
|
|
87
87
|
await expect(specmatic.test(HOST, PORT)).resolves.toBeTruthy();
|
|
88
88
|
|
|
89
|
-
expect(spawn.mock.calls[0][
|
|
90
|
-
expect(spawn.mock.calls[0][1]
|
|
89
|
+
expect(spawn.mock.calls[0][0]).toBe(`java`);
|
|
90
|
+
expect(spawn.mock.calls[0][1]).toEqual([`-jar`, path.resolve(SPECMATIC_JAR_PATH), 'test', '--junitReportDir=dist/test-report', `--host=${HOST}`, `--port=${PORT}`]);
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
test('runs the contract tests and returns a summary', async function () {
|
package/src/core/index.ts
CHANGED
|
@@ -27,10 +27,10 @@ export class Stub {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const startStub = (host?: string, port?: number, args?: (string | number)[]): Promise<Stub> => {
|
|
30
|
-
var cmd = `stub`
|
|
31
|
-
if (host) cmd
|
|
32
|
-
if (port) cmd
|
|
33
|
-
if (args) cmd
|
|
30
|
+
var cmd = [`stub`]
|
|
31
|
+
if (host) cmd .push(`--host=${host}`)
|
|
32
|
+
if (port) cmd .push(`--port=${port}`)
|
|
33
|
+
if (args) cmd .push(...args.map(arg => String(arg)))
|
|
34
34
|
|
|
35
35
|
logger.info('Stub: Starting server')
|
|
36
36
|
logger.debug(`Stub: Executing "${cmd}"`)
|
|
@@ -76,7 +76,7 @@ function extractErrorMessage(error: any): string {
|
|
|
76
76
|
if (typeof error === 'string') {
|
|
77
77
|
return error;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
|
|
80
80
|
if (error instanceof Error) {
|
|
81
81
|
return error.message;
|
|
82
82
|
}
|
|
@@ -91,18 +91,18 @@ function parseStubOutput(
|
|
|
91
91
|
): Stub {
|
|
92
92
|
const url = stubInfo[0].trim();
|
|
93
93
|
const urlInfo = /\b(.*?):\/\/(.*?):?([0-9]+)?(\/.*)?$/.exec(url);
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
if (urlInfo === null || !urlInfo[1] || !urlInfo[2]) {
|
|
96
96
|
throw new Error('Cannot determine host and port from stub output');
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
const protocol = urlInfo[1];
|
|
100
100
|
const host = urlInfo[2];
|
|
101
101
|
const regexPort = urlInfo[3];
|
|
102
102
|
const path = urlInfo[4] || "";
|
|
103
103
|
const defaultPort = protocol === 'http' ? '80' : protocol === 'https' ? '443' : undefined;
|
|
104
104
|
const finalPort = parsedPort ?? regexPort ?? defaultPort;
|
|
105
|
-
|
|
105
|
+
|
|
106
106
|
if (!finalPort) {
|
|
107
107
|
throw new Error('Cannot determine port from stub output');
|
|
108
108
|
}
|
|
@@ -147,12 +147,12 @@ const testWithApiCoverage = async (
|
|
|
147
147
|
const test = (host?: string, port?: number, contractPath?: string, args?: (string | number)[]): Promise<{ [k: string]: number } | undefined> => {
|
|
148
148
|
const specsPath = path.resolve(contractPath + '')
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
if (contractPath) cmd
|
|
152
|
-
cmd
|
|
153
|
-
if (host) cmd
|
|
154
|
-
if (port) cmd
|
|
155
|
-
if (args) cmd
|
|
150
|
+
const cmd = [`test`]
|
|
151
|
+
if (contractPath) cmd.push(specsPath)
|
|
152
|
+
cmd.push('--junitReportDir=dist/test-report')
|
|
153
|
+
if (host) cmd.push(`--host=${host}`)
|
|
154
|
+
if (port) cmd.push(`--port=${port}`)
|
|
155
|
+
if (args) cmd.push(...args.map(arg => String(arg)))
|
|
156
156
|
|
|
157
157
|
logger.info('Test: Running')
|
|
158
158
|
logger.debug(`Test: Executing "${cmd}"`)
|
|
@@ -207,7 +207,7 @@ const setExpectations = (stubPath: string, stubServerBaseUrl?: string): Promise<
|
|
|
207
207
|
|
|
208
208
|
const setExpectationJson = (stubResponse: any, stubServerBaseUrl?: string): Promise<void> => {
|
|
209
209
|
stubServerBaseUrl = stubServerBaseUrl || 'http://localhost:9000'
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
logger.info(`Set Expectations: Stub url is ${stubServerBaseUrl}`)
|
|
212
212
|
|
|
213
213
|
return new Promise((resolve, reject) => {
|
|
@@ -237,7 +237,7 @@ const setExpectationJson = (stubResponse: any, stubServerBaseUrl?: string): Prom
|
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
const printJarVersion = () => {
|
|
240
|
-
const cmd = `--version`
|
|
240
|
+
const cmd = [`--version`]
|
|
241
241
|
logger.info('Print Jar Version: Running')
|
|
242
242
|
logger.debug(`Print Jar Version: Executing "${cmd}"`)
|
|
243
243
|
|
package/src/index.ts
CHANGED
|
@@ -12,19 +12,3 @@ export {
|
|
|
12
12
|
printJarVersion,
|
|
13
13
|
showTestResults,
|
|
14
14
|
} from "./core";
|
|
15
|
-
export {
|
|
16
|
-
startKafkaStub,
|
|
17
|
-
startKafkaStub as startKafkaMock,
|
|
18
|
-
stopKafkaStub,
|
|
19
|
-
stopKafkaStub as stopKafkaMock,
|
|
20
|
-
verifyKafkaStubMessage,
|
|
21
|
-
verifyKafkaStubMessage as verifyKafkaMockMessage,
|
|
22
|
-
verifyKafkaStub,
|
|
23
|
-
verifyKafkaStub as verifyKafkaMock,
|
|
24
|
-
setKafkaStubExpectations,
|
|
25
|
-
setKafkaStubExpectations as setKafkaMockExpectations,
|
|
26
|
-
} from "./kafka";
|
|
27
|
-
export {
|
|
28
|
-
startGraphQlStub,
|
|
29
|
-
stopGraphQlStub,
|
|
30
|
-
} from "./graphql";
|
package/dist/graphql/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess } from "node:child_process";
|
|
2
|
-
export declare class GraphQlStub {
|
|
3
|
-
host: string;
|
|
4
|
-
port: number;
|
|
5
|
-
data?: string;
|
|
6
|
-
process: ChildProcess;
|
|
7
|
-
constructor(host: string, port: number, process: ChildProcess, data?: string);
|
|
8
|
-
}
|
|
9
|
-
declare const startGraphQlStub: (host?: string, port?: string, data?: string, args?: (string | number)[]) => Promise<GraphQlStub>;
|
|
10
|
-
declare const stopGraphQlStub: (graphQlStub: GraphQlStub) => Promise<void>;
|
|
11
|
-
export { startGraphQlStub, stopGraphQlStub };
|