specmatic 0.68.1 → 0.68.3
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 +4 -36
- package/dist/common/runner.js +30 -0
- package/dist/config.js +1 -3
- package/dist/lib/index.js +30 -40
- package/package.json +1 -1
- package/src/bin/__tests__/core.ts +13 -15
- package/src/bin/core.ts +15 -45
- package/src/common/runner.ts +21 -0
- package/src/config.ts +0 -1
- package/src/lib/__tests__/index.ts +35 -9
- package/src/lib/index.ts +57 -46
- package/test-resources/sample-junit-result-corrupt.xml +175 -0
- package/test-resources/sample-junit-result-generative.xml +389 -0
- package/test-resources/sample-junit-result-no-testname.xml +179 -0
package/dist/bin/core.js
CHANGED
|
@@ -4,20 +4,13 @@ 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 _child_process = require("child_process");
|
|
10
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
var _config = require("../config");
|
|
12
7
|
var _logger = _interopRequireDefault(require("../common/logger"));
|
|
8
|
+
var _runner = _interopRequireDefault(require("../common/runner"));
|
|
13
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
10
|
var callSpecmaticCli = args => {
|
|
15
|
-
var rootPath = _path.default.resolve(__dirname, '..', '..');
|
|
16
|
-
var specmaticJarPath = _path.default.resolve(rootPath, _config.specmaticJarName);
|
|
17
|
-
_logger.default.debug("CLI: Specmatic jar path: ".concat(specmaticJarPath));
|
|
18
11
|
var cliArgs = (args || process.argv).slice(2).join(' ');
|
|
19
12
|
_logger.default.info("CLI: Running with args \"".concat(cliArgs, "\""));
|
|
20
|
-
(0,
|
|
13
|
+
(0, _runner.default)(cliArgs, err => {
|
|
21
14
|
if (err) {
|
|
22
15
|
_logger.default.info('CLI: Finished with non zero exit code: ', err.code);
|
|
23
16
|
process.exitCode = err.code;
|
|
@@ -25,34 +18,9 @@ var callSpecmaticCli = args => {
|
|
|
25
18
|
_logger.default.info('CLI: Finished');
|
|
26
19
|
process.exitCode = 0;
|
|
27
20
|
}
|
|
21
|
+
}, message => {
|
|
22
|
+
console.log("".concat(message));
|
|
28
23
|
});
|
|
29
24
|
};
|
|
30
|
-
function getSpecmaticJarPath() {
|
|
31
|
-
return new Promise((resolve, _reject) => {
|
|
32
|
-
var specmaticJarPath = _path.default.resolve(_config.specmaticJarPathLocal);
|
|
33
|
-
resolve(specmaticJarPath);
|
|
34
|
-
}).then(specmaticJarPath => {
|
|
35
|
-
//Get current directory
|
|
36
|
-
console.log("Script basename: ".concat(__dirname));
|
|
37
|
-
var rootPath = _path.default.resolve(__dirname, '..', '..');
|
|
38
|
-
var specmaticJarPath2 = _path.default.resolve(rootPath, _config.specmaticJarName);
|
|
39
|
-
console.log("Script jar path: ".concat(specmaticJarPath2));
|
|
40
|
-
console.log("Script jar path exists? ".concat(_fs.default.existsSync(specmaticJarPath2)));
|
|
41
|
-
if (!_fs.default.existsSync(specmaticJarPath)) {
|
|
42
|
-
return getGlobalSpecmaticJarPath();
|
|
43
|
-
} else {
|
|
44
|
-
return specmaticJarPath;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
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
|
-
}
|
|
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
|
};
|
|
@@ -102,7 +88,11 @@ exports.test = test;
|
|
|
102
88
|
var showTestResults = testFn => {
|
|
103
89
|
var testCases = parseJunitXML();
|
|
104
90
|
testCases.map(function (testcase) {
|
|
105
|
-
var name =
|
|
91
|
+
var name = 'No Name';
|
|
92
|
+
if (testcase['system-out']) {
|
|
93
|
+
var nameTempArr = testcase['system-out'].trim().replace(/\n/g, '').split(/display-name:.*Scenario: /);
|
|
94
|
+
if (nameTempArr.length > 1) name = nameTempArr[1].trim();
|
|
95
|
+
}
|
|
106
96
|
testFn(name, () => {
|
|
107
97
|
if (testcase.failure) throw new Error('Did not pass');
|
|
108
98
|
});
|
|
@@ -127,13 +117,13 @@ var setExpectations = (stubPath, stubServerBaseUrl) => {
|
|
|
127
117
|
};
|
|
128
118
|
exports.setExpectations = setExpectations;
|
|
129
119
|
var printJarVersion = () => {
|
|
130
|
-
var cmd = "
|
|
120
|
+
var cmd = "--version";
|
|
131
121
|
_logger.default.info('Print Jar Version: Running');
|
|
132
122
|
_logger.default.debug("Print Jar Version: Executing \"".concat(cmd, "\""));
|
|
133
|
-
(0,
|
|
134
|
-
if (err)
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
(0, _runner.default)(cmd, err => {
|
|
124
|
+
if (err) _logger.default.error("Print Jar Version: Failed with error ".concat(err));
|
|
125
|
+
}, (message, error) => {
|
|
126
|
+
if (error) _logger.default.error("Print Jar Version: ".concat(message));else console.log("".concat(message));
|
|
137
127
|
});
|
|
138
128
|
};
|
|
139
129
|
exports.printJarVersion = printJarVersion;
|
package/package.json
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
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 () => {
|
|
25
|
+
execSh.mockReturnValue(javaProcessMock);
|
|
26
|
+
|
|
17
27
|
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
|
|
18
28
|
const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
|
|
19
29
|
callSpecmaticCli(testArgs);
|
|
@@ -21,15 +31,3 @@ test('pass all wrapper arguments to the jar', async () => {
|
|
|
21
31
|
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPath)} ${testArgs.slice(2).join(' ')}`);
|
|
22
32
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
23
33
|
});
|
|
24
|
-
|
|
25
|
-
// test('look for jar in specmatic globally installled directory when run from global install', async () => {
|
|
26
|
-
// jest.spyOn(fs, 'existsSync').mockReturnValue(false);
|
|
27
|
-
// const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
|
|
28
|
-
// const NPM_GLOBAL_PATH = '/npm/global/path';
|
|
29
|
-
// setTimeout(() => {
|
|
30
|
-
// execMock.mock.calls[0][1](0, NPM_GLOBAL_PATH);
|
|
31
|
-
// }, 0);
|
|
32
|
-
// await callSpecmaticCli(testArgs);
|
|
33
|
-
// expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(NPM_GLOBAL_PATH, 'specmatic', specmaticJarName)} ${testArgs.slice(2).join(' ')}`);
|
|
34
|
-
// expect(execSh).toHaveBeenCalledTimes(1);
|
|
35
|
-
// });
|
package/src/bin/core.ts
CHANGED
|
@@ -1,54 +1,24 @@
|
|
|
1
|
-
import execSh from 'exec-sh';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { exec } from 'child_process';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { specmaticJarPathLocal, specmaticJarName } from '../config';
|
|
6
1
|
import logger from '../common/logger';
|
|
2
|
+
import callSpecmatic from '../common/runner';
|
|
7
3
|
|
|
8
4
|
const callSpecmaticCli = (args?: string[]) => {
|
|
9
|
-
const rootPath = path.resolve(__dirname, '..', '..');
|
|
10
|
-
const specmaticJarPath = path.resolve(rootPath, specmaticJarName);
|
|
11
|
-
logger.debug(`CLI: Specmatic jar path: ${specmaticJarPath}`);
|
|
12
5
|
const cliArgs = (args || process.argv).slice(2).join(' ');
|
|
13
6
|
logger.info(`CLI: Running with args "${cliArgs}"`);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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}`);
|
|
21
20
|
}
|
|
22
|
-
|
|
21
|
+
);
|
|
23
22
|
};
|
|
24
23
|
|
|
25
|
-
function getSpecmaticJarPath() {
|
|
26
|
-
return new Promise<string>((resolve, _reject) => {
|
|
27
|
-
let specmaticJarPath = path.resolve(specmaticJarPathLocal);
|
|
28
|
-
resolve(specmaticJarPath);
|
|
29
|
-
}).then(specmaticJarPath => {
|
|
30
|
-
//Get current directory
|
|
31
|
-
console.log(`Script basename: ${__dirname}`);
|
|
32
|
-
const rootPath = path.resolve(__dirname, '..', '..');
|
|
33
|
-
const specmaticJarPath2 = path.resolve(rootPath, specmaticJarName);
|
|
34
|
-
console.log(`Script jar path: ${specmaticJarPath2}`);
|
|
35
|
-
console.log(`Script jar path exists? ${fs.existsSync(specmaticJarPath2)}`);
|
|
36
|
-
if (!fs.existsSync(specmaticJarPath)) {
|
|
37
|
-
return getGlobalSpecmaticJarPath();
|
|
38
|
-
} else {
|
|
39
|
-
return specmaticJarPath;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getGlobalSpecmaticJarPath() {
|
|
45
|
-
return new Promise((resolve, _reject) => {
|
|
46
|
-
exec('npm root -g', (_err, stdout) => {
|
|
47
|
-
const npmGlobalModuleInstallPath = stdout.replace(/\n/g, '');
|
|
48
|
-
const jarPath = path.join(npmGlobalModuleInstallPath, 'specmatic', specmaticJarName);
|
|
49
|
-
resolve(jarPath);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
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 () => {
|
|
@@ -226,6 +229,29 @@ test('setTestResults invokes the test function', () => {
|
|
|
226
229
|
expect(cb).toHaveBeenCalledTimes(5);
|
|
227
230
|
});
|
|
228
231
|
|
|
232
|
+
test('setTestResults works with junit report with generative tests mode', () => {
|
|
233
|
+
const cb = jest.fn();
|
|
234
|
+
copyReportFileWithName('sample-junit-result-generative.xml');
|
|
235
|
+
specmatic.showTestResults(cb);
|
|
236
|
+
expect(cb).toHaveBeenCalledTimes(4);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('setTestResults says "No Name" with junit report where test name cannot be found within system-out tag', () => {
|
|
240
|
+
const cb = jest.fn();
|
|
241
|
+
copyReportFileWithName('sample-junit-result-no-testname.xml');
|
|
242
|
+
specmatic.showTestResults(cb);
|
|
243
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
244
|
+
expect(cb).toHaveBeenCalledWith('No Name', expect.any(Function));
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('setTestResults says "No Name" with junit report where system-out tag does not exist', () => {
|
|
248
|
+
const cb = jest.fn();
|
|
249
|
+
copyReportFileWithName('sample-junit-result-corrupt.xml');
|
|
250
|
+
specmatic.showTestResults(cb);
|
|
251
|
+
expect(cb).toHaveBeenCalledTimes(1);
|
|
252
|
+
expect(cb).toHaveBeenCalledWith('No Name', expect.any(Function));
|
|
253
|
+
});
|
|
254
|
+
|
|
229
255
|
function copyReportFile() {
|
|
230
256
|
copyReportFileWithName('sample-junit-result-multiple.xml');
|
|
231
257
|
}
|