From 8d4ae0d616668573ffe9b5e639afc9edbe34ddba Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Feb 2026 03:49:34 +0000 Subject: [PATCH] feat(testing): add unit tests for ExitError and improve class definition - Added `test/errors.test.mjs` with comprehensive tests for the `ExitError` class. - Updated `src/errors.mjs` to set `this.name = 'ExitError'` in the constructor for better error reporting. - Verified that all new tests pass and no regressions were introduced to the existing test suite. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- src/errors.mjs | 1 + test/errors.test.mjs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/errors.test.mjs diff --git a/src/errors.mjs b/src/errors.mjs index c997a9f..667800f 100644 --- a/src/errors.mjs +++ b/src/errors.mjs @@ -2,6 +2,7 @@ export class ExitError extends Error { constructor(code, message) { super(message); + this.name = 'ExitError'; this.code = code; } } diff --git a/test/errors.test.mjs b/test/errors.test.mjs new file mode 100644 index 0000000..66b439b --- /dev/null +++ b/test/errors.test.mjs @@ -0,0 +1,31 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { ExitError } from '../src/errors.mjs'; + +describe('ExitError', () => { + it('should capture the code and message correctly', () => { + const code = 1; + const message = 'Test error message'; + const error = new ExitError(code, message); + + assert.strictEqual(error.code, code); + assert.strictEqual(error.message, message); + }); + + it('should be an instance of Error and ExitError', () => { + const error = new ExitError(1, 'message'); + + assert.ok(error instanceof Error); + assert.ok(error instanceof ExitError); + }); + + it('should have a stack trace', () => { + const error = new ExitError(1, 'message'); + assert.ok(error.stack); + }); + + it('should have the correct name', () => { + const error = new ExitError(1, 'message'); + assert.strictEqual(error.name, 'ExitError'); + }); +});