@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 +3 -6
- package/package.json +1 -1
- package/test/index.js +12 -6
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
|
-
|
|
38
|
-
return;
|
|
37
|
+
throw new Error(`Cannot convert from ${parsed.asyncapi} to ${version}.`);
|
|
39
38
|
}
|
|
40
39
|
if (fromVersion > toVersion) {
|
|
41
|
-
|
|
42
|
-
return;
|
|
40
|
+
throw new Error(`Cannot downgrade from ${parsed.asyncapi} to ${version}.`);
|
|
43
41
|
}
|
|
44
42
|
if (fromVersion === toVersion) {
|
|
45
|
-
|
|
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
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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', () => {
|