Skip to content

Commit

Permalink
refactor: assert error message when file cannot be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
anshchaturvedi committed May 17, 2024
1 parent 1df69dc commit 87fc87e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/openapi-generator/src/sourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function parseSource(
span: module.span,
};
} catch (e: unknown) {
console.error('Error parsing source file: ', path, e);
console.error(`Error parsing source file: ${path}`, e);
return undefined;
}
}
6 changes: 3 additions & 3 deletions packages/openapi-generator/test/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ test('non-strict files are ignored and logged to stderr', async () => {

console.error = (...args) => {
errorCalled = true;
originalConsoleError(...args);
console.error = originalConsoleError;
const errorRegex = /Error parsing source file: \/index.ts/;
assert(errorRegex.test(args[0]));
};

const project = new TestProject({ '/index.ts': NON_STRICT_MODE_SRC }, {});
Expand All @@ -116,6 +118,4 @@ test('non-strict files are ignored and logged to stderr', async () => {

assert.strictEqual(sourceFile, undefined);
assert.strictEqual(errorCalled, true, new Error('console.error was not called'));

console.error = originalConsoleError;
});

0 comments on commit 87fc87e

Please sign in to comment.