specmatic 0.67.1 → 0.67.4
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/npm-publish.yml +6 -17
- package/.github/workflows/test.yml +1 -1
- package/README.md +3 -2
- package/dist/bin/core.js +6 -3
- package/dist/lib/index.js +1 -1
- package/package.json +13 -14
- package/src/bin/__tests__/core.ts +2 -2
- package/src/bin/core.ts +6 -3
- package/src/lib/__tests__/index.ts +18 -9
- package/src/lib/index.ts +1 -1
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: publish
|
|
1
|
+
name: NPM Publish
|
|
5
2
|
|
|
6
3
|
on:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
types:
|
|
10
|
-
- completed
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
11
6
|
|
|
12
7
|
jobs:
|
|
13
|
-
|
|
14
|
-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
8
|
+
publish:
|
|
15
9
|
runs-on: ubuntu-latest
|
|
16
10
|
steps:
|
|
17
11
|
- uses: actions/checkout@v2
|
|
@@ -20,14 +14,9 @@ jobs:
|
|
|
20
14
|
node-version: 14
|
|
21
15
|
- run: npm install
|
|
22
16
|
- run: npm run build
|
|
23
|
-
-
|
|
24
|
-
- name: Create Tag
|
|
25
|
-
id: create_tag
|
|
26
|
-
uses: jaywcjlove/create-tag-action@main
|
|
27
|
-
if: env.previous_tag
|
|
17
|
+
- uses: reedyuk/npm-version@1.1.1
|
|
28
18
|
with:
|
|
29
|
-
|
|
30
|
-
release: true
|
|
19
|
+
version: ${{ github.event.release.tag_name }}
|
|
31
20
|
- uses: JS-DevTools/npm-publish@v1
|
|
32
21
|
with:
|
|
33
22
|
check-version: true
|
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
stopStub,
|
|
39
39
|
test,
|
|
40
40
|
setExpecations,
|
|
41
|
+
showTestResults,
|
|
41
42
|
printJarVersion
|
|
42
43
|
} from 'specmatic';
|
|
43
44
|
```
|
|
@@ -54,8 +55,8 @@ method to run tests.
|
|
|
54
55
|
`setExpectations(stubPath: string, stubServerBaseUrl?: string): Promise<boolean>` <br />
|
|
55
56
|
method to dynamically set stub expectiona. Stub should be running before invoking this method.
|
|
56
57
|
|
|
57
|
-
`showTestResults
|
|
58
|
+
`showTestResults(testFn: (name: string, cb: () => void) => void)` <br />
|
|
58
59
|
method to report test results in any framework so that it shows up in IDE test results interface.
|
|
59
60
|
|
|
60
|
-
`
|
|
61
|
+
`printJarVersion()` <br />
|
|
61
62
|
method to print the version of specmatic.jar
|
package/dist/bin/core.js
CHANGED
|
@@ -11,11 +11,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
11
11
|
var callSpecmaticCli = args => {
|
|
12
12
|
var specmaticJarPath = _path.default.resolve(_config.specmaticJarPathLocal);
|
|
13
13
|
var cliArgs = (args || process.argv).slice(2).join(' ');
|
|
14
|
-
console.log('
|
|
14
|
+
console.log('Running specmatic ', cliArgs);
|
|
15
15
|
(0, _execSh.default)("java -jar ".concat(specmaticJarPath, " ").concat(cliArgs), {}, err => {
|
|
16
16
|
if (err) {
|
|
17
|
-
console.log('
|
|
18
|
-
process.
|
|
17
|
+
console.log('Specmatic finished with non zero exit code: ', err.code);
|
|
18
|
+
process.exitCode = err.code;
|
|
19
|
+
} else {
|
|
20
|
+
console.log('Specmatic finished');
|
|
21
|
+
process.exitCode = 0;
|
|
19
22
|
}
|
|
20
23
|
});
|
|
21
24
|
};
|
package/dist/lib/index.js
CHANGED
|
@@ -92,7 +92,7 @@ exports.test = test;
|
|
|
92
92
|
var showTestResults = testFn => {
|
|
93
93
|
var testCases = parseJunitXML();
|
|
94
94
|
testCases.map(function (testcase) {
|
|
95
|
-
var name = testcase['system-out'].trim().
|
|
95
|
+
var name = testcase['system-out'].trim().replace(/\n/g, '').split('display-name: Scenario: ')[1].trim();
|
|
96
96
|
testFn(name, () => {
|
|
97
97
|
if (testcase.failure) throw new Error('Did not pass');
|
|
98
98
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specmatic",
|
|
3
|
-
"version": "0.67.
|
|
3
|
+
"version": "0.67.4",
|
|
4
4
|
"description": "Node wrapper for Specmatic",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,25 +24,24 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/znsio/specmatic-node#readme",
|
|
26
26
|
"bin": {
|
|
27
|
-
"specmatic": "dist/bin/index.js"
|
|
28
|
-
"qontract": "dist/bin/index.js"
|
|
27
|
+
"specmatic": "dist/bin/index.js"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"@babel/cli": "^7.
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/preset-env": "^7.
|
|
34
|
-
"@babel/preset-typescript": "^7.
|
|
30
|
+
"@babel/cli": "^7.21.5",
|
|
31
|
+
"@babel/core": "^7.21.8",
|
|
32
|
+
"@babel/preset-env": "^7.21.5",
|
|
33
|
+
"@babel/preset-typescript": "^7.21.5",
|
|
35
34
|
"@types/node": "^20.2.3",
|
|
36
|
-
"@types/node-fetch": "^2.
|
|
37
|
-
"@types/yargs": "^
|
|
38
|
-
"exec-sh": "^0.
|
|
35
|
+
"@types/node-fetch": "^2.6.4",
|
|
36
|
+
"@types/yargs": "^17.0.24",
|
|
37
|
+
"exec-sh": "^0.4.0",
|
|
39
38
|
"fast-xml-parser": "^4.2.2",
|
|
40
|
-
"node-fetch": "^2.6.
|
|
41
|
-
"rimraf": "^
|
|
42
|
-
"yargs": "^
|
|
39
|
+
"node-fetch": "^2.6.11",
|
|
40
|
+
"rimraf": "^5.0.1",
|
|
41
|
+
"yargs": "^17.7.2"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@types/jest": "^
|
|
44
|
+
"@types/jest": "^29.5.1",
|
|
46
45
|
"jest": "^29.5.0",
|
|
47
46
|
"jest-mock-extended": "^3.0.4"
|
|
48
47
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import execSh from 'exec-sh';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import
|
|
3
|
+
import callSpecmaticCli from '../core';
|
|
4
4
|
import { specmaticJarPathLocal } from '../../config';
|
|
5
5
|
|
|
6
6
|
jest.mock('exec-sh');
|
|
7
7
|
|
|
8
8
|
test('arguments to be passed correctly to Specmatic lib', () => {
|
|
9
9
|
const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
|
|
10
|
-
|
|
10
|
+
callSpecmaticCli(testArgs);
|
|
11
11
|
expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} ${testArgs.slice(2).join(' ')}`);
|
|
12
12
|
expect(execSh).toHaveBeenCalledTimes(1);
|
|
13
13
|
});
|
package/src/bin/core.ts
CHANGED
|
@@ -6,11 +6,14 @@ const callSpecmaticCli = (args?: string[]) => {
|
|
|
6
6
|
const specmaticJarPath = path.resolve(specmaticJarPathLocal);
|
|
7
7
|
const cliArgs = (args || process.argv).slice(2).join(' ');
|
|
8
8
|
|
|
9
|
-
console.log('
|
|
9
|
+
console.log('Running specmatic ', cliArgs);
|
|
10
10
|
execSh(`java -jar ${specmaticJarPath} ${cliArgs}`, {}, (err: any) => {
|
|
11
11
|
if (err) {
|
|
12
|
-
console.log('
|
|
13
|
-
process.
|
|
12
|
+
console.log('Specmatic finished with non zero exit code: ', err.code);
|
|
13
|
+
process.exitCode = err.code;
|
|
14
|
+
} else {
|
|
15
|
+
console.log('Specmatic finished');
|
|
16
|
+
process.exitCode = 0;
|
|
14
17
|
}
|
|
15
18
|
});
|
|
16
19
|
};
|
|
@@ -13,6 +13,8 @@ import mockStub from '../../../test-resources/sample-mock-stub.json';
|
|
|
13
13
|
jest.mock('exec-sh');
|
|
14
14
|
jest.mock('node-fetch');
|
|
15
15
|
|
|
16
|
+
const fetchMock = (fetch as unknown as jest.Mock)
|
|
17
|
+
|
|
16
18
|
const STUB_PATH = 'test-resources/sample-mock-stub.json';
|
|
17
19
|
const CONTRACT_YAML_FILE_PATH = './contracts';
|
|
18
20
|
const STUB_DIR_PATH = './data';
|
|
@@ -26,7 +28,7 @@ javaProcessMock.stderr = readableMock;
|
|
|
26
28
|
|
|
27
29
|
beforeEach(() => {
|
|
28
30
|
execSh.mockReset();
|
|
29
|
-
|
|
31
|
+
fetchMock.mockReset();
|
|
30
32
|
});
|
|
31
33
|
|
|
32
34
|
test('startStub method starts the specmatic stub server', async () => {
|
|
@@ -164,36 +166,43 @@ test('printJarVersion', () => {
|
|
|
164
166
|
});
|
|
165
167
|
|
|
166
168
|
test('setExpectations with default baseUrl', done => {
|
|
167
|
-
|
|
169
|
+
fetchMock.mockReturnValue(Promise.resolve('{}'));
|
|
168
170
|
specmatic.setExpectations(path.resolve(STUB_PATH)).then(result => {
|
|
169
171
|
expect(result).toBeTruthy();
|
|
170
172
|
done();
|
|
171
173
|
});
|
|
172
174
|
|
|
173
|
-
expect(
|
|
174
|
-
expect(
|
|
175
|
-
expect(
|
|
175
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
176
|
+
expect(fetchMock.mock.calls[0][0]).toBe('http://localhost:9000/_specmatic/expectations');
|
|
177
|
+
expect(fetchMock.mock.calls[0][1]).toMatchObject({
|
|
176
178
|
method: 'POST',
|
|
177
179
|
body: JSON.stringify(mockStub),
|
|
178
180
|
});
|
|
179
181
|
});
|
|
180
182
|
|
|
181
183
|
test('setExpectations with a different baseUrl for the stub server', done => {
|
|
182
|
-
|
|
184
|
+
fetchMock.mockReturnValue(Promise.resolve('{}'));
|
|
183
185
|
const stubServerBaseUrl = 'http://localhost:8000/';
|
|
184
186
|
specmatic.setExpectations(path.resolve(STUB_PATH), stubServerBaseUrl).then(result => {
|
|
185
187
|
expect(result).toBeTruthy();
|
|
186
188
|
done();
|
|
187
189
|
});
|
|
188
190
|
|
|
189
|
-
expect(
|
|
190
|
-
expect(
|
|
191
|
-
expect(
|
|
191
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
192
|
+
expect(fetchMock.mock.calls[0][0]).toBe(`${stubServerBaseUrl}_specmatic/expectations`);
|
|
193
|
+
expect(fetchMock.mock.calls[0][1]).toMatchObject({
|
|
192
194
|
method: 'POST',
|
|
193
195
|
body: JSON.stringify(mockStub),
|
|
194
196
|
});
|
|
195
197
|
});
|
|
196
198
|
|
|
199
|
+
test('setTestResults invokes the test function', () => {
|
|
200
|
+
const cb = jest.fn();
|
|
201
|
+
copyReportFile();
|
|
202
|
+
specmatic.showTestResults(cb);
|
|
203
|
+
expect(cb).toHaveBeenCalledTimes(5);
|
|
204
|
+
});
|
|
205
|
+
|
|
197
206
|
function copyReportFile() {
|
|
198
207
|
copyReportFileWithName('sample-junit-result-multiple.xml');
|
|
199
208
|
}
|
package/src/lib/index.ts
CHANGED
|
@@ -78,7 +78,7 @@ const test = (host?: string, port?: string, specs?: string): Promise<{ [k: strin
|
|
|
78
78
|
const showTestResults = (testFn: (name: string, cb: () => void) => void) => {
|
|
79
79
|
var testCases = parseJunitXML();
|
|
80
80
|
testCases.map(function (testcase: { [id: string]: any }) {
|
|
81
|
-
var name = testcase['system-out'].trim().
|
|
81
|
+
var name = testcase['system-out'].trim().replace(/\n/g, '').split('display-name: Scenario: ')[1].trim();
|
|
82
82
|
testFn(name, () => {
|
|
83
83
|
if (testcase.failure) throw new Error('Did not pass');
|
|
84
84
|
});
|