specmatic 1.0.0 → 1.0.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/.babelrc +8 -12
- package/.github/dependabot.yml +18 -0
- package/.github/workflows/publish.yml +22 -0
- package/.github/workflows/test.yml +21 -0
- package/CONTRIBUTING.MD +17 -41
- package/README.md +152 -22
- package/dist/app.d.js +2 -1
- package/dist/bin/command.line.d.ts +2 -0
- package/dist/bin/command.line.js +36 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.js +4 -5
- package/dist/common/logger.d.ts +3 -0
- package/dist/common/logger.js +62 -0
- package/dist/common/runner.d.ts +4 -0
- package/dist/common/runner.js +53 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +6 -7
- package/dist/core/index.d.ts +24 -0
- package/dist/core/index.js +297 -0
- package/dist/core/shutdownUtils.d.ts +2 -0
- package/dist/core/shutdownUtils.js +42 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +100 -9
- package/dist/kafka/index.d.ts +14 -0
- package/dist/kafka/index.js +158 -0
- package/global.d.ts +1 -0
- package/jest.config.json +5 -0
- package/package.json +50 -23
- package/specmatic.jar +0 -0
- package/src/app.d.ts +1 -1
- package/src/bin/__tests__/command.line.ts +40 -0
- package/src/bin/command.line.ts +35 -0
- package/src/bin/index.ts +2 -2
- package/src/common/__tests__/logger.ts +85 -0
- package/src/common/logger.ts +49 -0
- package/src/common/runner.ts +44 -0
- package/src/config.ts +2 -3
- package/src/core/__tests__/end.points.api.ts +103 -0
- package/src/core/__tests__/print.jar.version.ts +28 -0
- package/src/core/__tests__/set.expectation.ts +54 -0
- package/src/core/__tests__/set.test.results.ts +62 -0
- package/src/core/__tests__/stub.ts +136 -0
- package/src/core/__tests__/test.ts +176 -0
- package/src/core/index.ts +261 -0
- package/src/core/shutdownUtils.ts +21 -0
- package/src/downloadSpecmaticJar.js +30 -0
- package/src/index.ts +19 -2
- package/src/kafka/index.ts +140 -0
- 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-multiple.xml +304 -0
- package/test-resources/sample-junit-result-no-testname.xml +179 -0
- package/test-resources/sample-junit-result-single.xml +92 -0
- package/test-resources/sample-junit-result-skipped.xml +198 -0
- package/tsconfig.json +106 -20
- package/.github/workflows/npm-publish.yml +0 -25
- package/.vscode/settings.json +0 -7
- package/dist/bin/core.js +0 -30
- package/dist/lib/index.js +0 -107
- package/src/bin/__tests__/core.ts +0 -13
- package/src/bin/core.ts +0 -22
- package/src/lib/__tests__/index.ts +0 -122
- package/src/lib/index.ts +0 -84
- /package/{mockStub.json → test-resources/sample-mock-stub.json} +0 -0
- /package/{specmatic.json → test-resources/sample-specmatic.json} +0 -0
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import execSh from 'exec-sh';
|
|
2
|
-
import fetch from 'node-fetch';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { ChildProcess } from 'child_process';
|
|
5
|
-
import { mock as jestMock } from 'jest-mock-extended';
|
|
6
|
-
import { Readable } from "stream";
|
|
7
|
-
|
|
8
|
-
import * as specmatic from '../';
|
|
9
|
-
import { startStub, stopStub, printJarVersion, setExpectations } from '../';
|
|
10
|
-
import { specmaticJarPathLocal } from '../../config';
|
|
11
|
-
import mockStub from '../../../mockStub.json';
|
|
12
|
-
|
|
13
|
-
jest.mock('exec-sh');
|
|
14
|
-
jest.mock('node-fetch');
|
|
15
|
-
|
|
16
|
-
const contractsPath = './contracts';
|
|
17
|
-
const stubDataPath = './data';
|
|
18
|
-
const host = 'localhost';
|
|
19
|
-
const port = '8000';
|
|
20
|
-
const javaProcessMock = jestMock<ChildProcess>();
|
|
21
|
-
const readableMock = jestMock<Readable>();
|
|
22
|
-
javaProcessMock.stdout = readableMock;
|
|
23
|
-
javaProcessMock.stderr = readableMock;
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
execSh.mockReset();
|
|
27
|
-
fetch.mockReset();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('startStub method starts the specmatic stub server', async () => {
|
|
31
|
-
execSh.mockReturnValue(javaProcessMock);
|
|
32
|
-
|
|
33
|
-
startStub(host, port, stubDataPath).then(javaProcess => {
|
|
34
|
-
expect(javaProcess).toBe(javaProcessMock);
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
readableMock.on.mock.calls[0][1]("Stub server is running");
|
|
38
|
-
|
|
39
|
-
expect(execSh).toHaveBeenCalledTimes(1);
|
|
40
|
-
expect(execSh.mock.calls[0][0])
|
|
41
|
-
.toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} stub --data=${path.resolve(stubDataPath)} --host=${host} --port=${port}`);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('startStub method stubDir is optional', async () => {
|
|
45
|
-
execSh.mockReturnValue(javaProcessMock);
|
|
46
|
-
|
|
47
|
-
startStub(host, port).then(javaProcess => {
|
|
48
|
-
expect(javaProcess).toBe(javaProcessMock);
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
readableMock.on.mock.calls[0][1]("Stub server is running");
|
|
52
|
-
|
|
53
|
-
expect(execSh).toHaveBeenCalledTimes(1);
|
|
54
|
-
expect(execSh.mock.calls[0][0])
|
|
55
|
-
.toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} stub --host=${host} --port=${port}`);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('startStub method host and port are optional', async () => {
|
|
59
|
-
execSh.mockReturnValue(javaProcessMock);
|
|
60
|
-
|
|
61
|
-
startStub().then(javaProcess => {
|
|
62
|
-
expect(javaProcess).toBe(javaProcessMock);
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
readableMock.on.mock.calls[0][1]("Stub server is running");
|
|
66
|
-
|
|
67
|
-
expect(execSh).toHaveBeenCalledTimes(1);
|
|
68
|
-
expect(execSh.mock.calls[0][0])
|
|
69
|
-
.toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} stub`);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('stopStub method stops any running stub server', () => {
|
|
73
|
-
stopStub(javaProcessMock);
|
|
74
|
-
|
|
75
|
-
expect(readableMock.removeAllListeners).toHaveBeenCalledTimes(2);
|
|
76
|
-
expect(javaProcessMock.removeAllListeners).toHaveBeenCalledTimes(1);
|
|
77
|
-
expect(javaProcessMock.kill).toHaveBeenCalledTimes(1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('test runs the contract tests', function (done) {
|
|
81
|
-
specmatic.test(contractsPath, host, port).then(result => {
|
|
82
|
-
expect(result).toBeTruthy();
|
|
83
|
-
done();
|
|
84
|
-
});
|
|
85
|
-
execSh.mock.calls[0][2](); //Execute the callback
|
|
86
|
-
expect(execSh).toHaveBeenCalledTimes(1);
|
|
87
|
-
expect(execSh.mock.calls[0][0])
|
|
88
|
-
.toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} test ${path.resolve(contractsPath)} --host=${host} --port=${port}`);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('printJarVersion', () => {
|
|
92
|
-
printJarVersion();
|
|
93
|
-
|
|
94
|
-
expect(execSh).toHaveBeenCalledTimes(1);
|
|
95
|
-
expect(execSh.mock.calls[0][0])
|
|
96
|
-
.toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} --version`);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
test('setExpectations with default baseUrl', () => {
|
|
100
|
-
fetch.mockReturnValue(Promise.resolve("{}"));
|
|
101
|
-
setExpectations(path.resolve('./mockStub.json'));
|
|
102
|
-
|
|
103
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
104
|
-
expect(fetch.mock.calls[0][0]).toBe('http://localhost:9000/_specmatic/expectations');
|
|
105
|
-
expect(fetch.mock.calls[0][1]).toMatchObject({
|
|
106
|
-
method: 'POST',
|
|
107
|
-
body: JSON.stringify(mockStub)
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test('setExpectations with a different baseUrl for the stub server', () => {
|
|
112
|
-
fetch.mockReturnValue(Promise.resolve("{}"));
|
|
113
|
-
const stubServerBaseUrl = 'http://localhost:8000/'
|
|
114
|
-
setExpectations(path.resolve('./mockStub.json'), stubServerBaseUrl);
|
|
115
|
-
|
|
116
|
-
expect(fetch).toHaveBeenCalledTimes(1);
|
|
117
|
-
expect(fetch.mock.calls[0][0]).toBe(`${stubServerBaseUrl}_specmatic/expectations`);
|
|
118
|
-
expect(fetch.mock.calls[0][1]).toMatchObject({
|
|
119
|
-
method: 'POST',
|
|
120
|
-
body: JSON.stringify(mockStub)
|
|
121
|
-
});
|
|
122
|
-
});
|
package/src/lib/index.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import fetch from 'node-fetch';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import execSh from 'exec-sh';
|
|
4
|
-
import { specmaticJarPathLocal, specmatic } from '../config';
|
|
5
|
-
import { ChildProcess } from 'child_process';
|
|
6
|
-
|
|
7
|
-
const specmaticJarPath = path.resolve(specmaticJarPathLocal);
|
|
8
|
-
|
|
9
|
-
const startStub = (host?: string, port?: string, stubDir?: string) : Promise<ChildProcess> => {
|
|
10
|
-
const stubs = path.resolve(stubDir + '');
|
|
11
|
-
|
|
12
|
-
var cmd = `java -jar ${specmaticJarPath} stub`;
|
|
13
|
-
if (stubDir) cmd += ` --data=${stubs}`;
|
|
14
|
-
if (host) cmd += ` --host=${host}`;
|
|
15
|
-
if (port) cmd += ` --port=${port}`;
|
|
16
|
-
console.log(cmd);
|
|
17
|
-
|
|
18
|
-
console.log('Starting specmatic stub server');
|
|
19
|
-
return new Promise((resolve, _reject) => {
|
|
20
|
-
const javaProcess = execSh(cmd, { stdio: 'pipe', stderr: 'pipe' }, (err: any) => {
|
|
21
|
-
if (err) {
|
|
22
|
-
console.error('Specmatic stub server exited with error', err);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
javaProcess.stdout.on('data', function (data: String) {
|
|
26
|
-
console.log('STDOUT: ' + data);
|
|
27
|
-
if (data.indexOf('Stub server is running') > -1) {
|
|
28
|
-
resolve(javaProcess);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
javaProcess.stderr.on('data', function (data: String) {
|
|
32
|
-
console.log('STDERR: ' + data);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const stopStub = (javaProcess: ChildProcess) => {
|
|
38
|
-
console.log(`Stopping specmatic server`);
|
|
39
|
-
javaProcess.stdout?.removeAllListeners();
|
|
40
|
-
javaProcess.stderr?.removeAllListeners();
|
|
41
|
-
javaProcess.removeAllListeners('close');
|
|
42
|
-
javaProcess.kill();
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const test = (specs?: string, host?: string, port?: string): Promise<boolean> => {
|
|
46
|
-
const specsPath = path.resolve(specs + '');
|
|
47
|
-
|
|
48
|
-
var cmd = `java -jar ${specmaticJarPath} test`;
|
|
49
|
-
if (specs) cmd += ` ${specsPath}`;
|
|
50
|
-
if (host) cmd += ` --host=${host}`;
|
|
51
|
-
if (port) cmd += ` --port=${port}`;
|
|
52
|
-
console.log(cmd);
|
|
53
|
-
|
|
54
|
-
console.log('Running specmatic tests');
|
|
55
|
-
|
|
56
|
-
return new Promise((resolve, _reject) => {
|
|
57
|
-
execSh(cmd, {}, (err: any) => {
|
|
58
|
-
if (err) {
|
|
59
|
-
console.error('Specmatic test run failed with error', err);
|
|
60
|
-
}
|
|
61
|
-
resolve(err == null);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const setExpectations = (stubPath: string, stubServerBaseUrl?: string) => {
|
|
67
|
-
const stubResponse = require(path.resolve(stubPath));
|
|
68
|
-
|
|
69
|
-
console.log('Setting expectations');
|
|
70
|
-
fetch(`${stubServerBaseUrl ? stubServerBaseUrl : `http://localhost:9000/`}_specmatic/expectations`, {
|
|
71
|
-
method: 'POST',
|
|
72
|
-
body: JSON.stringify(stubResponse),
|
|
73
|
-
}).then(json => console.log(json));
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const printJarVersion = () => {
|
|
77
|
-
execSh(`java -jar ${specmaticJarPath} --version`, {}, (err: any) => {
|
|
78
|
-
if (err) {
|
|
79
|
-
console.error('Could not print specmatic version', err);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export { startStub, stopStub, test, setExpectations, printJarVersion };
|
|
File without changes
|
|
File without changes
|