specmatic 0.65.2 → 0.67.0

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 CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
- "presets": [
3
- "@babel/typescript",
4
- [
5
- "@babel/preset-env",
6
- {
7
- "targets": {
8
- "esmodules": true
9
- }
10
- }
11
- ],
12
- ]
13
- }
2
+ "presets": [
3
+ "@babel/typescript",
4
+ [
5
+ "@babel/preset-env",
6
+ {
7
+ "targets": {
8
+ "esmodules": true
9
+ }
10
+ }
11
+ ],
12
+ ]
13
+ }
@@ -1,15 +1,17 @@
1
1
  # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
3
 
4
- name: Node.js Package
4
+ name: publish
5
5
 
6
6
  on:
7
- push:
8
- branches:
9
- - master
7
+ workflow_run:
8
+ workflows: ["test"]
9
+ types:
10
+ - completed
10
11
 
11
12
  jobs:
12
13
  build-and-publish:
14
+ if: ${{ github.event.workflow_run.conclusion == 'success' }}
13
15
  runs-on: ubuntu-latest
14
16
  steps:
15
17
  - uses: actions/checkout@v2
@@ -17,8 +19,15 @@ jobs:
17
19
  with:
18
20
  node-version: 14
19
21
  - run: npm install
20
- - run: npm test
21
22
  - 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
28
+ with:
29
+ package-path: ./package.json
30
+ release: true
22
31
  - uses: JS-DevTools/npm-publish@v1
23
32
  with:
24
33
  check-version: true
@@ -0,0 +1,17 @@
1
+ name: test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: actions/setup-node@v2
14
+ with:
15
+ node-version: 14
16
+ - run: npm install
17
+ - run: npm test
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Specmatic Framework Node Module
2
2
 
3
+ ![tests](https://github.com/znsio/specmatic-node/actions/workflows/test.yml/badge.svg)
4
+ [![publish](https://github.com/znsio/specmatic-node/actions/workflows/npm-publish.yml/badge.svg)](https://www.npmjs.com/package/specmatic)
5
+ [![GitHub release badge](https://badgen.net/github/release/znsio/specmatic-node/master)](https://github.com/znsio/specmatic-node/releases/latest)
6
+
3
7
  This node module is a thin wrapper over the [standalone executable jar](https://specmatic.in/getting_started.html#setup). All core capabilities are in the main [Specmatic project](https://github.com/znsio/specmatic). The purpose of this wrapper module is to act as a convenience to help with below aspects.
4
8
  * Easy installation and upgrade of the jar file in node projects through npm
5
9
  * JS helper library which provides to do various setup steps like start, stop the specmatic stub server, installing specs etc. These helpers methods can be used inside a setup file inside a javascript project programmatically instead of using cli scripts.
@@ -21,6 +25,9 @@ Tests for Free – Specmatic parses your API Specification files and based on th
21
25
 
22
26
  Check [Documentation](https://specmatic.in/documentation.html) for more information on cli commands and arguments.
23
27
 
28
+ ## Sample Repo
29
+ https://github.com/znsio/specmatic-order-bff-nodejs
30
+
24
31
  ## Programmatic Access
25
32
 
26
33
  Specmatic JS library exposes some of the commands as methods that can be run programmatically from any javascript testing framework, during setup or test phases.
@@ -41,10 +48,10 @@ method to start the stub server.
41
48
  `stopStub(process: ChildProcess)` <br />
42
49
  method to stop the stub server.
43
50
 
44
- `test(specs?: string, host?: string, port?: string): Promise<boolean>` <br />
51
+ `test(host?: string, port?: string, specs?: string): Promise<boolean>` <br />
45
52
  method to run tests.
46
53
 
47
- `setExpectations(stubPath: string, stubServerBaseUrl?: string)` <br />
54
+ `setExpectations(stubPath: string, stubServerBaseUrl?: string): Promise<boolean>` <br />
48
55
  method to dynamically set stub expectiona. Stub should be running before invoking this method.
49
56
 
50
57
  `printSpecmaticJarVersion()` <br />
package/dist/bin/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
- var _core = _interopRequireDefault(require("./core"));
5
-
4
+ var _core = _interopRequireDefault(require("../lib/core"));
6
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
-
8
6
  (0, _core.default)();
package/dist/config.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.specmatic = exports.specmaticJarPathRemote = exports.specmaticJarPathLocal = void 0;
6
+ exports.specmaticJarPathRemote = exports.specmaticJarPathLocal = exports.specmatic = void 0;
7
7
  var specmaticJarPathLocal = './node_modules/specmatic/specmatic.jar';
8
8
  exports.specmaticJarPathLocal = specmaticJarPathLocal;
9
9
  var specmaticJarPathRemote = 'https://github.com/znsio/specmatic/releases/download/0.24.2/specmatic.jar';
package/dist/index.js CHANGED
@@ -3,35 +3,40 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "startStub", {
6
+ Object.defineProperty(exports, "printJarVersion", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _lib.startStub;
9
+ return _lib.printJarVersion;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "stopStub", {
12
+ Object.defineProperty(exports, "setExpectations", {
13
13
  enumerable: true,
14
14
  get: function get() {
15
- return _lib.stopStub;
15
+ return _lib.setExpectations;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "test", {
18
+ Object.defineProperty(exports, "showTestResults", {
19
19
  enumerable: true,
20
20
  get: function get() {
21
- return _lib.test;
21
+ return _lib.showTestResults;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "setExpectations", {
24
+ Object.defineProperty(exports, "startStub", {
25
25
  enumerable: true,
26
26
  get: function get() {
27
- return _lib.setExpectations;
27
+ return _lib.startStub;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "printJarVersion", {
30
+ Object.defineProperty(exports, "stopStub", {
31
31
  enumerable: true,
32
32
  get: function get() {
33
- return _lib.printJarVersion;
33
+ return _lib.stopStub;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "test", {
37
+ enumerable: true,
38
+ get: function get() {
39
+ return _lib.test;
34
40
  }
35
41
  });
36
-
37
42
  var _lib = require("./lib");
@@ -4,18 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _execSh = _interopRequireDefault(require("exec-sh"));
9
-
10
8
  var _path = _interopRequireDefault(require("path"));
11
-
12
9
  var _config = require("../config");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  var callSpecmaticCli = args => {
17
12
  var specmaticJarPath = _path.default.resolve(_config.specmaticJarPathLocal);
18
-
19
13
  var cliArgs = (args || process.argv).slice(2).join(' ');
20
14
  console.log('starting specmatic server', cliArgs);
21
15
  (0, _execSh.default)("java -jar ".concat(specmaticJarPath, " ").concat(cliArgs), {}, err => {
@@ -25,6 +19,5 @@ var callSpecmaticCli = args => {
25
19
  }
26
20
  });
27
21
  };
28
-
29
22
  var _default = callSpecmaticCli;
30
23
  exports.default = _default;
package/dist/lib/index.js CHANGED
@@ -3,28 +3,23 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.printJarVersion = exports.setExpectations = exports.test = exports.stopStub = exports.startStub = void 0;
7
-
6
+ exports.test = exports.stopStub = exports.startStub = exports.showTestResults = exports.setExpectations = exports.printJarVersion = void 0;
8
7
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
9
-
10
8
  var _path = _interopRequireDefault(require("path"));
11
-
12
9
  var _execSh = _interopRequireDefault(require("exec-sh"));
13
-
14
10
  var _config = require("../config");
15
-
11
+ var _fastXmlParser = require("fast-xml-parser");
12
+ var _fs = _interopRequireDefault(require("fs"));
16
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
14
  var specmaticJarPath = _path.default.resolve(_config.specmaticJarPathLocal);
19
-
20
15
  var startStub = (host, port, stubDir) => {
21
16
  var stubs = _path.default.resolve(stubDir + '');
22
-
23
17
  var cmd = "java -jar ".concat(specmaticJarPath, " stub");
24
18
  if (stubDir) cmd += " --data=".concat(stubs);
25
19
  if (host) cmd += " --host=".concat(host);
26
20
  if (port) cmd += " --port=".concat(port);
27
- console.log(cmd);
21
+ // console.log(cmd);
22
+
28
23
  console.log('Starting specmatic stub server');
29
24
  return new Promise((resolve, _reject) => {
30
25
  var javaProcess = (0, _execSh.default)(cmd, {
@@ -36,9 +31,9 @@ var startStub = (host, port, stubDir) => {
36
31
  }
37
32
  });
38
33
  javaProcess.stdout.on('data', function (data) {
39
- console.log('STDOUT: ' + data);
40
-
34
+ // console.log('STDOUT: ' + data);
41
35
  if (data.indexOf('Stub server is running') > -1) {
36
+ console.log('STDOUT: ' + data);
42
37
  resolve(javaProcess);
43
38
  }
44
39
  });
@@ -47,55 +42,71 @@ var startStub = (host, port, stubDir) => {
47
42
  });
48
43
  });
49
44
  };
50
-
51
45
  exports.startStub = startStub;
52
-
53
46
  var stopStub = javaProcess => {
54
47
  var _javaProcess$stdout, _javaProcess$stderr;
55
-
56
- console.log("Stopping specmatic server");
48
+ console.log("Stopping specmatic stub server");
57
49
  (_javaProcess$stdout = javaProcess.stdout) === null || _javaProcess$stdout === void 0 ? void 0 : _javaProcess$stdout.removeAllListeners();
58
50
  (_javaProcess$stderr = javaProcess.stderr) === null || _javaProcess$stderr === void 0 ? void 0 : _javaProcess$stderr.removeAllListeners();
59
51
  javaProcess.removeAllListeners('close');
60
52
  javaProcess.kill();
61
53
  };
62
-
63
54
  exports.stopStub = stopStub;
64
-
65
- var test = (specs, host, port) => {
55
+ var test = (host, port, specs) => {
66
56
  var specsPath = _path.default.resolve(specs + '');
67
-
68
57
  var cmd = "java -jar ".concat(specmaticJarPath, " test");
69
58
  if (specs) cmd += " ".concat(specsPath);
59
+ cmd += ' --junitReportDir=dist/test-report';
70
60
  if (host) cmd += " --host=".concat(host);
71
61
  if (port) cmd += " --port=".concat(port);
72
- console.log(cmd);
62
+ // console.log(cmd);
63
+
73
64
  console.log('Running specmatic tests');
65
+ var reportDir = _path.default.resolve('dist/test-report');
66
+ _fs.default.rmSync(reportDir, {
67
+ recursive: true,
68
+ force: true
69
+ });
74
70
  return new Promise((resolve, _reject) => {
75
- (0, _execSh.default)(cmd, {}, err => {
76
- if (err) {
77
- console.error('Specmatic test run failed with error', err);
78
- }
79
-
80
- resolve(err == null);
71
+ (0, _execSh.default)(cmd, {
72
+ stdio: 'pipe',
73
+ stderr: 'pipe'
74
+ }, err => {
75
+ // if (err) {
76
+ // console.error('Specmatic test run failed with error', err);
77
+ // }
78
+ var testCases = parseJunitXML();
79
+ var total = testCases.length;
80
+ var success = testCases.filter(testcase => testcase['system-out'] && !testcase['failure']).length;
81
+ var failure = testCases.filter(testcase => testcase['failure']).length;
82
+ var result = new TestResult(total, success, failure);
83
+ resolve(result);
81
84
  });
82
85
  });
83
86
  };
84
-
85
87
  exports.test = test;
86
-
88
+ var showTestResults = cb => {
89
+ var testCases = parseJunitXML();
90
+ testCases.map(function (testcase) {
91
+ var name = testcase['system-out'].trim().replaceAll('\n', '').split('display-name: Scenario: ')[1].trim();
92
+ cb(name, !testcase.failure);
93
+ });
94
+ };
95
+ exports.showTestResults = showTestResults;
87
96
  var setExpectations = (stubPath, stubServerBaseUrl) => {
88
97
  var stubResponse = require(_path.default.resolve(stubPath));
89
-
90
98
  console.log('Setting expectations');
91
- (0, _nodeFetch.default)("".concat(stubServerBaseUrl ? stubServerBaseUrl : "http://localhost:9000/", "_specmatic/expectations"), {
92
- method: 'POST',
93
- body: JSON.stringify(stubResponse)
94
- }).then(json => console.log(json));
99
+ return new Promise((resolve, _reject) => {
100
+ (0, _nodeFetch.default)("".concat(stubServerBaseUrl ? stubServerBaseUrl : "http://localhost:9000/", "_specmatic/expectations"), {
101
+ method: 'POST',
102
+ body: JSON.stringify(stubResponse)
103
+ }).then(json => {
104
+ console.log('Setting expectations complete');
105
+ resolve(true);
106
+ });
107
+ });
95
108
  };
96
-
97
109
  exports.setExpectations = setExpectations;
98
-
99
110
  var printJarVersion = () => {
100
111
  (0, _execSh.default)("java -jar ".concat(specmaticJarPath, " --version"), {}, err => {
101
112
  if (err) {
@@ -103,5 +114,19 @@ var printJarVersion = () => {
103
114
  }
104
115
  });
105
116
  };
106
-
107
- exports.printJarVersion = printJarVersion;
117
+ exports.printJarVersion = printJarVersion;
118
+ var parseJunitXML = () => {
119
+ var reportPath = _path.default.resolve('dist/test-report/TEST-junit-jupiter.xml');
120
+ var data = _fs.default.readFileSync(reportPath);
121
+ var parser = new _fastXmlParser.XMLParser();
122
+ var resultXml = parser.parse(data);
123
+ resultXml.testsuite.testcase = Array.isArray(resultXml.testsuite.testcase) ? resultXml.testsuite.testcase : [resultXml.testsuite.testcase];
124
+ return resultXml.testsuite.testcase;
125
+ };
126
+ class TestResult {
127
+ constructor(count, success, failure) {
128
+ this.count = count;
129
+ this.success = success;
130
+ this.failure = failure;
131
+ }
132
+ }
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "specmatic",
3
- "version": "0.65.2",
3
+ "version": "0.67.0",
4
4
  "description": "Node wrapper for Specmatic",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
- "build": "npm test && rimraf dist && ./node_modules/.bin/babel src --extensions '.ts,.js' --ignore '**/__tests__/*.ts' -d dist",
9
- "build-and-publish-patch": "npm run build && npm version patch && npm publish",
10
- "build-and-publish-minor": "npm run build && npm version minor && npm publish",
11
- "build-and-publish-major": "npm run build && npm version major && npm publish"
8
+ "build": "npm test && rimraf dist && ./node_modules/.bin/babel src --extensions '.ts,.js' --ignore '**/__tests__/*.ts' -d dist"
12
9
  },
13
10
  "repository": {
14
11
  "type": "git",
@@ -35,16 +32,18 @@
35
32
  "@babel/core": "^7.11.4",
36
33
  "@babel/preset-env": "^7.11.0",
37
34
  "@babel/preset-typescript": "^7.10.4",
35
+ "@types/node": "^20.2.3",
38
36
  "@types/node-fetch": "^2.5.7",
39
37
  "@types/yargs": "^15.0.5",
40
38
  "exec-sh": "^0.3.4",
39
+ "fast-xml-parser": "^4.2.2",
41
40
  "node-fetch": "^2.6.0",
42
41
  "rimraf": "^3.0.2",
43
42
  "yargs": "^15.4.1"
44
43
  },
45
44
  "devDependencies": {
46
- "@types/jest": "^26.0.14",
47
- "jest": "^26.4.2",
45
+ "@types/jest": "^26.0.24",
46
+ "jest": "^29.5.0",
48
47
  "jest-mock-extended": "^3.0.4"
49
48
  }
50
49
  }
package/specmatic.jar CHANGED
Binary file
package/src/app.d.ts CHANGED
@@ -1 +1 @@
1
- declare module 'exec-sh';
1
+ declare module 'exec-sh';
@@ -1,13 +1,13 @@
1
1
  import execSh from 'exec-sh';
2
2
  import path from 'path';
3
- import startSpecmaticServer from '../core';
3
+ import startSpecmaticServer from '../../lib/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
- const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
10
- startSpecmaticServer(testArgs);
11
- expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} ${testArgs.slice(2).join(' ')}`);
12
- expect(execSh).toHaveBeenCalledTimes(1);
9
+ const testArgs = ['node', 'index.js', 'stub', '*.specmatic', '--data', 'src/mocks', '--host', 'localhost', '--port', '8000'];
10
+ startSpecmaticServer(testArgs);
11
+ expect(execSh.mock.calls[0][0]).toBe(`java -jar ${path.resolve(specmaticJarPathLocal)} ${testArgs.slice(2).join(' ')}`);
12
+ expect(execSh).toHaveBeenCalledTimes(1);
13
13
  });
package/src/bin/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import callSpecmaticCli from './core';
2
+ import callSpecmaticCli from '../lib/core';
3
3
 
4
- callSpecmaticCli();
4
+ callSpecmaticCli();
package/src/config.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export const specmaticJarPathLocal = './node_modules/specmatic/specmatic.jar';
2
2
  export const specmaticJarPathRemote = 'https://github.com/znsio/specmatic/releases/download/0.24.2/specmatic.jar';
3
- export const specmatic = 'specmatic.json'
3
+ export const specmatic = 'specmatic.json'
package/src/index.ts CHANGED
@@ -1,7 +1 @@
1
- export {
2
- startStub,
3
- stopStub,
4
- test,
5
- setExpectations,
6
- printJarVersion
7
- } from './lib';
1
+ export { startStub, stopStub, test, setExpectations, printJarVersion, showTestResults } from './lib';