Skip to content

Commit

Permalink
Do not swallow error
Browse files Browse the repository at this point in the history
  • Loading branch information
tsauerwein committed Jun 27, 2024
1 parent 4b54aa5 commit a2ac491
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ export const resolve = async (
) => {
const docs = [];

try {
for (const asyncapiDocument of asyncapiDocuments) {
await parse(asyncapiDocument, specVersion, options);
docs.push(asyncapiDocument);
}
} catch (e) {} // eslint-disable-line
for (const asyncapiDocument of asyncapiDocuments) {
await parse(asyncapiDocument, specVersion, options);
docs.push(asyncapiDocument);
}

return docs;
};
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import { describe, expect, test } from '@jest/globals';
import bundle from '../../src';
import { isExternalReference } from '../../src/util';
import path from 'path';
import { JSONParserError } from '@apidevtools/json-schema-ref-parser';

describe('[integration testing] bundler should ', () => {
// as the working directory might get changed, make sure to reset it
let workingDirectory: string = process.cwd();
afterEach(() => {
process.chdir(workingDirectory);
});

test('should return bundled doc', async () => {
const files = ['./tests/camera.yml', './tests/audio.yml'];
const response = await bundle(files, {
Expand Down Expand Up @@ -41,6 +48,21 @@ describe('[integration testing] bundler should ', () => {
).resolves;
});

test('should throw if external `$ref` cannot be resolved', async () => {
const files = ['wrong-external-ref.yaml'];

await expect(
async () => {
await bundle(files, {
xOrigin: true,
base: 'base.yml',
baseDir: path.resolve(process.cwd(), './tests'),
noValidation: true,
})
}
).rejects.toThrow(JSONParserError);
});

test('should be able to bundle base file', async () => {
const files = [
'./tests/base-option/lights.yaml',
Expand Down
10 changes: 10 additions & 0 deletions tests/wrong-external-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
asyncapi: '2.2.0'
info:
title: Account Service
version: 1.0.0
description: This service is in charge of processing user signups
channels:
user/signedup:
subscribe:
message:
$ref: "./audio.yml#/components/messages/WrongReference"

0 comments on commit a2ac491

Please sign in to comment.