Skip to content

Commit 1b6bf5d

Browse files
authored
fix: remove obsolete try...catch (#176)
1 parent 4b54aa5 commit 1b6bf5d

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

src/util.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ export const resolve = async (
5454
) => {
5555
const docs = [];
5656

57-
try {
58-
for (const asyncapiDocument of asyncapiDocuments) {
59-
await parse(asyncapiDocument, specVersion, options);
60-
docs.push(asyncapiDocument);
61-
}
62-
} catch (e) {} // eslint-disable-line
57+
for (const asyncapiDocument of asyncapiDocuments) {
58+
await parse(asyncapiDocument, specVersion, options);
59+
docs.push(asyncapiDocument);
60+
}
6361

6462
return docs;
6563
};

tests/lib/index.spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ import { describe, expect, test } from '@jest/globals';
22
import bundle from '../../src';
33
import { isExternalReference } from '../../src/util';
44
import path from 'path';
5+
import { JSONParserError } from '@apidevtools/json-schema-ref-parser';
56

67
describe('[integration testing] bundler should ', () => {
8+
// as the working directory might get changed, make sure to reset it
9+
let workingDirectory: string = process.cwd();
10+
afterEach(() => {
11+
process.chdir(workingDirectory);
12+
});
13+
714
test('should return bundled doc', async () => {
815
const files = ['./tests/camera.yml', './tests/audio.yml'];
916
const response = await bundle(files, {
@@ -41,6 +48,21 @@ describe('[integration testing] bundler should ', () => {
4148
).resolves;
4249
});
4350

51+
test('should throw if external `$ref` cannot be resolved', async () => {
52+
const files = ['wrong-external-ref.yaml'];
53+
54+
await expect(
55+
async () => {
56+
await bundle(files, {
57+
xOrigin: true,
58+
base: 'base.yml',
59+
baseDir: path.resolve(process.cwd(), './tests'),
60+
noValidation: true,
61+
})
62+
}
63+
).rejects.toThrow(JSONParserError);
64+
});
65+
4466
test('should be able to bundle base file', async () => {
4567
const files = [
4668
'./tests/base-option/lights.yaml',

tests/wrong-external-ref.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
asyncapi: '2.2.0'
2+
info:
3+
title: Account Service
4+
version: 1.0.0
5+
description: This service is in charge of processing user signups
6+
channels:
7+
user/signedup:
8+
subscribe:
9+
message:
10+
$ref: "./audio.yml#/components/messages/WrongReference"

0 commit comments

Comments
 (0)