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.
@@ -1,17 +1,11 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
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
- workflow_run:
8
- workflows: ["test"]
9
- types:
10
- - completed
4
+ release:
5
+ types: [published]
11
6
 
12
7
  jobs:
13
- build-and-publish:
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
- - run: echo "previous_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo '')" >> $GITHUB_ENV
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
- package-path: ./package.json
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
@@ -1,4 +1,4 @@
1
- name: test
1
+ name: Run Tests
2
2
 
3
3
  on:
4
4
  push:
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 = (testFn: (name: string, cb: () => void) => void)` <br />
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
- `printSpecmaticJarVersion()` <br />
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('starting specmatic server', cliArgs);
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('Exit code: ', err.code);
18
- process.exit(err.code);
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().replaceAll('\n', '').split('display-name: Scenario: ')[1].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.1",
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.10.5",
32
- "@babel/core": "^7.11.4",
33
- "@babel/preset-env": "^7.11.0",
34
- "@babel/preset-typescript": "^7.10.4",
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.5.7",
37
- "@types/yargs": "^15.0.5",
38
- "exec-sh": "^0.3.4",
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.0",
41
- "rimraf": "^3.0.2",
42
- "yargs": "^15.4.1"
39
+ "node-fetch": "^2.6.11",
40
+ "rimraf": "^5.0.1",
41
+ "yargs": "^17.7.2"
43
42
  },
44
43
  "devDependencies": {
45
- "@types/jest": "^26.0.24",
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 startSpecmaticServer from '../core';
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
- startSpecmaticServer(testArgs);
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('starting specmatic server', cliArgs);
9
+ console.log('Running specmatic ', cliArgs);
10
10
  execSh(`java -jar ${specmaticJarPath} ${cliArgs}`, {}, (err: any) => {
11
11
  if (err) {
12
- console.log('Exit code: ', err.code);
13
- process.exit(err.code);
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
- fetch.mockReset();
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
- fetch.mockReturnValue(Promise.resolve('{}'));
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(fetch).toHaveBeenCalledTimes(1);
174
- expect(fetch.mock.calls[0][0]).toBe('http://localhost:9000/_specmatic/expectations');
175
- expect(fetch.mock.calls[0][1]).toMatchObject({
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
- fetch.mockReturnValue(Promise.resolve('{}'));
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(fetch).toHaveBeenCalledTimes(1);
190
- expect(fetch.mock.calls[0][0]).toBe(`${stubServerBaseUrl}_specmatic/expectations`);
191
- expect(fetch.mock.calls[0][1]).toMatchObject({
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().replaceAll('\n', '').split('display-name: Scenario: ')[1].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
  });