@asyncapi/converter 0.6.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.
Files changed (39) hide show
  1. package/.github/workflows/automerge-orphans.yml +63 -0
  2. package/.github/workflows/automerge.yml +47 -0
  3. package/.github/workflows/bump.yml +32 -0
  4. package/.github/workflows/if-go-pr-testing.yml +58 -0
  5. package/.github/workflows/if-nodejs-pr-testing.yml +48 -0
  6. package/.github/workflows/if-nodejs-release.yml +70 -0
  7. package/.github/workflows/if-nodejs-version-bump.yml +48 -0
  8. package/.github/workflows/issues-prs-notifications.yml +72 -0
  9. package/.github/workflows/lint-pr-title.yml +22 -0
  10. package/.github/workflows/release-announcements.yml +76 -0
  11. package/.github/workflows/sentiment-analysis.yml +44 -0
  12. package/.github/workflows/stale-issues-prs.yml +30 -0
  13. package/.github/workflows/welcome-first-time-contrib.yml +34 -0
  14. package/README.md +60 -0
  15. package/cli.js +47 -0
  16. package/lib/helpers.js +91 -0
  17. package/lib/index.js +204 -0
  18. package/package.json +70 -0
  19. package/test/index.js +194 -0
  20. package/test/input/1.0.0/streetlights.yml +120 -0
  21. package/test/input/1.1.0/streetlights.yml +120 -0
  22. package/test/input/1.2.0/gitter-streaming.yml +140 -0
  23. package/test/input/1.2.0/slack-rtm.yml +876 -0
  24. package/test/input/1.2.0/streetlights.yml +120 -0
  25. package/test/input/2.0.0/streetlights.yml +113 -0
  26. package/test/input/2.0.0-rc1/streetlights.yml +109 -0
  27. package/test/input/2.0.0-rc2/streetlights.yml +113 -0
  28. package/test/input/2.1.0/streetlights.yml +113 -0
  29. package/test/output/2.0.0/gitter-streaming.yml +137 -0
  30. package/test/output/2.0.0/slack-rtm.yml +879 -0
  31. package/test/output/2.0.0/streetlights.yml +113 -0
  32. package/test/output/2.0.0-rc1/gitter-streaming.yml +137 -0
  33. package/test/output/2.0.0-rc1/slack-rtm.yml +879 -0
  34. package/test/output/2.0.0-rc1/streetlights.yml +109 -0
  35. package/test/output/2.0.0-rc2/gitter-streaming.yml +137 -0
  36. package/test/output/2.0.0-rc2/slack-rtm.yml +879 -0
  37. package/test/output/2.0.0-rc2/streetlights.yml +113 -0
  38. package/test/output/2.1.0/streetlights.yml +113 -0
  39. package/test/output/2.2.0/streetlights.yml +113 -0
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # AsyncAPI Converter
2
+
3
+ Convert [AsyncAPI](https://asyncapi.com) documents older to newer versions.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm i -g @asyncapi/converter
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### From CLI
14
+
15
+ Minimal example:
16
+
17
+ ```sh
18
+ asyncapi-converter streetlights.yml
19
+
20
+ # Result:
21
+ asyncapi: '2.0.0'
22
+ channels:
23
+ ...
24
+ ```
25
+
26
+ Specify the application id:
27
+
28
+ ```sh
29
+ asyncapi-converter --id=urn:com.asynapi.streetlights streetlights.yml
30
+
31
+ # Result:
32
+ asyncapi: '2.0.0'
33
+ id: 'urn:com.asynapi.streetlights'
34
+ ...
35
+ ```
36
+
37
+ Save the result in a file:
38
+
39
+ ```sh
40
+ asyncapi-converter streetlights.yml > streetlights2.yml
41
+ ```
42
+
43
+ ### As a package
44
+
45
+ ```js
46
+ const { convert } = require('@asyncapi/converter')
47
+
48
+ try {
49
+ const asyncapi = fs.readFileSync('streetlights.yml', 'utf-8')
50
+ console.log(convert(asyncapi, '2.0.0', {
51
+ id: 'urn:com.asyncapi.streetlights'
52
+ }))
53
+ } catch (e) {
54
+ console.error(e)
55
+ }
56
+ ```
57
+
58
+ ## Known missing features
59
+
60
+ * When converting from 1.x to 2.x, Streaming APIs (those using `stream` instead of `topics` or `events`) are converted correctly but information about framing type and delimiter is missing until a [protocolInfo](https://github.com/asyncapi/extensions-catalog/issues/1) for that purpose is created.
package/cli.js ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const program = require('commander');
6
+ const packageInfo = require('./package.json');
7
+ const converter = require('./lib');
8
+
9
+ const red = text => `\x1b[31m${text}\x1b[0m`;
10
+
11
+ let asyncapiFile;
12
+ let version;
13
+
14
+ const showErrorAndExit = err => {
15
+ console.error(red('Something went wrong:'));
16
+ console.error(red(err.stack || err.message));
17
+ process.exit(1);
18
+ };
19
+
20
+ program
21
+ .version(packageInfo.version)
22
+ .arguments('<document> [version]')
23
+ .action((asyncAPIPath, v) => {
24
+ asyncapiFile = path.resolve(asyncAPIPath);
25
+ version = v;
26
+ })
27
+ .option('--id <id>', 'application id (defaults to a generated one)')
28
+ .parse(process.argv);
29
+
30
+ if (!asyncapiFile) {
31
+ console.error(red('> Path to AsyncAPI file not provided.'));
32
+ program.help(); // This exits the process
33
+ }
34
+ if (!version) {
35
+ version = '2.1.0';
36
+ }
37
+
38
+ try {
39
+ const asyncapi = fs.readFileSync(asyncapiFile, 'utf-8');
40
+ console.log(converter.convert(asyncapi, version, {
41
+ id: program.id,
42
+ }));
43
+ } catch (e) {
44
+ showErrorAndExit(e);
45
+ }
46
+
47
+ process.on('unhandledRejection', showErrorAndExit);
package/lib/helpers.js ADDED
@@ -0,0 +1,91 @@
1
+ const _ = require('lodash');
2
+ const yaml = require('js-yaml');
3
+ const helpers = module.exports;
4
+
5
+ helpers.serialize = (text) => {
6
+ try {
7
+ return {
8
+ isYAML: true,
9
+ parsed: yaml.safeLoad(text)
10
+ };
11
+ } catch (e) {
12
+ try {
13
+ return {
14
+ isYAML: false,
15
+ parsed: JSON.parse(text)
16
+ };
17
+ } catch (err) {
18
+ throw new Error('AsyncAPI document must be a valid JSON or YAML document.');
19
+ }
20
+ }
21
+ };
22
+
23
+ helpers.dotsToSlashes = topic => topic.replace(/\./g, '/');
24
+
25
+ helpers.eventToChannel = event => {
26
+ const out = {};
27
+ if (event.receive) {
28
+ out.publish = {
29
+ message: {
30
+ oneOf: event.receive
31
+ }
32
+ }
33
+ }
34
+ if (event.send) {
35
+ out.subscribe = {
36
+ message: {
37
+ oneOf: event.send
38
+ }
39
+ }
40
+ }
41
+
42
+ return out;
43
+ };
44
+
45
+ helpers.streamToChannel = event => {
46
+ const out = {};
47
+ if (event.read) {
48
+ out.publish = {
49
+ message: {
50
+ oneOf: event.read
51
+ }
52
+ }
53
+ }
54
+ if (event.write) {
55
+ out.subscribe = {
56
+ message: {
57
+ oneOf: event.write
58
+ }
59
+ }
60
+ }
61
+
62
+ return out;
63
+ };
64
+
65
+ const objectToSchema = obj => {
66
+ const schema = { type: 'object', properties: {} };
67
+ _.each(obj, (prop, propName) => {
68
+ schema.properties[propName] = prop;
69
+ });
70
+ return obj;
71
+ };
72
+
73
+ helpers.convertMessage = message => {
74
+ if (message.oneOf) {
75
+ message.oneOf.forEach(m => {
76
+ if (m.protocolInfo) {
77
+ m.bindings = m.protocolInfo;
78
+ delete m.protocolInfo;
79
+ }
80
+
81
+ if (m.headers) m.headers = objectToSchema(m.headers);
82
+ });
83
+ } else {
84
+ if (message.protocolInfo) {
85
+ message.bindings = message.protocolInfo;
86
+ delete message.protocolInfo;
87
+ }
88
+
89
+ if (message.headers) message.headers = objectToSchema(message.headers);
90
+ }
91
+ }
package/lib/index.js ADDED
@@ -0,0 +1,204 @@
1
+ const yaml = require('js-yaml');
2
+ const _ = require('lodash');
3
+ const {
4
+ serialize,
5
+ dotsToSlashes,
6
+ eventToChannel,
7
+ streamToChannel,
8
+ convertMessage,
9
+ } = require('./helpers');
10
+
11
+ const lib = module.exports;
12
+
13
+ /**
14
+ * Value for key (version) represents the function which converts specification from previous version to the given as key.
15
+ */
16
+ const conversions = {
17
+ '1.0.0': undefined,
18
+ '1.1.0': from__1_0_0__to__1_1_0,
19
+ '1.2.0': from__1_1_0__to__1_2_0,
20
+ '2.0.0-rc1': from__1_2_0__to__2_0_0_rc1,
21
+ '2.0.0-rc2': from__2_0_0_rc1__to__2_0_0_rc2,
22
+ '2.0.0': from__2_0_0_rc2__to__2_0_0,
23
+ '2.1.0': from__2_0_0__to__2_1_0,
24
+ '2.2.0': from__2_1_0__to__2_2_0,
25
+ }
26
+ const conversionVersions = Object.keys(conversions);
27
+
28
+ lib.convert = (asyncapi, version, options = {}) => {
29
+ const { isYAML, parsed } = serialize(asyncapi);
30
+ if (parsed === undefined) return '';
31
+
32
+ let fromVersion = conversionVersions.indexOf(parsed.asyncapi);
33
+ const toVersion = conversionVersions.indexOf(version);
34
+
35
+ if (fromVersion === -1 || toVersion === -1) {
36
+ console.error(`Cannot convert from ${parsed.asyncapi} to ${version}.`);
37
+ return;
38
+ }
39
+ if (fromVersion > toVersion) {
40
+ console.error(`Cannot downgrade from ${parsed.asyncapi} to ${version}.`);
41
+ return;
42
+ }
43
+ if (fromVersion === toVersion) {
44
+ console.error(`Cannot convert to the same version.`);
45
+ return;
46
+ }
47
+
48
+ // add 1 to `fromVersion` because we convert from previous to next
49
+ fromVersion++;
50
+ let converted = parsed;
51
+ for (let i = fromVersion; i <= toVersion; i++) {
52
+ const fn = conversions[conversionVersions[i]];
53
+ converted = fn(converted, options);
54
+ }
55
+
56
+ if (isYAML) {
57
+ converted = yaml.safeDump(converted, { skipInvalid: true });
58
+ }
59
+ return converted;
60
+ };
61
+
62
+ function from__1_0_0__to__1_1_0(asyncapi) {
63
+ return asyncapi;
64
+ }
65
+
66
+ function from__1_1_0__to__1_2_0(asyncapi) {
67
+ return asyncapi;
68
+ }
69
+
70
+ function from__1_2_0__to__2_0_0_rc1(asyncapi1, options) { // NOSONAR
71
+ const result = asyncapi1;
72
+
73
+ result.asyncapi = '2.0.0-rc1';
74
+ result.id = options.id || `urn:${asyncapi1.info.title.toLowerCase().split(' ').join('.')}`;
75
+
76
+ if (asyncapi1.servers) {
77
+ const security = asyncapi1.security;
78
+ result.servers = asyncapi1.servers.map(server => {
79
+ const { scheme, schemeVersion, ...rest } = server;
80
+
81
+ const out = {
82
+ ...rest,
83
+ ...{
84
+ protocol: scheme,
85
+ }
86
+ };
87
+
88
+ if (schemeVersion) out.protocolVersion = schemeVersion;
89
+
90
+ if (security) {
91
+ out.security = security;
92
+ }
93
+
94
+ return out;
95
+ });
96
+ }
97
+
98
+ if (asyncapi1.topics) {
99
+ result.channels = _.mapKeys(result.topics, (_, topicName) => dotsToSlashes(`${asyncapi1.baseTopic ? `${asyncapi1.baseTopic}.` : ''}${topicName}`));
100
+ _.map(result.channels, ch => {
101
+ if (ch.publish) {
102
+ ch.publish = { message: ch.publish };
103
+ }
104
+ if (ch.subscribe) {
105
+ ch.subscribe = { message: ch.subscribe };
106
+ }
107
+ });
108
+ } else if (asyncapi1.stream) {
109
+ result.channels = {
110
+ '/': streamToChannel(asyncapi1.stream),
111
+ };
112
+ } else if (asyncapi1.events) {
113
+ result.channels = {
114
+ '/': eventToChannel(asyncapi1.events),
115
+ };
116
+ }
117
+
118
+ delete result.topics;
119
+ delete result.stream;
120
+ delete result.events;
121
+ delete result.baseTopic;
122
+ delete result.security;
123
+
124
+ return result;
125
+ }
126
+
127
+ function from__2_0_0_rc1__to__2_0_0_rc2(asyncapi2rc1, options) { // NOSONAR
128
+ const result = asyncapi2rc1;
129
+
130
+ result.asyncapi = '2.0.0-rc2';
131
+ result.id = result.id || options.id;
132
+
133
+ if (asyncapi2rc1.servers) {
134
+ const serverMap = {};
135
+ asyncapi2rc1.servers.forEach((server, index) => {
136
+ if (server.baseChannel) delete server.baseChannel;
137
+ const name = index === 0 ? 'default' : `server${index}`;
138
+ serverMap[name] = server;
139
+ });
140
+ result.servers = serverMap;
141
+ }
142
+
143
+ if (result.channels) {
144
+ _.each(result.channels, (channel, channelName) => {
145
+ if (channel.parameters) {
146
+ const parametersMap = {};
147
+ const paramNames = channelName.match(/\{([^\}]{1,100})\}/g).map(p => p.substr(1, p.length - 2));
148
+ channel.parameters.forEach((parameter, index) => {
149
+ const name = parameter.name || paramNames[index];
150
+ if (parameter.name) delete parameter.name;
151
+ parametersMap[name] = parameter;
152
+ });
153
+ channel.parameters = parametersMap;
154
+ }
155
+
156
+ if (channel.publish && channel.publish.message) {
157
+ const message = channel.publish.message;
158
+ convertMessage(message);
159
+ }
160
+
161
+ if (channel.subscribe && channel.subscribe.message) {
162
+ const message = channel.subscribe.message;
163
+ convertMessage(message);
164
+ }
165
+
166
+ if (channel.protocolInfo) {
167
+ channel.bindings = channel.protocolInfo;
168
+ delete channel.protocolInfo;
169
+ }
170
+
171
+ if (channel.publish && channel.publish.protocolInfo) {
172
+ channel.publish.bindings = channel.publish.protocolInfo;
173
+ delete channel.publish.protocolInfo;
174
+ }
175
+
176
+ if (channel.subscribe && channel.subscribe.protocolInfo) {
177
+ channel.subscribe.bindings = channel.subscribe.protocolInfo;
178
+ delete channel.subscribe.protocolInfo;
179
+ }
180
+ });
181
+ }
182
+
183
+ if (!options.id) delete result.id;
184
+ return result;
185
+ }
186
+
187
+ function from__2_0_0_rc2__to__2_0_0(asyncapi2rc2, options) {
188
+ const result = asyncapi2rc2;
189
+ if (!options.id) delete result.id;
190
+ result.asyncapi = '2.0.0';
191
+ return result;
192
+ }
193
+
194
+ function from__2_0_0__to__2_1_0(asyncapi2) {
195
+ const result = asyncapi2;
196
+ result.asyncapi = '2.1.0';
197
+ return result;
198
+ }
199
+
200
+ function from__2_1_0__to__2_2_0(asyncapi2) {
201
+ const result = asyncapi2;
202
+ result.asyncapi = '2.2.0';
203
+ return result;
204
+ }
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@asyncapi/converter",
3
+ "version": "0.6.0",
4
+ "description": "Convert AsyncAPI documents from older to newer versions.",
5
+ "bin": {
6
+ "asyncapi-converter": "cli.js"
7
+ },
8
+ "main": "lib/index.js",
9
+ "scripts": {
10
+ "test": "mocha",
11
+ "lint": "echo 'no linter configured yet'",
12
+ "release": "semantic-release",
13
+ "generate:assets": "echo 'No additional assets need to be generated at the moment'",
14
+ "bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION"
15
+ },
16
+ "keywords": [
17
+ "asyncapi",
18
+ "upgrade",
19
+ "version",
20
+ "convert"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/asyncapi/converter-js.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/asyncapi/converter-js/issues"
28
+ },
29
+ "homepage": "https://github.com/asyncapi/converter-js#readme",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "author": "Fran Mendez <fmvilas@gmail.com> (fmvilas.com)",
34
+ "license": "Apache-2.0",
35
+ "dependencies": {
36
+ "commander": "^2.20.0",
37
+ "js-yaml": "^3.13.1",
38
+ "lodash": "^4.17.15",
39
+ "mocha": "^6.1.4"
40
+ },
41
+ "devDependencies": {
42
+ "@semantic-release/commit-analyzer": "^8.0.1",
43
+ "@semantic-release/github": "^7.0.4",
44
+ "@semantic-release/npm": "^7.0.3",
45
+ "@semantic-release/release-notes-generator": "^9.0.1",
46
+ "conventional-changelog-conventionalcommits": "^4.2.3",
47
+ "semantic-release": "^17.0.4"
48
+ },
49
+ "release": {
50
+ "branches": [
51
+ "master"
52
+ ],
53
+ "plugins": [
54
+ [
55
+ "@semantic-release/commit-analyzer",
56
+ {
57
+ "preset": "conventionalcommits"
58
+ }
59
+ ],
60
+ [
61
+ "@semantic-release/release-notes-generator",
62
+ {
63
+ "preset": "conventionalcommits"
64
+ }
65
+ ],
66
+ "@semantic-release/npm",
67
+ "@semantic-release/github"
68
+ ]
69
+ }
70
+ }
package/test/index.js ADDED
@@ -0,0 +1,194 @@
1
+ const assert = require('assert');
2
+ const fs = require('fs');
3
+ const path = require("path");
4
+ const { convert } = require('../lib');
5
+
6
+ describe('#convert', () => {
7
+ it('should not convert to lowest version', () => {
8
+ const result = convert(`asyncapi: '2.1.0'`, '2.0.0');
9
+ assert.strictEqual(result, undefined);
10
+ });
11
+
12
+ it('should not convert from non existing version', () => {
13
+ const result = convert(`asyncapi: '2.0.0-rc3'`, '2.1.0');
14
+ assert.strictEqual(result, undefined);
15
+ });
16
+
17
+ it('should not convert to this same version', () => {
18
+ const result = convert(`asyncapi: '2.1.0'`, '2.1.0');
19
+ assert.strictEqual(result, undefined);
20
+ });
21
+
22
+ it('should convert from 1.0.0 to 2.0.0-rc1', () => {
23
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
24
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
25
+ const result = convert(input, '2.0.0-rc1');
26
+ assertResults(output, result);
27
+ });
28
+
29
+ it('should convert from 1.1.0 to 2.0.0-rc1', () => {
30
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
31
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
32
+ const result = convert(input, '2.0.0-rc1');
33
+ assertResults(output, result);
34
+ });
35
+
36
+ it('should convert from 1.2.0 to 2.0.0-rc1', () => {
37
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
38
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
39
+ const result = convert(input, '2.0.0-rc1');
40
+ assertResults(output, result);
41
+ });
42
+
43
+ it('should convert from 1.2.0 to 2.0.0-rc1 - stream', () => {
44
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'gitter-streaming.yml'), 'utf8');
45
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'gitter-streaming.yml'), 'utf8');
46
+ const result = convert(input, '2.0.0-rc1');
47
+ assertResults(output, result);
48
+ });
49
+
50
+ it('should convert from 1.2.0 to 2.0.0-rc1 - events', () => {
51
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'slack-rtm.yml'), 'utf8');
52
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc1', 'slack-rtm.yml'), 'utf8');
53
+ const result = convert(input, '2.0.0-rc1');
54
+ assertResults(output, result);
55
+ });
56
+
57
+ it('should convert from 1.0.0 to 2.0.0-rc2', () => {
58
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
59
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
60
+ const result = convert(input, '2.0.0-rc2');
61
+ assertResults(output, result);
62
+ });
63
+
64
+ it('should convert from 1.1.0 to 2.0.0-rc2', () => {
65
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
66
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
67
+ const result = convert(input, '2.0.0-rc2');
68
+ assertResults(output, result);
69
+ });
70
+
71
+ it('should convert from 1.2.0 to 2.0.0-rc2 - stream', () => {
72
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'gitter-streaming.yml'), 'utf8');
73
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'gitter-streaming.yml'), 'utf8');
74
+ const result = convert(input, '2.0.0-rc2');
75
+ assertResults(output, result);
76
+ });
77
+
78
+ it('should convert from 1.2.0 to 2.0.0-rc2 - events', () => {
79
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'slack-rtm.yml'), 'utf8');
80
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'slack-rtm.yml'), 'utf8');
81
+ const result = convert(input, '2.0.0-rc2');
82
+ assertResults(output, result);
83
+ });
84
+
85
+ it('should convert from 1.2.0 to 2.0.0-rc2', () => {
86
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
87
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
88
+ const result = convert(input, '2.0.0-rc2');
89
+ assertResults(output, result);
90
+ });
91
+
92
+ it('should convert from 1.0.0 to 2.0.0', () => {
93
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
94
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
95
+ const result = convert(input, '2.0.0');
96
+ assertResults(output, result);
97
+ });
98
+
99
+ it('should convert from 1.1.0 to 2.0.0', () => {
100
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
101
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
102
+ const result = convert(input, '2.0.0');
103
+ assertResults(output, result);
104
+ });
105
+
106
+ it('should convert from 1.2.0 to 2.0.0', () => {
107
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
108
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
109
+ const result = convert(input, '2.0.0');
110
+ assertResults(output, result);
111
+ });
112
+
113
+ it('should convert from 2.0.0-rc1 to 2.0.0', () => {
114
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
115
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
116
+ const result = convert(input, '2.0.0');
117
+ assertResults(output, result);
118
+ });
119
+
120
+ it('should convert from 2.0.0-rc2 to 2.0.0', () => {
121
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
122
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.0.0', 'streetlights.yml'), 'utf8');
123
+ const result = convert(input, '2.0.0');
124
+ assertResults(output, result);
125
+ });
126
+
127
+ it('should convert from 1.0.0 to 2.1.0', () => {
128
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.0.0', 'streetlights.yml'), 'utf8');
129
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
130
+ const result = convert(input, '2.1.0');
131
+ assertResults(output, result);
132
+ });
133
+
134
+ it('should convert from 1.1.0 to 2.1.0', () => {
135
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.1.0', 'streetlights.yml'), 'utf8');
136
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
137
+ const result = convert(input, '2.1.0');
138
+ assertResults(output, result);
139
+ });
140
+
141
+ it('should convert from 1.2.0 to 2.1.0', () => {
142
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '1.2.0', 'streetlights.yml'), 'utf8');
143
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
144
+ const result = convert(input, '2.1.0');
145
+ assertResults(output, result);
146
+ });
147
+
148
+ it('should convert from 2.0.0-rc1 to 2.1.0', () => {
149
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc1', 'streetlights.yml'), 'utf8');
150
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
151
+ const result = convert(input, '2.1.0');
152
+ assertResults(output, result);
153
+ });
154
+
155
+ it('should convert from 2.0.0-rc2 to 2.1.0', () => {
156
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0-rc2', 'streetlights.yml'), 'utf8');
157
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
158
+ const result = convert(input, '2.1.0');
159
+ assertResults(output, result);
160
+ });
161
+
162
+ it('should convert from 2.0.0 to 2.1.0', () => {
163
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0', 'streetlights.yml'), 'utf8');
164
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.1.0', 'streetlights.yml'), 'utf8');
165
+ const result = convert(input, '2.1.0');
166
+ assertResults(output, result);
167
+ });
168
+
169
+ it('should convert from 2.0.0 to 2.2.0', () => {
170
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.0.0', 'streetlights.yml'), 'utf8');
171
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.2.0', 'streetlights.yml'), 'utf8');
172
+ const result = convert(input, '2.2.0');
173
+ assertResults(output, result);
174
+ });
175
+
176
+ it('should convert from 2.1.0 to 2.2.0', () => {
177
+ const input = fs.readFileSync(path.resolve(__dirname, 'input', '2.1.0', 'streetlights.yml'), 'utf8');
178
+ const output = fs.readFileSync(path.resolve(__dirname, 'output', '2.2.0', 'streetlights.yml'), 'utf8');
179
+ const result = convert(input, '2.2.0');
180
+ assertResults(output, result);
181
+ });
182
+ });
183
+
184
+ /*
185
+ It is a helper required for testing on windows. It can't be solved by editor configuration and the end line setting because expected result is converted during tests.
186
+ We need to remove all line breaks from the string
187
+ */
188
+ function removeLineBreaks(str) {
189
+ return str.replace(/\r?\n|\r/g, '')
190
+ }
191
+
192
+ function assertResults(output, result){
193
+ assert.strictEqual(removeLineBreaks(output), removeLineBreaks(result));
194
+ }