@redocly/openapi-core 1.0.0-beta.105 → 1.0.0-beta.108

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 (240) hide show
  1. package/README.md +4 -4
  2. package/__tests__/utils.ts +5 -5
  3. package/lib/benchmark/benches/lint-with-top-level-rule-report.bench.js +0 -1
  4. package/lib/benchmark/benches/recommended-oas3.bench.js +1 -1
  5. package/lib/benchmark/utils.d.ts +2 -2
  6. package/lib/benchmark/utils.js +2 -2
  7. package/lib/bundle.d.ts +2 -2
  8. package/lib/bundle.js +7 -4
  9. package/lib/config/all.d.ts +2 -2
  10. package/lib/config/all.js +3 -3
  11. package/lib/config/builtIn.d.ts +2 -2
  12. package/lib/config/builtIn.js +2 -2
  13. package/lib/config/config-resolvers.d.ts +5 -5
  14. package/lib/config/config-resolvers.js +70 -49
  15. package/lib/config/config.d.ts +8 -10
  16. package/lib/config/config.js +10 -7
  17. package/lib/config/load.d.ts +7 -0
  18. package/lib/config/load.js +18 -10
  19. package/lib/config/minimal.d.ts +2 -2
  20. package/lib/config/minimal.js +5 -4
  21. package/lib/config/recommended.d.ts +2 -2
  22. package/lib/config/recommended.js +5 -4
  23. package/lib/config/rules.d.ts +3 -3
  24. package/lib/config/rules.js +1 -1
  25. package/lib/config/types.d.ts +23 -19
  26. package/lib/config/utils.d.ts +5 -5
  27. package/lib/config/utils.js +48 -31
  28. package/lib/decorators/common/registry-dependencies.js +1 -1
  29. package/lib/decorators/common/remove-x-internal.js +2 -2
  30. package/lib/env.d.ts +3 -0
  31. package/lib/env.js +8 -0
  32. package/lib/format/codeframes.js +16 -10
  33. package/lib/format/format.js +29 -27
  34. package/lib/index.d.ts +5 -5
  35. package/lib/index.js +4 -2
  36. package/lib/js-yaml/index.js +2 -6
  37. package/lib/lint.d.ts +2 -2
  38. package/lib/lint.js +16 -6
  39. package/lib/logger.d.ts +10 -0
  40. package/lib/logger.js +31 -0
  41. package/lib/output.d.ts +3 -0
  42. package/lib/output.js +9 -0
  43. package/lib/redocly/index.js +10 -9
  44. package/lib/redocly/registry-api-types.d.ts +28 -30
  45. package/lib/redocly/registry-api.d.ts +4 -3
  46. package/lib/redocly/registry-api.js +9 -4
  47. package/lib/ref-utils.js +2 -1
  48. package/lib/resolve.d.ts +1 -1
  49. package/lib/resolve.js +1 -1
  50. package/lib/rules/ajv.d.ts +1 -1
  51. package/lib/rules/ajv.js +7 -7
  52. package/lib/rules/common/assertions/asserts.js +4 -4
  53. package/lib/rules/common/assertions/index.js +1 -1
  54. package/lib/rules/common/info-license-url.d.ts +1 -1
  55. package/lib/rules/common/info-license-url.js +5 -10
  56. package/lib/rules/common/info-license.d.ts +2 -0
  57. package/lib/rules/common/info-license.js +17 -0
  58. package/lib/rules/common/no-enum-type-mismatch.js +1 -3
  59. package/lib/rules/common/no-invalid-parameter-examples.js +3 -3
  60. package/lib/rules/common/no-invalid-schema-examples.js +3 -3
  61. package/lib/rules/common/operation-operationId.js +1 -1
  62. package/lib/rules/common/operation-security-defined.js +1 -1
  63. package/lib/rules/common/path-not-include-query.js +1 -1
  64. package/lib/rules/common/paths-kebab-case.js +4 -1
  65. package/lib/rules/common/spec.js +3 -3
  66. package/lib/rules/oas2/index.js +4 -4
  67. package/lib/rules/oas2/remove-unused-components.js +5 -5
  68. package/lib/rules/oas3/index.js +6 -6
  69. package/lib/rules/oas3/no-empty-servers.js +1 -1
  70. package/lib/rules/oas3/no-invalid-media-type-examples.js +2 -2
  71. package/lib/rules/oas3/no-server-variables-empty-enum.d.ts +2 -0
  72. package/lib/rules/oas3/{no-servers-empty-enum.js → no-server-variables-empty-enum.js} +4 -4
  73. package/lib/rules/oas3/no-unused-components.js +1 -1
  74. package/lib/rules/oas3/remove-unused-components.js +5 -5
  75. package/lib/rules/other/stats.js +43 -14
  76. package/lib/rules/utils.d.ts +3 -2
  77. package/lib/rules/utils.js +20 -5
  78. package/lib/types/index.d.ts +2 -2
  79. package/lib/types/redocly-yaml.js +9 -8
  80. package/lib/utils.d.ts +5 -0
  81. package/lib/utils.js +22 -5
  82. package/lib/visitors.d.ts +1 -1
  83. package/lib/visitors.js +2 -2
  84. package/lib/walk.d.ts +2 -1
  85. package/lib/walk.js +6 -3
  86. package/package.json +2 -2
  87. package/src/__tests__/__snapshots__/bundle.test.ts.snap +141 -0
  88. package/src/__tests__/bundle.test.ts +68 -34
  89. package/src/__tests__/codeframes.test.ts +13 -14
  90. package/src/__tests__/js-yaml.test.ts +6 -4
  91. package/src/__tests__/lint.test.ts +74 -6
  92. package/src/__tests__/logger-browser.test.ts +53 -0
  93. package/src/__tests__/logger.test.ts +47 -0
  94. package/src/__tests__/login.test.ts +2 -2
  95. package/src/__tests__/normalizeVisitors.test.ts +4 -4
  96. package/src/__tests__/output-browser.test.ts +18 -0
  97. package/src/__tests__/output.test.ts +15 -0
  98. package/src/__tests__/ref-utils.test.ts +13 -13
  99. package/src/__tests__/resolve-http.test.ts +1 -1
  100. package/src/__tests__/resolve.test.ts +14 -11
  101. package/src/__tests__/utils-browser.test.ts +11 -0
  102. package/src/__tests__/utils.test.ts +7 -0
  103. package/src/__tests__/walk.test.ts +48 -56
  104. package/src/benchmark/benches/lint-with-many-rules.bench.ts +1 -1
  105. package/src/benchmark/benches/lint-with-nested-rule.bench.ts +1 -1
  106. package/src/benchmark/benches/lint-with-no-rules.bench.ts +1 -1
  107. package/src/benchmark/benches/lint-with-top-level-rule-report.bench.ts +1 -2
  108. package/src/benchmark/benches/lint-with-top-level-rule.bench.ts +1 -1
  109. package/src/benchmark/benches/recommended-oas3.bench.ts +3 -3
  110. package/src/benchmark/benches/resolve-with-no-external.bench.ts +1 -1
  111. package/src/benchmark/benchmark.js +9 -5
  112. package/src/benchmark/utils.ts +5 -5
  113. package/src/bundle.ts +24 -20
  114. package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +7 -5
  115. package/src/config/__tests__/config-resolvers.test.ts +123 -121
  116. package/src/config/__tests__/config.test.ts +111 -76
  117. package/src/config/__tests__/fixtures/resolve-config/api/plugin.js +4 -2
  118. package/src/config/__tests__/fixtures/resolve-config/plugin.js +4 -1
  119. package/src/config/__tests__/load.test.ts +79 -1
  120. package/src/config/__tests__/resolve-plugins.test.ts +3 -3
  121. package/src/config/__tests__/utils.test.ts +83 -0
  122. package/src/config/all.ts +5 -6
  123. package/src/config/builtIn.ts +5 -5
  124. package/src/config/config-resolvers.ts +161 -96
  125. package/src/config/config.ts +15 -13
  126. package/src/config/load.ts +34 -11
  127. package/src/config/minimal.ts +7 -6
  128. package/src/config/recommended.ts +7 -6
  129. package/src/config/rules.ts +6 -6
  130. package/src/config/types.ts +28 -19
  131. package/src/config/utils.ts +78 -57
  132. package/src/decorators/__tests__/filter-out.test.ts +8 -4
  133. package/src/decorators/__tests__/remove-x-internal.test.ts +5 -5
  134. package/src/decorators/common/filters/filter-helper.ts +1 -1
  135. package/src/decorators/common/info-description-override.ts +1 -1
  136. package/src/decorators/common/operation-description-override.ts +1 -1
  137. package/src/decorators/common/registry-dependencies.ts +1 -1
  138. package/src/decorators/common/remove-x-internal.ts +4 -4
  139. package/src/decorators/common/tag-description-override.ts +1 -1
  140. package/src/env.ts +5 -0
  141. package/src/format/codeframes.ts +18 -12
  142. package/src/format/format.ts +37 -42
  143. package/src/index.ts +8 -7
  144. package/src/js-yaml/index.ts +4 -8
  145. package/src/lint.ts +22 -18
  146. package/src/logger.ts +34 -0
  147. package/src/oas-types.ts +1 -6
  148. package/src/output.ts +7 -0
  149. package/src/redocly/__tests__/redocly-client.test.ts +25 -19
  150. package/src/redocly/index.ts +12 -7
  151. package/src/redocly/registry-api-types.ts +27 -29
  152. package/src/redocly/registry-api.ts +22 -12
  153. package/src/ref-utils.ts +4 -3
  154. package/src/resolve.ts +11 -8
  155. package/src/rules/__tests__/no-unresolved-refs.test.ts +4 -4
  156. package/src/rules/__tests__/utils.test.ts +160 -0
  157. package/src/rules/ajv.ts +7 -8
  158. package/src/rules/common/__tests__/info-description.test.ts +3 -3
  159. package/src/rules/common/__tests__/info-license.test.ts +2 -2
  160. package/src/rules/common/__tests__/license-url.test.ts +2 -2
  161. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -1
  162. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +8 -8
  163. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -1
  164. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +3 -3
  165. package/src/rules/common/__tests__/operation-2xx-response.test.ts +3 -3
  166. package/src/rules/common/__tests__/operation-4xx-response.test.ts +3 -3
  167. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +2 -2
  168. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -1
  169. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +4 -4
  170. package/src/rules/common/__tests__/operation-security-defined.test.ts +2 -2
  171. package/src/rules/common/__tests__/operation-singular-tag.test.ts +2 -2
  172. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +2 -2
  173. package/src/rules/common/__tests__/path-not-include-query.test.ts +2 -2
  174. package/src/rules/common/__tests__/path-params-defined.test.ts +3 -3
  175. package/src/rules/common/__tests__/paths-kebab-case.test.ts +15 -15
  176. package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +8 -8
  177. package/src/rules/common/__tests__/spec.test.ts +2 -2
  178. package/src/rules/common/__tests__/tag-description.test.ts +2 -2
  179. package/src/rules/common/__tests__/tags-alphabetical.test.ts +2 -2
  180. package/src/rules/common/assertions/__tests__/asserts.test.ts +513 -130
  181. package/src/rules/common/assertions/asserts.ts +4 -4
  182. package/src/rules/common/assertions/index.ts +7 -7
  183. package/src/rules/common/info-license-url.ts +4 -9
  184. package/src/rules/common/info-license.ts +15 -0
  185. package/src/rules/common/no-ambiguous-paths.ts +1 -1
  186. package/src/rules/common/no-enum-type-mismatch.ts +12 -9
  187. package/src/rules/common/no-invalid-parameter-examples.ts +4 -4
  188. package/src/rules/common/no-invalid-schema-examples.ts +4 -4
  189. package/src/rules/common/operation-operationId.ts +1 -1
  190. package/src/rules/common/operation-parameters-unique.ts +2 -2
  191. package/src/rules/common/operation-security-defined.ts +1 -1
  192. package/src/rules/common/path-not-include-query.ts +1 -1
  193. package/src/rules/common/path-params-defined.ts +1 -1
  194. package/src/rules/common/paths-kebab-case.ts +4 -1
  195. package/src/rules/common/scalar-property-missing-example.ts +1 -1
  196. package/src/rules/common/spec.ts +12 -9
  197. package/src/rules/no-unresolved-refs.ts +1 -1
  198. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  199. package/src/rules/oas2/__tests__/spec/info.test.ts +12 -12
  200. package/src/rules/oas2/__tests__/spec/operation.test.ts +4 -4
  201. package/src/rules/oas2/__tests__/spec/paths.test.ts +10 -10
  202. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +6 -2
  203. package/src/rules/oas2/__tests__/spec/utils.ts +6 -6
  204. package/src/rules/oas2/index.ts +3 -3
  205. package/src/rules/oas2/remove-unused-components.ts +14 -9
  206. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +3 -3
  207. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +16 -16
  208. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +2 -2
  209. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +13 -13
  210. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +2 -2
  211. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +3 -3
  212. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -1
  213. package/src/rules/oas3/__tests__/spec/callbacks.test.ts +1 -1
  214. package/src/rules/oas3/__tests__/spec/info.test.ts +12 -12
  215. package/src/rules/oas3/__tests__/spec/operation.test.ts +8 -8
  216. package/src/rules/oas3/__tests__/spec/paths.test.ts +10 -10
  217. package/src/rules/oas3/__tests__/spec/referenceableScalars.test.ts +12 -12
  218. package/src/rules/oas3/__tests__/spec/servers.test.ts +15 -15
  219. package/src/rules/oas3/__tests__/spec/spec.test.ts +6 -6
  220. package/src/rules/oas3/__tests__/spec/utils.ts +6 -6
  221. package/src/rules/oas3/index.ts +5 -5
  222. package/src/rules/oas3/no-empty-servers.ts +1 -1
  223. package/src/rules/oas3/no-invalid-media-type-examples.ts +14 -6
  224. package/src/rules/oas3/{no-servers-empty-enum.ts → no-server-variables-empty-enum.ts} +10 -11
  225. package/src/rules/oas3/no-unused-components.ts +1 -1
  226. package/src/rules/oas3/remove-unused-components.ts +21 -10
  227. package/src/rules/other/stats.ts +46 -17
  228. package/src/rules/utils.ts +20 -4
  229. package/src/types/index.ts +5 -5
  230. package/src/types/redocly-yaml.ts +9 -8
  231. package/src/typings/common.ts +9 -1
  232. package/src/typings/openapi.ts +1 -1
  233. package/src/utils.ts +26 -3
  234. package/src/visitors.ts +9 -9
  235. package/src/walk.ts +15 -11
  236. package/tsconfig.tsbuildinfo +1 -1
  237. package/lib/rules/common/license-url.d.ts +0 -2
  238. package/lib/rules/common/license-url.js +0 -12
  239. package/lib/rules/oas3/no-servers-empty-enum.d.ts +0 -2
  240. package/src/rules/common/license-url.ts +0 -10
@@ -17,7 +17,7 @@ describe('Location', () => {
17
17
  license:
18
18
  name: MIT
19
19
  url: https://google.com
20
- `,
20
+ `
21
21
  ),
22
22
  };
23
23
  const preciseLocation = getLineColLocation(loc);
@@ -37,7 +37,7 @@ describe('Location', () => {
37
37
  license:
38
38
  name: MIT
39
39
  url: https://google.com
40
- `,
40
+ `
41
41
  ),
42
42
  };
43
43
  const preciseLocation = getLineColLocation(loc);
@@ -57,7 +57,7 @@ describe('Location', () => {
57
57
  license:
58
58
  name: MIT
59
59
  url: https://google.com
60
- `,
60
+ `
61
61
  ),
62
62
  };
63
63
  const preciseLocation = getLineColLocation(loc);
@@ -77,7 +77,7 @@ describe('Location', () => {
77
77
  license:
78
78
  name: MIT
79
79
  url: https://google.com
80
- `,
80
+ `
81
81
  ),
82
82
  };
83
83
  const preciseLocation = getLineColLocation(loc);
@@ -98,7 +98,7 @@ describe('Location', () => {
98
98
  license:
99
99
  name: MIT
100
100
  url: https://google.com
101
- `,
101
+ `
102
102
  ),
103
103
  };
104
104
  const preciseLocation = getLineColLocation(loc);
@@ -106,7 +106,6 @@ describe('Location', () => {
106
106
  expect(preciseLocation.end).toEqual({ line: 2, col: 9 });
107
107
  });
108
108
 
109
-
110
109
  it('should return first line for empty doc', () => {
111
110
  const loc = {
112
111
  reportOnKey: false,
@@ -158,7 +157,7 @@ describe('codeframes', () => {
158
157
  license:
159
158
  name: MIT
160
159
  url: https://google.com
161
- `,
160
+ `
162
161
  ),
163
162
  };
164
163
 
@@ -222,7 +221,7 @@ describe('codeframes', () => {
222
221
  license:
223
222
  name: MIT
224
223
  url: https://google.com
225
- `,
224
+ `
226
225
  ),
227
226
  };
228
227
 
@@ -256,7 +255,7 @@ describe('codeframes', () => {
256
255
  name: MIT,
257
256
  url: https://google.com
258
257
  }
259
- `,
258
+ `
260
259
  ),
261
260
  };
262
261
 
@@ -299,7 +298,7 @@ describe('codeframes', () => {
299
298
  field5: MIT
300
299
  url: https://google.com
301
300
  openapi: 3.0.2
302
- `,
301
+ `
303
302
  ),
304
303
  };
305
304
 
@@ -343,7 +342,7 @@ describe('codeframes', () => {
343
342
  field3: MIT
344
343
  field4: MIT
345
344
  field5: MIT
346
- `,
345
+ `
347
346
  ),
348
347
  };
349
348
 
@@ -390,7 +389,7 @@ describe('codeframes', () => {
390
389
  in: wrong
391
390
  post:
392
391
  operationId: test2
393
- `,
392
+ `
394
393
  ),
395
394
  };
396
395
 
@@ -425,7 +424,7 @@ describe('codeframes', () => {
425
424
  license:
426
425
  name: MIT
427
426
  url: https://google.com
428
- `,
427
+ `
429
428
  ),
430
429
  };
431
430
 
@@ -483,7 +482,7 @@ describe('codeframes', () => {
483
482
  license:
484
483
  name: MIT
485
484
  url: https://google.com
486
- `,
485
+ `
487
486
  ),
488
487
  };
489
488
 
@@ -48,7 +48,7 @@ describe('js-yaml', () => {
48
48
 
49
49
  test('should correctly dump date and string', () => {
50
50
  expect(stringifyYaml(parseYaml(yamlToDump))).toMatchInlineSnapshot(
51
- `
51
+ `
52
52
  "date: '2022-01-21T11:29:56.694Z'
53
53
  dateWithoutQuotes: '2020-01-01'
54
54
  dateWithQuotes: '2020-01-01'
@@ -57,7 +57,8 @@ describe('js-yaml', () => {
57
57
  stringWithQuotes: test
58
58
  stringWithDoubleQuotes: test
59
59
  "
60
- `);
60
+ `
61
+ );
61
62
  });
62
63
 
63
64
  test('parse and stringify', () => {
@@ -65,7 +66,8 @@ describe('js-yaml', () => {
65
66
  });
66
67
 
67
68
  test('should throw an error for unsupported types', () => {
68
- expect(() => stringifyYaml({ foo: () => {} }))
69
- .toThrow('unacceptable kind of an object to dump [object Function]');
69
+ expect(() => stringifyYaml({ foo: () => {} })).toThrow(
70
+ 'unacceptable kind of an object to dump [object Function]'
71
+ );
70
72
  });
71
73
  });
@@ -49,7 +49,7 @@ describe('lint', () => {
49
49
  const document = parseYamlToDocument(
50
50
  outdent`
51
51
  apis: error string
52
- lint:
52
+ styleguide:
53
53
  plugins:
54
54
  - './local-plugin.js'
55
55
  extends:
@@ -107,14 +107,82 @@ describe('lint', () => {
107
107
  `);
108
108
  });
109
109
 
110
- it("'plugins' shouldn't be allowed in 'apis' -> 'lint' field", async () => {
110
+ it('lintConfig should detect wrong fields and suggest correct ones', async () => {
111
+ const document = parseYamlToDocument(
112
+ outdent`
113
+ api:
114
+ name@version:
115
+ root: ./file.yaml
116
+ syleguide:
117
+ rules:
118
+ operation-2xx-response: warn
119
+ `,
120
+ ''
121
+ );
122
+ const results = await lintConfig({ document });
123
+
124
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
125
+ Array [
126
+ Object {
127
+ "location": Array [
128
+ Object {
129
+ "pointer": "#/api",
130
+ "reportOnKey": true,
131
+ "source": "",
132
+ },
133
+ ],
134
+ "message": "Property \`api\` is not expected here.",
135
+ "ruleId": "configuration spec",
136
+ "severity": "error",
137
+ "suggest": Array [
138
+ "apis",
139
+ ],
140
+ },
141
+ Object {
142
+ "location": Array [
143
+ Object {
144
+ "pointer": "#/syleguide",
145
+ "reportOnKey": true,
146
+ "source": "",
147
+ },
148
+ ],
149
+ "message": "Property \`syleguide\` is not expected here.",
150
+ "ruleId": "configuration spec",
151
+ "severity": "error",
152
+ "suggest": Array [
153
+ "styleguide",
154
+ ],
155
+ },
156
+ ]
157
+ `);
158
+ });
159
+
160
+ it('lintConfig should work with legacy fields', async () => {
161
+ const document = parseYamlToDocument(
162
+ outdent`
163
+ apiDefinitions:
164
+ entry: ./file.yaml
165
+ lint:
166
+ rules:
167
+ operation-2xx-response: warn
168
+ referenceDocs:
169
+ showConsole: true
170
+ `,
171
+ ''
172
+ );
173
+ const results = await lintConfig({ document });
174
+
175
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
176
+ });
177
+
178
+ it("'plugins' shouldn't be allowed in 'apis' -> 'styleguide' field", async () => {
111
179
  const document = parseYamlToDocument(
112
180
  outdent`
113
181
  apis:
114
- lint:
182
+ styleguide:
115
183
  plugins:
116
184
  - './local-plugin.js'
117
- lint:
185
+ styleguide:
118
186
  plugins:
119
187
  - './local-plugin.js'
120
188
  `,
@@ -127,7 +195,7 @@ describe('lint', () => {
127
195
  Object {
128
196
  "location": Array [
129
197
  Object {
130
- "pointer": "#/apis/lint",
198
+ "pointer": "#/apis/styleguide",
131
199
  "reportOnKey": true,
132
200
  "source": "",
133
201
  },
@@ -140,7 +208,7 @@ describe('lint', () => {
140
208
  Object {
141
209
  "location": Array [
142
210
  Object {
143
- "pointer": "#/apis/lint/plugins",
211
+ "pointer": "#/apis/styleguide/plugins",
144
212
  "reportOnKey": true,
145
213
  "source": "",
146
214
  },
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import * as colorette from 'colorette';
6
+ import { logger, colorize } from '../logger';
7
+
8
+ describe('Logger in Browser', () => {
9
+ it('should call "console.error"', () => {
10
+ const error = jest.spyOn(console, 'error').mockImplementation();
11
+
12
+ logger.error('error');
13
+
14
+ expect(error).toBeCalledTimes(1);
15
+ expect(error).toBeCalledWith('error');
16
+
17
+ error.mockRestore();
18
+ });
19
+
20
+ it('should call "console.log"', () => {
21
+ const log = jest.spyOn(console, 'log').mockImplementation();
22
+
23
+ logger.info('info');
24
+
25
+ expect(log).toBeCalledTimes(1);
26
+ expect(log).toBeCalledWith('info');
27
+
28
+ log.mockRestore();
29
+ });
30
+
31
+ it('should call "console.warn"', () => {
32
+ const warn = jest.spyOn(console, 'warn').mockImplementation();
33
+
34
+ logger.warn('warn');
35
+
36
+ expect(warn).toBeCalledTimes(1);
37
+ expect(warn).toBeCalledWith('warn');
38
+
39
+ warn.mockRestore();
40
+ });
41
+ });
42
+
43
+ describe('colorize in Browser', () => {
44
+ it('should not call original colorette lib', () => {
45
+ const color = 'cyan';
46
+ const spyingCyan = jest.spyOn(colorette, color);
47
+
48
+ const colorized = colorize.cyan(color);
49
+
50
+ expect(spyingCyan).not.toBeCalled();
51
+ expect(colorized).toEqual(color);
52
+ });
53
+ });
@@ -0,0 +1,47 @@
1
+ import * as colorette from 'colorette';
2
+ import { logger, colorize } from '../logger';
3
+
4
+ describe('Logger in nodejs', () => {
5
+ let spyingStderr: jest.SpyInstance;
6
+
7
+ beforeEach(() => {
8
+ spyingStderr = jest.spyOn(process.stderr, 'write').mockImplementation();
9
+ });
10
+
11
+ afterEach(() => {
12
+ spyingStderr.mockRestore();
13
+ });
14
+
15
+ it('should call "process.stderr.write" for error severity', () => {
16
+ logger.error('error');
17
+
18
+ expect(spyingStderr).toBeCalledTimes(1);
19
+ expect(spyingStderr).toBeCalledWith(colorette.red('error'));
20
+ });
21
+
22
+ it('should call "process.stderr.write" for warn severity', () => {
23
+ logger.warn('warn');
24
+
25
+ expect(spyingStderr).toBeCalledTimes(1);
26
+ expect(spyingStderr).toBeCalledWith(colorette.yellow('warn'));
27
+ });
28
+
29
+ it('should call "process.stderr.write" for info severity', () => {
30
+ logger.info('info');
31
+
32
+ expect(spyingStderr).toBeCalledTimes(1);
33
+ expect(spyingStderr).toBeCalledWith('info');
34
+ });
35
+ });
36
+
37
+ describe('colorize in nodejs', () => {
38
+ it('should call original colorette lib', () => {
39
+ const color = 'cyan';
40
+ const spyingCyan = jest.spyOn(colorette, color);
41
+
42
+ const colorized = colorize.cyan(color);
43
+
44
+ expect(spyingCyan).toBeCalledWith(color);
45
+ expect(colorized).toEqual(colorette[color](color));
46
+ });
47
+ });
@@ -6,10 +6,10 @@ describe.skip('login', () => {
6
6
  Object.defineProperty(client, 'registryApi', {
7
7
  value: {
8
8
  setAccessTokens: jest.fn(),
9
- authStatus: jest.fn(() => true)
9
+ authStatus: jest.fn(() => true),
10
10
  },
11
11
  writable: true,
12
- configurable: true
12
+ configurable: true,
13
13
  });
14
14
  await client.login('token'); // TODO: bug with rewrite local config file
15
15
  expect(client.registryApi.setAccessTokens).toHaveBeenCalled();
@@ -22,7 +22,7 @@ describe('Normalize visitors', () => {
22
22
  ruleId,
23
23
  severity: 'error' as 'error',
24
24
  visitor: ruleset[ruleId]({}),
25
- })),
25
+ }))
26
26
  );
27
27
 
28
28
  const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
@@ -66,7 +66,7 @@ describe('Normalize visitors', () => {
66
66
  ruleId,
67
67
  severity: 'error' as 'error',
68
68
  visitor: ruleset[ruleId]({}),
69
- })),
69
+ }))
70
70
  );
71
71
 
72
72
  const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
@@ -104,7 +104,7 @@ describe('Normalize visitors', () => {
104
104
  ruleId,
105
105
  severity: 'error' as 'error',
106
106
  visitor: ruleset[ruleId]({}),
107
- })),
107
+ }))
108
108
  );
109
109
 
110
110
  const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
@@ -139,7 +139,7 @@ describe('Normalize visitors', () => {
139
139
  ruleId,
140
140
  severity: 'error' as 'error',
141
141
  visitor: ruleset[ruleId]({}),
142
- })),
142
+ }))
143
143
  );
144
144
 
145
145
  const normalized = normalizeVisitors(visitors, normalizeTypes(Oas3Types));
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import { output } from '../output';
6
+
7
+ describe('output', () => {
8
+ it('should ignore all parsable data in browser', () => {
9
+ const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation();
10
+ const data = '{ "errors" : [] }';
11
+
12
+ output.write(data);
13
+
14
+ expect(spyingStdout).not.toBeCalled();
15
+
16
+ spyingStdout.mockRestore();
17
+ });
18
+ });
@@ -0,0 +1,15 @@
1
+ import { output } from '../output';
2
+
3
+ describe('output', () => {
4
+ it('should write all parsable data to stdout', () => {
5
+ const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation();
6
+ const data = '{ "errors" : [] }';
7
+
8
+ output.write(data);
9
+
10
+ expect(spyingStdout).toBeCalledTimes(1);
11
+ expect(spyingStdout).toBeCalledWith(data);
12
+
13
+ spyingStdout.mockRestore();
14
+ });
15
+ });
@@ -2,7 +2,7 @@ import outdent from 'outdent';
2
2
  import { parseYamlToDocument } from '../../__tests__/utils';
3
3
  import { parseRef, refBaseName } from '../ref-utils';
4
4
  import { lintDocument } from '../lint';
5
- import { LintConfig } from '../config';
5
+ import { StyleguideConfig } from '../config';
6
6
  import { BaseResolver } from '../resolve';
7
7
 
8
8
  describe('ref-utils', () => {
@@ -84,37 +84,37 @@ describe('ref-utils', () => {
84
84
  name:
85
85
  type: string
86
86
  `,
87
- '',
87
+ ''
88
88
  );
89
89
 
90
90
  const result = await lintDocument({
91
91
  document,
92
92
  externalRefResolver: new BaseResolver(),
93
- config: new LintConfig({}),
93
+ config: new StyleguideConfig({}),
94
94
  });
95
95
 
96
96
  expect(result).toMatchInlineSnapshot(`Array []`);
97
97
  });
98
98
 
99
99
  describe('refBaseName', () => {
100
- it("returns base name for file reference", () => {
101
- expect(refBaseName("../testcase/Pet.yaml")).toStrictEqual("Pet");
100
+ it('returns base name for file reference', () => {
101
+ expect(refBaseName('../testcase/Pet.yaml')).toStrictEqual('Pet');
102
102
  });
103
103
 
104
- it("returns base name for local file reference", () => {
105
- expect(refBaseName("Cat.json")).toStrictEqual("Cat");
104
+ it('returns base name for local file reference', () => {
105
+ expect(refBaseName('Cat.json')).toStrictEqual('Cat');
106
106
  });
107
107
 
108
- it("returns base name for url reference", () => {
109
- expect(refBaseName("http://example.com/tests/crocodile.json")).toStrictEqual("crocodile");
108
+ it('returns base name for url reference', () => {
109
+ expect(refBaseName('http://example.com/tests/crocodile.json')).toStrictEqual('crocodile');
110
110
  });
111
111
 
112
- it("returns base name for file with multiple dots in name", () => {
113
- expect(refBaseName("feline.tiger.v1.yaml")).toStrictEqual("feline.tiger.v1");
112
+ it('returns base name for file with multiple dots in name', () => {
113
+ expect(refBaseName('feline.tiger.v1.yaml')).toStrictEqual('feline.tiger.v1');
114
114
  });
115
115
 
116
- it("returns base name for file without any dots in name", () => {
117
- expect(refBaseName("abcdefg")).toStrictEqual("abcdefg");
116
+ it('returns base name for file without any dots in name', () => {
117
+ expect(refBaseName('abcdefg')).toStrictEqual('abcdefg');
118
118
  });
119
119
  });
120
120
  });
@@ -19,7 +19,7 @@ describe('Resolve http-headers', () => {
19
19
  C:
20
20
  $ref: 'https://sample.com/test/a/test.yaml'
21
21
  `,
22
- 'foobar.yaml',
22
+ 'foobar.yaml'
23
23
  );
24
24
 
25
25
  const fetchMock = jest.fn(() => Promise.resolve({ ok: true, text: Promise.resolve('') }));
@@ -18,7 +18,7 @@ describe('collect refs', () => {
18
18
  contact: {}
19
19
  license: {}
20
20
  `,
21
- 'foobar.yaml',
21
+ 'foobar.yaml'
22
22
  );
23
23
 
24
24
  const resolvedRefs = await resolveDocument({
@@ -35,7 +35,7 @@ describe('collect refs', () => {
35
35
  Array [
36
36
  "foobar.yaml::#/defs/info",
37
37
  ]
38
- `,
38
+ `
39
39
  );
40
40
  expect(Array.from(resolvedRefs.values()).map((info) => info.node)).toEqual([
41
41
  { contact: {}, license: {} },
@@ -56,7 +56,7 @@ describe('collect refs', () => {
56
56
  contact: {}
57
57
  license: {}
58
58
  `,
59
- '',
59
+ ''
60
60
  );
61
61
 
62
62
  try {
@@ -89,7 +89,7 @@ describe('collect refs', () => {
89
89
  contact: {}
90
90
  license: {}
91
91
  `,
92
- 'foobar.yaml',
92
+ 'foobar.yaml'
93
93
  );
94
94
 
95
95
  const resolvedRefs = await resolveDocument({
@@ -125,7 +125,7 @@ describe('collect refs', () => {
125
125
  loop2:
126
126
  $ref: '#/info'
127
127
  `,
128
- 'foobar.yaml',
128
+ 'foobar.yaml'
129
129
  );
130
130
 
131
131
  try {
@@ -147,7 +147,7 @@ describe('collect refs', () => {
147
147
  info:
148
148
  $ref: "./externalInfo.yaml#/info"
149
149
  `,
150
- path.join(cwd, 'foobar.yaml'),
150
+ path.join(cwd, 'foobar.yaml')
151
151
  );
152
152
 
153
153
  const resolvedRefs = await resolveDocument({
@@ -181,7 +181,7 @@ describe('collect refs', () => {
181
181
  const externalRefResolver = new BaseResolver();
182
182
  const rootDocument = await externalRefResolver.resolveDocument(
183
183
  null,
184
- `${cwd}/openapi-with-back.yaml`,
184
+ `${cwd}/openapi-with-back.yaml`
185
185
  );
186
186
 
187
187
  const resolvedRefs = await resolveDocument({
@@ -192,8 +192,11 @@ describe('collect refs', () => {
192
192
 
193
193
  expect(resolvedRefs).toBeDefined();
194
194
 
195
- expect(Array.from(resolvedRefs.keys()).map((ref) => ref.substring(cwd.length + 1)).sort())
196
- .toMatchInlineSnapshot(`
195
+ expect(
196
+ Array.from(resolvedRefs.keys())
197
+ .map((ref) => ref.substring(cwd.length + 1))
198
+ .sort()
199
+ ).toMatchInlineSnapshot(`
197
200
  Array [
198
201
  "openapi-with-back.yaml::./schemas/type-a.yaml#/",
199
202
  "openapi-with-back.yaml::./schemas/type-b.yaml#/",
@@ -345,7 +348,7 @@ describe('collect refs', () => {
345
348
  const externalRefResolver = new BaseResolver();
346
349
  const rootDocument = await externalRefResolver.resolveDocument(
347
350
  null,
348
- `${cwd}/openapi-with-md-description.yaml`,
351
+ `${cwd}/openapi-with-md-description.yaml`
349
352
  );
350
353
 
351
354
  expect(rootDocument).toBeDefined();
@@ -383,7 +386,7 @@ describe('collect refs', () => {
383
386
  components:
384
387
  $ref: "./transitive/components.yaml#/components/schemas/a"
385
388
  `,
386
- path.join(cwd, 'foobar.yaml'),
389
+ path.join(cwd, 'foobar.yaml')
387
390
  );
388
391
 
389
392
  const resolvedRefs = await resolveDocument({
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import { isBrowser } from '../env';
6
+
7
+ describe('isBrowser', () => {
8
+ it('should be browser', () => {
9
+ expect(isBrowser).toBe(true);
10
+ });
11
+ });
@@ -5,6 +5,7 @@ import {
5
5
  getMatchingStatusCodeRange,
6
6
  doesYamlFileExist,
7
7
  } from '../utils';
8
+ import { isBrowser } from '../env';
8
9
  import * as fs from 'fs';
9
10
  import * as path from 'path';
10
11
 
@@ -122,5 +123,11 @@ describe('utils', () => {
122
123
  expect(doesYamlFileExist('redocly.yam')).toBe(false);
123
124
  });
124
125
  });
126
+
127
+ describe('isBrowser', () => {
128
+ it('should not be browser', () => {
129
+ expect(isBrowser).toBe(false);
130
+ });
131
+ });
125
132
  });
126
133
  });