@asyncapi/converter 0.7.2 → 0.8.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/lib/index.js CHANGED
@@ -34,16 +34,13 @@ lib.convert = (asyncapi, version, options = {}) => {
34
34
  const toVersion = conversionVersions.indexOf(version);
35
35
 
36
36
  if (fromVersion === -1 || toVersion === -1) {
37
- console.error(`Cannot convert from ${parsed.asyncapi} to ${version}.`);
38
- return;
37
+ throw new Error(`Cannot convert from ${parsed.asyncapi} to ${version}.`);
39
38
  }
40
39
  if (fromVersion > toVersion) {
41
- console.error(`Cannot downgrade from ${parsed.asyncapi} to ${version}.`);
42
- return;
40
+ throw new Error(`Cannot downgrade from ${parsed.asyncapi} to ${version}.`);
43
41
  }
44
42
  if (fromVersion === toVersion) {
45
- console.error(`Cannot convert to the same version.`);
46
- return;
43
+ throw new Error(`Cannot convert to the same version.`);
47
44
  }
48
45
 
49
46
  // add 1 to `fromVersion` because we convert from previous to next
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/converter",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "Convert AsyncAPI documents from older to newer versions.",
5
5
  "bin": {
6
6
  "asyncapi-converter": "cli.js"
package/test/index.js CHANGED
@@ -6,18 +6,24 @@ const { serialize } = require('../lib/helpers');
6
6
 
7
7
  describe('#convert', () => {
8
8
  it('should not convert to lowest version', () => {
9
- const result = convert(`asyncapi: '2.1.0'`, '2.0.0');
10
- assert.strictEqual(result, undefined);
9
+ assert.throws(
10
+ () => convert(`asyncapi: '2.1.0'`, '2.0.0'),
11
+ /^Error: Cannot downgrade from 2.1.0 to 2.0.0.$/
12
+ );
11
13
  });
12
14
 
13
15
  it('should not convert from non existing version', () => {
14
- const result = convert(`asyncapi: '2.0.0-rc3'`, '2.1.0');
15
- assert.strictEqual(result, undefined);
16
+ assert.throws(
17
+ () => convert(`asyncapi: '2.0.0-rc3'`, '2.1.0'),
18
+ /^Error: Cannot convert from 2.0.0-rc3 to 2.1.0.$/
19
+ );
16
20
  });
17
21
 
18
22
  it('should not convert to this same version', () => {
19
- const result = convert(`asyncapi: '2.1.0'`, '2.1.0');
20
- assert.strictEqual(result, undefined);
23
+ assert.throws(
24
+ () => convert(`asyncapi: '2.1.0'`, '2.1.0'),
25
+ /^Error: Cannot convert to the same version.$/
26
+ );
21
27
  });
22
28
 
23
29
  it('should convert from 1.0.0 to 2.0.0-rc1', () => {