specmatic 0.68.0 → 0.68.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/dist/bin/core.js +13 -45
- package/dist/common/runner.js +30 -0
- package/dist/config.js +1 -3
- package/dist/lib/index.js +25 -39
- package/package.json +1 -1
- package/src/bin/__tests__/core.ts +16 -17
- package/src/bin/core.ts +16 -39
- package/src/common/runner.ts +21 -0
- package/src/config.ts +0 -1
- package/src/lib/__tests__/index.ts +12 -9
- package/src/lib/index.ts +49 -45
package/dist/bin/core.js
CHANGED
|
@@ -4,55 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _execSh = _interopRequireDefault(require("exec-sh"));
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _config = require("../config");
|
|
10
7
|
var _logger = _interopRequireDefault(require("../common/logger"));
|
|
11
|
-
var
|
|
12
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _runner = _interopRequireDefault(require("../common/runner"));
|
|
13
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
_logger.default.info("CLI: Running with args \"".concat(cliArgs, "\""));
|
|
22
|
-
(0, _execSh.default)("java -jar ".concat(specmaticJarPath, " ").concat(cliArgs), {}, err => {
|
|
23
|
-
if (err) {
|
|
24
|
-
_logger.default.info('CLI: Finished with non zero exit code: ', err.code);
|
|
25
|
-
process.exitCode = err.code;
|
|
26
|
-
} else {
|
|
27
|
-
_logger.default.info('CLI: Finished');
|
|
28
|
-
process.exitCode = 0;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
return function callSpecmaticCli(_x) {
|
|
33
|
-
return _ref.apply(this, arguments);
|
|
34
|
-
};
|
|
35
|
-
}();
|
|
36
|
-
function getSpecmaticJarPath() {
|
|
37
|
-
return new Promise((resolve, _reject) => {
|
|
38
|
-
var specmaticJarPath = _path.default.resolve(_config.specmaticJarPathLocal);
|
|
39
|
-
resolve(specmaticJarPath);
|
|
40
|
-
}).then(specmaticJarPath => {
|
|
41
|
-
if (!_fs.default.existsSync(specmaticJarPath)) {
|
|
42
|
-
return getGlobalSpecmaticJarPath();
|
|
10
|
+
var callSpecmaticCli = args => {
|
|
11
|
+
var cliArgs = (args || process.argv).slice(2).join(' ');
|
|
12
|
+
_logger.default.info("CLI: Running with args \"".concat(cliArgs, "\""));
|
|
13
|
+
(0, _runner.default)(cliArgs, err => {
|
|
14
|
+
if (err) {
|
|
15
|
+
_logger.default.info('CLI: Finished with non zero exit code: ', err.code);
|
|
16
|
+
process.exitCode = err.code;
|
|
43
17
|
} else {
|
|
44
|
-
|
|
18
|
+
_logger.default.info('CLI: Finished');
|
|
19
|
+
process.exitCode = 0;
|
|
45
20
|
}
|
|
21
|
+
}, message => {
|
|
22
|
+
console.log("".concat(message));
|
|
46
23
|
});
|
|
47
|
-
}
|
|
48
|
-
function getGlobalSpecmaticJarPath() {
|
|
49
|
-
return new Promise((resolve, _reject) => {
|
|
50
|
-
(0, _child_process.exec)('npm root -g', (_err, stdout) => {
|
|
51
|
-
var npmGlobalModuleInstallPath = stdout.replace(/\n/g, '');
|
|
52
|
-
var jarPath = _path.default.join(npmGlobalModuleInstallPath, 'specmatic', _config.specmaticJarName);
|
|
53
|
-
resolve(jarPath);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
24
|
+
};
|
|
57
25
|
var _default = callSpecmaticCli;
|
|
58
26
|
exports.default = _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _execSh = _interopRequireDefault(require("exec-sh"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _config = require("../config");
|
|
10
|
+
var _logger = _interopRequireDefault(require("../common/logger"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
var callSpecmatic = (args, done, onOutput) => {
|
|
13
|
+
var _javaProcess$stdout, _javaProcess$stderr;
|
|
14
|
+
var rootPath = _path.default.resolve(__dirname, '..', '..');
|
|
15
|
+
var specmaticJarPath = _path.default.resolve(rootPath, _config.specmaticJarName);
|
|
16
|
+
_logger.default.debug("CLI: Specmatic jar path: ".concat(specmaticJarPath));
|
|
17
|
+
var javaProcess = (0, _execSh.default)("java -jar ".concat(specmaticJarPath, " ").concat(args), {
|
|
18
|
+
stdio: 'pipe',
|
|
19
|
+
stderr: 'pipe'
|
|
20
|
+
}, done);
|
|
21
|
+
(_javaProcess$stdout = javaProcess.stdout) === null || _javaProcess$stdout === void 0 ? void 0 : _javaProcess$stdout.on('data', function (data) {
|
|
22
|
+
onOutput("".concat(data), false);
|
|
23
|
+
});
|
|
24
|
+
(_javaProcess$stderr = javaProcess.stderr) === null || _javaProcess$stderr === void 0 ? void 0 : _javaProcess$stderr.on('data', function (data) {
|
|
25
|
+
onOutput("".concat(data), true);
|
|
26
|
+
});
|
|
27
|
+
return javaProcess;
|
|
28
|
+
};
|
|
29
|
+
var _default = callSpecmatic;
|
|
30
|
+
exports.default = _default;
|
package/dist/config.js
CHANGED
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.specmaticJarPathRemote = exports.
|
|
6
|
+
exports.specmaticJarPathRemote = exports.specmaticJarName = exports.specmatic = void 0;
|
|
7
7
|
var specmaticJarName = 'specmatic.jar';
|
|
8
8
|
exports.specmaticJarName = specmaticJarName;
|
|
9
|
-
var specmaticJarPathLocal = "./node_modules/specmatic/".concat(specmaticJarName);
|
|
10
|
-
exports.specmaticJarPathLocal = specmaticJarPathLocal;
|
|
11
9
|
var specmaticJarPathRemote = 'https://github.com/znsio/specmatic/releases/download/0.24.2/specmatic.jar';
|
|
12
10
|
exports.specmaticJarPathRemote = specmaticJarPathRemote;
|
|
13
11
|
var specmatic = 'specmatic.json';
|
package/dist/lib/index.js
CHANGED
|
@@ -6,44 +6,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.test = exports.stopStub = exports.startStub = exports.showTestResults = exports.setExpectations = exports.printJarVersion = void 0;
|
|
7
7
|
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _execSh = _interopRequireDefault(require("exec-sh"));
|
|
10
|
-
var _config = require("../config");
|
|
11
9
|
var _fastXmlParser = require("fast-xml-parser");
|
|
12
10
|
var _fs = _interopRequireDefault(require("fs"));
|
|
13
11
|
var _logger = _interopRequireDefault(require("../common/logger"));
|
|
12
|
+
var _runner = _interopRequireDefault(require("../common/runner"));
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
var specmaticJarPath = _path.default.resolve(_config.specmaticJarPathLocal);
|
|
16
14
|
var startStub = (host, port, stubDir) => {
|
|
17
15
|
var stubs = _path.default.resolve(stubDir + '');
|
|
18
|
-
var cmd = "
|
|
16
|
+
var cmd = "stub";
|
|
19
17
|
if (stubDir) cmd += " --data=".concat(stubs);
|
|
20
18
|
if (host) cmd += " --host=".concat(host);
|
|
21
19
|
if (port) cmd += " --port=".concat(port);
|
|
22
20
|
_logger.default.info('Stub: Starting server');
|
|
23
21
|
_logger.default.debug("Stub: Executing \"".concat(cmd, "\""));
|
|
24
22
|
return new Promise((resolve, reject) => {
|
|
25
|
-
var javaProcess = (0,
|
|
26
|
-
stdio: 'pipe',
|
|
27
|
-
stderr: 'pipe'
|
|
28
|
-
}, err => {
|
|
23
|
+
var javaProcess = (0, _runner.default)(cmd, err => {
|
|
29
24
|
if (err) {
|
|
30
25
|
_logger.default.error("Stub: Exited with error ".concat(err));
|
|
31
26
|
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
}, (message, error) => {
|
|
28
|
+
if (!error) {
|
|
29
|
+
if (message.indexOf('Stub server is running') > -1) {
|
|
30
|
+
_logger.default.info("Stub: ".concat(message));
|
|
31
|
+
resolve(javaProcess);
|
|
32
|
+
} else if (message.indexOf('Address already in use') > -1) {
|
|
33
|
+
_logger.default.error("Stub: ".concat(message));
|
|
34
|
+
reject();
|
|
35
|
+
} else {
|
|
36
|
+
_logger.default.debug("Stub: ".concat(message));
|
|
37
|
+
}
|
|
40
38
|
} else {
|
|
41
|
-
_logger.default.
|
|
39
|
+
_logger.default.error("Stub: ".concat(message));
|
|
42
40
|
}
|
|
43
41
|
});
|
|
44
|
-
javaProcess.stderr.on('data', function (data) {
|
|
45
|
-
_logger.default.error("Stub: ".concat(data));
|
|
46
|
-
});
|
|
47
42
|
});
|
|
48
43
|
};
|
|
49
44
|
exports.startStub = startStub;
|
|
@@ -59,7 +54,7 @@ var stopStub = javaProcess => {
|
|
|
59
54
|
exports.stopStub = stopStub;
|
|
60
55
|
var test = (host, port, specs) => {
|
|
61
56
|
var specsPath = _path.default.resolve(specs + '');
|
|
62
|
-
var cmd = "
|
|
57
|
+
var cmd = "test";
|
|
63
58
|
if (specs) cmd += " ".concat(specsPath);
|
|
64
59
|
cmd += ' --junitReportDir=dist/test-report';
|
|
65
60
|
if (host) cmd += " --host=".concat(host);
|
|
@@ -72,13 +67,8 @@ var test = (host, port, specs) => {
|
|
|
72
67
|
force: true
|
|
73
68
|
});
|
|
74
69
|
return new Promise((resolve, _reject) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
stderr: 'pipe'
|
|
78
|
-
}, err => {
|
|
79
|
-
if (err) {
|
|
80
|
-
_logger.default.error("Test: Failed with error ".concat(err));
|
|
81
|
-
}
|
|
70
|
+
(0, _runner.default)(cmd, err => {
|
|
71
|
+
if (err) _logger.default.error("Test: Failed with error ".concat(err));
|
|
82
72
|
var testCases = parseJunitXML();
|
|
83
73
|
var total = testCases.length;
|
|
84
74
|
var success = testCases.filter(testcase => testcase['system-out'] && !testcase['failure']).length;
|
|
@@ -89,12 +79,8 @@ var test = (host, port, specs) => {
|
|
|
89
79
|
failure
|
|
90
80
|
};
|
|
91
81
|
resolve(result);
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
_logger.default.debug("Test: ".concat(data));
|
|
95
|
-
});
|
|
96
|
-
javaProcess.stderr.on('data', function (data) {
|
|
97
|
-
_logger.default.error("Test: ".concat(data));
|
|
82
|
+
}, (message, error) => {
|
|
83
|
+
_logger.default[error ? 'error' : 'debug']("Test: ".concat(message));
|
|
98
84
|
});
|
|
99
85
|
});
|
|
100
86
|
};
|
|
@@ -127,13 +113,13 @@ var setExpectations = (stubPath, stubServerBaseUrl) => {
|
|
|
127
113
|
};
|
|
128
114
|
exports.setExpectations = setExpectations;
|
|
129
115
|
var printJarVersion = () => {
|
|
130
|
-
var cmd = "
|
|
116
|
+
var cmd = "--version";
|
|
131
117
|
_logger.default.info('Print Jar Version: Running');
|
|
132
118
|
_logger.default.debug("Print Jar Version: Executing \"".concat(cmd, "\""));
|
|
133
|
-
(0,
|
|
134
|
-
if (err)
|
|
135
|
-
|
|
136
|
-
|
|
119
|
+
(0, _runner.default)(cmd, err => {
|
|
120
|
+
if (err) _logger.default.error("Print Jar Version: Failed with error ".concat(err));
|
|
121
|
+
}, (message, error) => {
|
|
122
|
+
if (error) _logger.default.error("Print Jar Version: ".concat(message));else console.log("".concat(message));
|
|
137
123
|
});
|
|
138
124
|
};
|
|
139
125
|
exports.printJarVersion = printJarVersion;
|
package/package.json
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
import execSh from 'exec-sh';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import callSpecmaticCli from '../core';
|
|
4
|
-
import { specmaticJarName
|
|
4
|
+
import { specmaticJarName } from '../../config';
|
|
5
5
|
import fs from 'fs';
|
|
6
|
-
import {
|
|
6
|
+
import { ChildProcess } from 'child_process';
|
|
7
|
+
import { mock as jestMock, mockReset } from 'jest-mock-extended';
|
|
8
|
+
import { Readable } from 'stream';
|
|
7
9
|
|
|
8
10
|
jest.mock('exec-sh');
|
|
9
11
|
jest.mock('child_process');
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
const javaProcessMock = jestMock<ChildProcess>();
|
|
14
|
+
const readableMock = jestMock<Readable>();
|
|
15
|
+
javaProcessMock.stdout = readableMock;
|
|
16
|
+
javaProcessMock.stderr = readableMock;
|
|
11
17
|
|
|
12
18
|
beforeEach(() => {
|
|
13
19
|
jest.resetAllMocks();
|
|
20
|
+
mockReset(javaProcessMock);
|
|
21
|
+
mockReset(readableMock);
|
|
14
22
|
});
|
|
15
23
|
|
|
16
24
|
test('pass all wrapper arguments to the jar', async () => {
|
|
17
|
-
|
|
18
|
-
const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
|
|
19
|
-
await callSpecmaticCli(testArgs);
|
|
20
|
-
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} ${testArgs.slice(2).join(' ')}`);
|
|
21
|
-
expect(execSh).toHaveBeenCalledTimes(1);
|
|
22
|
-
});
|
|
25
|
+
execSh.mockReturnValue(javaProcessMock);
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
jest.spyOn(fs, 'existsSync').mockReturnValue(false);
|
|
27
|
+
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
|
|
26
28
|
const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, 0);
|
|
31
|
-
await callSpecmaticCli(testArgs);
|
|
32
|
-
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(NPM_GLOBAL_PATH, 'specmatic', specmaticJarName)} ${testArgs.slice(2).join(' ')}`);
|
|
29
|
+
callSpecmaticCli(testArgs);
|
|
30
|
+
const specmaticJarPath = path.resolve(__dirname, '..', '..', '..', specmaticJarName);
|
|
31
|
+
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPath)} ${testArgs.slice(2).join(' ')}`);
|
|
33
32
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
34
33
|
});
|
package/src/bin/core.ts
CHANGED
|
@@ -1,47 +1,24 @@
|
|
|
1
|
-
import execSh from 'exec-sh';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { specmaticJarPathLocal, specmaticJarName } from '../config';
|
|
4
1
|
import logger from '../common/logger';
|
|
5
|
-
import
|
|
6
|
-
import fs from 'fs';
|
|
2
|
+
import callSpecmatic from '../common/runner';
|
|
7
3
|
|
|
8
|
-
const callSpecmaticCli =
|
|
9
|
-
const specmaticJarPath = await getSpecmaticJarPath();
|
|
10
|
-
logger.debug(`CLI: Specmatic jar path: ${specmaticJarPath}`);
|
|
4
|
+
const callSpecmaticCli = (args?: string[]) => {
|
|
11
5
|
const cliArgs = (args || process.argv).slice(2).join(' ');
|
|
12
6
|
logger.info(`CLI: Running with args "${cliArgs}"`);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
callSpecmatic(
|
|
8
|
+
cliArgs,
|
|
9
|
+
(err?: any) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
logger.info('CLI: Finished with non zero exit code: ', err.code);
|
|
12
|
+
process.exitCode = err.code;
|
|
13
|
+
} else {
|
|
14
|
+
logger.info('CLI: Finished');
|
|
15
|
+
process.exitCode = 0;
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
message => {
|
|
19
|
+
console.log(`${message}`);
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
function getSpecmaticJarPath() {
|
|
25
|
-
return new Promise<string>((resolve, _reject) => {
|
|
26
|
-
let specmaticJarPath = path.resolve(specmaticJarPathLocal);
|
|
27
|
-
resolve(specmaticJarPath);
|
|
28
|
-
}).then(specmaticJarPath => {
|
|
29
|
-
if (!fs.existsSync(specmaticJarPath)) {
|
|
30
|
-
return getGlobalSpecmaticJarPath();
|
|
31
|
-
} else {
|
|
32
|
-
return specmaticJarPath;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getGlobalSpecmaticJarPath() {
|
|
38
|
-
return new Promise((resolve, _reject) => {
|
|
39
|
-
exec('npm root -g', (_err, stdout) => {
|
|
40
|
-
const npmGlobalModuleInstallPath = stdout.replace(/\n/g, '');
|
|
41
|
-
const jarPath = path.join(npmGlobalModuleInstallPath, 'specmatic', specmaticJarName);
|
|
42
|
-
resolve(jarPath);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
24
|
export default callSpecmaticCli;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import execSh from 'exec-sh';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { specmaticJarName } from '../config';
|
|
4
|
+
import logger from '../common/logger';
|
|
5
|
+
import { ChildProcess } from 'child_process';
|
|
6
|
+
|
|
7
|
+
const callSpecmatic = (args: string, done: (error: any) => void, onOutput: (message: string, error: boolean) => void): ChildProcess => {
|
|
8
|
+
const rootPath = path.resolve(__dirname, '..', '..');
|
|
9
|
+
const specmaticJarPath = path.resolve(rootPath, specmaticJarName);
|
|
10
|
+
logger.debug(`CLI: Specmatic jar path: ${specmaticJarPath}`);
|
|
11
|
+
const javaProcess = execSh(`java -jar ${specmaticJarPath} ${args}`, { stdio: 'pipe', stderr: 'pipe' }, done);
|
|
12
|
+
javaProcess.stdout?.on('data', function (data: String) {
|
|
13
|
+
onOutput(`${data}`, false);
|
|
14
|
+
});
|
|
15
|
+
javaProcess.stderr?.on('data', function (data: String) {
|
|
16
|
+
onOutput(`${data}`, true);
|
|
17
|
+
});
|
|
18
|
+
return javaProcess;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default callSpecmatic;
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export const specmaticJarName = 'specmatic.jar';
|
|
2
|
-
export const specmaticJarPathLocal = `./node_modules/specmatic/${specmaticJarName}`;
|
|
3
2
|
export const specmaticJarPathRemote = 'https://github.com/znsio/specmatic/releases/download/0.24.2/specmatic.jar';
|
|
4
3
|
export const specmatic = 'specmatic.json';
|
|
@@ -8,7 +8,7 @@ import { copyFileSync, mkdirSync, existsSync } from 'fs';
|
|
|
8
8
|
import fs from 'fs';
|
|
9
9
|
|
|
10
10
|
import * as specmatic from '../../';
|
|
11
|
-
import {
|
|
11
|
+
import { specmaticJarName } from '../../config';
|
|
12
12
|
import mockStub from '../../../test-resources/sample-mock-stub.json';
|
|
13
13
|
|
|
14
14
|
jest.mock('exec-sh');
|
|
@@ -16,6 +16,7 @@ jest.mock('node-fetch');
|
|
|
16
16
|
|
|
17
17
|
const fetchMock = fetch as unknown as jest.Mock;
|
|
18
18
|
|
|
19
|
+
const SPECMATIC_JAR_PATH = path.resolve(__dirname, '..', '..', '..', specmaticJarName);
|
|
19
20
|
const STUB_PATH = 'test-resources/sample-mock-stub.json';
|
|
20
21
|
const CONTRACT_YAML_FILE_PATH = './contracts';
|
|
21
22
|
const STUB_DIR_PATH = './data';
|
|
@@ -42,7 +43,7 @@ test('startStub method starts the specmatic stub server', async () => {
|
|
|
42
43
|
|
|
43
44
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
44
45
|
expect(execSh.mock.calls[0][0]).toBe(
|
|
45
|
-
`java -jar ${path.resolve(
|
|
46
|
+
`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --data=${path.resolve(STUB_DIR_PATH)} --host=${HOST} --port=${PORT}`
|
|
46
47
|
);
|
|
47
48
|
});
|
|
48
49
|
|
|
@@ -54,7 +55,7 @@ test('startStub method notifies when start fails due to port not available', asy
|
|
|
54
55
|
|
|
55
56
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
56
57
|
expect(execSh.mock.calls[0][0]).toBe(
|
|
57
|
-
`java -jar ${path.resolve(
|
|
58
|
+
`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --data=${path.resolve(STUB_DIR_PATH)} --host=${HOST} --port=${PORT}`
|
|
58
59
|
);
|
|
59
60
|
});
|
|
60
61
|
|
|
@@ -65,7 +66,7 @@ test('startStub method stubDir is optional', async () => {
|
|
|
65
66
|
await expect(specmatic.startStub(HOST, PORT)).resolves.toBe(javaProcessMock);
|
|
66
67
|
|
|
67
68
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
68
|
-
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(
|
|
69
|
+
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub --host=${HOST} --port=${PORT}`);
|
|
69
70
|
});
|
|
70
71
|
|
|
71
72
|
test('startStub method host and port are optional', async () => {
|
|
@@ -75,7 +76,7 @@ test('startStub method host and port are optional', async () => {
|
|
|
75
76
|
await expect(specmatic.startStub()).resolves.toBe(javaProcessMock);
|
|
76
77
|
|
|
77
78
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
78
|
-
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(
|
|
79
|
+
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} stub`);
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
test('stopStub method stops any running stub server', () => {
|
|
@@ -97,7 +98,7 @@ test('test runs the contract tests', async function () {
|
|
|
97
98
|
|
|
98
99
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
99
100
|
expect(execSh.mock.calls[0][0]).toBe(
|
|
100
|
-
`java -jar ${path.resolve(
|
|
101
|
+
`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} test ${path.resolve(
|
|
101
102
|
CONTRACT_YAML_FILE_PATH
|
|
102
103
|
)} --junitReportDir=dist/test-report --host=${HOST} --port=${PORT}`
|
|
103
104
|
);
|
|
@@ -113,7 +114,7 @@ test('test runs the contract tests with host and port optional', async function
|
|
|
113
114
|
await expect(specmatic.test()).resolves.toBeTruthy();
|
|
114
115
|
|
|
115
116
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
116
|
-
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(
|
|
117
|
+
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} test --junitReportDir=dist/test-report`);
|
|
117
118
|
});
|
|
118
119
|
|
|
119
120
|
test('test runs the contract tests with contracts path optional', async function () {
|
|
@@ -127,7 +128,7 @@ test('test runs the contract tests with contracts path optional', async function
|
|
|
127
128
|
|
|
128
129
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
129
130
|
expect(execSh.mock.calls[0][0]).toBe(
|
|
130
|
-
`java -jar ${path.resolve(
|
|
131
|
+
`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} test --junitReportDir=dist/test-report --host=${HOST} --port=${PORT}`
|
|
131
132
|
);
|
|
132
133
|
});
|
|
133
134
|
|
|
@@ -174,10 +175,12 @@ test('test invocation makes sure previous junit report if any is deleted', async
|
|
|
174
175
|
});
|
|
175
176
|
|
|
176
177
|
test('printJarVersion', () => {
|
|
178
|
+
execSh.mockReturnValue(javaProcessMock);
|
|
179
|
+
|
|
177
180
|
specmatic.printJarVersion();
|
|
178
181
|
|
|
179
182
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
180
|
-
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(
|
|
183
|
+
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(SPECMATIC_JAR_PATH)} --version`);
|
|
181
184
|
});
|
|
182
185
|
|
|
183
186
|
test('setExpectations with default baseUrl', async () => {
|
package/src/lib/index.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import fetch from 'node-fetch';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import execSh from 'exec-sh';
|
|
4
|
-
import { specmaticJarPathLocal, specmatic } from '../config';
|
|
5
3
|
import { ChildProcess } from 'child_process';
|
|
6
4
|
import { XMLParser } from 'fast-xml-parser';
|
|
7
5
|
import fs from 'fs';
|
|
8
6
|
import logger from '../common/logger';
|
|
9
|
-
|
|
10
|
-
const specmaticJarPath = path.resolve(specmaticJarPathLocal);
|
|
7
|
+
import callSpecmatic from '../common/runner';
|
|
11
8
|
|
|
12
9
|
const startStub = (host?: string, port?: string, stubDir?: string): Promise<ChildProcess> => {
|
|
13
10
|
const stubs = path.resolve(stubDir + '');
|
|
14
11
|
|
|
15
|
-
var cmd = `
|
|
12
|
+
var cmd = `stub`;
|
|
16
13
|
if (stubDir) cmd += ` --data=${stubs}`;
|
|
17
14
|
if (host) cmd += ` --host=${host}`;
|
|
18
15
|
if (port) cmd += ` --port=${port}`;
|
|
@@ -21,25 +18,29 @@ const startStub = (host?: string, port?: string, stubDir?: string): Promise<Chil
|
|
|
21
18
|
logger.debug(`Stub: Executing "${cmd}"`);
|
|
22
19
|
|
|
23
20
|
return new Promise((resolve, reject) => {
|
|
24
|
-
const javaProcess =
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const javaProcess = callSpecmatic(
|
|
22
|
+
cmd,
|
|
23
|
+
(err: any) => {
|
|
24
|
+
if (err) {
|
|
25
|
+
logger.error(`Stub: Exited with error ${err}`);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
(message, error) => {
|
|
29
|
+
if (!error) {
|
|
30
|
+
if (message.indexOf('Stub server is running') > -1) {
|
|
31
|
+
logger.info(`Stub: ${message}`);
|
|
32
|
+
resolve(javaProcess);
|
|
33
|
+
} else if (message.indexOf('Address already in use') > -1) {
|
|
34
|
+
logger.error(`Stub: ${message}`);
|
|
35
|
+
reject();
|
|
36
|
+
} else {
|
|
37
|
+
logger.debug(`Stub: ${message}`);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
logger.error(`Stub: ${message}`);
|
|
41
|
+
}
|
|
27
42
|
}
|
|
28
|
-
|
|
29
|
-
javaProcess.stdout.on('data', function (data: String) {
|
|
30
|
-
if (data.indexOf('Stub server is running') > -1) {
|
|
31
|
-
logger.info(`Stub: ${data}`);
|
|
32
|
-
resolve(javaProcess);
|
|
33
|
-
} else if (data.indexOf('Address already in use') > -1) {
|
|
34
|
-
logger.error(`Stub: ${data}`);
|
|
35
|
-
reject();
|
|
36
|
-
} else {
|
|
37
|
-
logger.debug(`Stub: ${data}`);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
javaProcess.stderr.on('data', function (data: String) {
|
|
41
|
-
logger.error(`Stub: ${data}`);
|
|
42
|
-
});
|
|
43
|
+
);
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
46
|
|
|
@@ -55,7 +56,7 @@ const stopStub = (javaProcess: ChildProcess) => {
|
|
|
55
56
|
const test = (host?: string, port?: string, specs?: string): Promise<{ [k: string]: number } | undefined> => {
|
|
56
57
|
const specsPath = path.resolve(specs + '');
|
|
57
58
|
|
|
58
|
-
var cmd = `
|
|
59
|
+
var cmd = `test`;
|
|
59
60
|
if (specs) cmd += ` ${specsPath}`;
|
|
60
61
|
cmd += ' --junitReportDir=dist/test-report';
|
|
61
62
|
if (host) cmd += ` --host=${host}`;
|
|
@@ -68,23 +69,21 @@ const test = (host?: string, port?: string, specs?: string): Promise<{ [k: strin
|
|
|
68
69
|
fs.rmSync(reportDir, { recursive: true, force: true });
|
|
69
70
|
|
|
70
71
|
return new Promise((resolve, _reject) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
callSpecmatic(
|
|
73
|
+
cmd,
|
|
74
|
+
(err: any) => {
|
|
75
|
+
if (err) logger.error(`Test: Failed with error ${err}`);
|
|
76
|
+
var testCases = parseJunitXML();
|
|
77
|
+
const total = testCases.length;
|
|
78
|
+
const success = testCases.filter((testcase: { [id: string]: any }) => testcase['system-out'] && !testcase['failure']).length;
|
|
79
|
+
const failure = testCases.filter((testcase: { [id: string]: any }) => testcase['failure']).length;
|
|
80
|
+
var result = { total, success, failure };
|
|
81
|
+
resolve(result);
|
|
82
|
+
},
|
|
83
|
+
(message, error) => {
|
|
84
|
+
logger[error ? 'error' : 'debug'](`Test: ${message}`);
|
|
74
85
|
}
|
|
75
|
-
|
|
76
|
-
const total = testCases.length;
|
|
77
|
-
const success = testCases.filter((testcase: { [id: string]: any }) => testcase['system-out'] && !testcase['failure']).length;
|
|
78
|
-
const failure = testCases.filter((testcase: { [id: string]: any }) => testcase['failure']).length;
|
|
79
|
-
var result = { total, success, failure };
|
|
80
|
-
resolve(result);
|
|
81
|
-
});
|
|
82
|
-
javaProcess.stdout.on('data', function (data: String) {
|
|
83
|
-
logger.debug(`Test: ${data}`);
|
|
84
|
-
});
|
|
85
|
-
javaProcess.stderr.on('data', function (data: String) {
|
|
86
|
-
logger.error(`Test: ${data}`);
|
|
87
|
-
});
|
|
86
|
+
);
|
|
88
87
|
});
|
|
89
88
|
};
|
|
90
89
|
|
|
@@ -120,15 +119,20 @@ const setExpectations = (stubPath: string, stubServerBaseUrl?: string): Promise<
|
|
|
120
119
|
};
|
|
121
120
|
|
|
122
121
|
const printJarVersion = () => {
|
|
123
|
-
const cmd =
|
|
122
|
+
const cmd = `--version`;
|
|
124
123
|
logger.info('Print Jar Version: Running');
|
|
125
124
|
logger.debug(`Print Jar Version: Executing "${cmd}"`);
|
|
126
125
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
callSpecmatic(
|
|
127
|
+
cmd,
|
|
128
|
+
(err: any) => {
|
|
129
|
+
if (err) logger.error(`Print Jar Version: Failed with error ${err}`);
|
|
130
|
+
},
|
|
131
|
+
(message, error) => {
|
|
132
|
+
if (error) logger.error(`Print Jar Version: ${message}`);
|
|
133
|
+
else console.log(`${message}`);
|
|
130
134
|
}
|
|
131
|
-
|
|
135
|
+
);
|
|
132
136
|
};
|
|
133
137
|
|
|
134
138
|
const parseJunitXML = () => {
|