Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export class UncaughtError extends Error {

constructor (private error: any) {
super('UncaughtError: ' + error.toString());

// Preserve original stack to ease debugging:
this.stack = error.stack;
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/task.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Weird but I have to import "nothing" from "jest" to have the global jest functions (describe, etc.) available
import {} from 'jest';
import { Task, UncaughtError } from '../src/task';
import { assertFork, jestAssertNever, jestAssertUntypedNeverCalled } from './jest-helper';



describe('Task', () => {
describe('fork', () => {
it('should be lazy (dont call if not forked)', cb => {
Expand Down
38 changes: 38 additions & 0 deletions test/uncaught-error.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Weird but I have to import "nothing" from "jest" to have the global jest functions (describe, etc.) available
import {} from 'jest';
import { UncaughtError } from '../src/task';

describe('UncaughtError', () => {
// Maintains wrapped error's stack
describe('.message', () => {
it('should include the wrapped error\'s message', () => {
const originalErrorMsg = 'Buuuu!';
const wrappedError = new Error(originalErrorMsg);
expect(new UncaughtError(wrappedError).message).toMatch(originalErrorMsg);
});

it('should prepend "UncaughtError:"', () => {
const wrappedError = new Error('Buuuu!');
expect(new UncaughtError(wrappedError).message).toMatch(/^UncaughtError\:/);
});
});

describe('.stack', () => {
it('should mantain wrapped error\'s stack', () => {
// Throw an Error with an "interesting" stack
const foo = () => bar();
const bar = () => baz();
const baz = () => {
throw new Error('Buuuu!');
};

try {
foo();
}
catch (wrappedError) {
const uncaughtError = new UncaughtError(wrappedError);
expect(uncaughtError.stack).toBe(wrappedError.stack);
}
});
});
});
2 changes: 2 additions & 0 deletions test/utils/as-uncaught-error.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Weird but I have to import "nothing" from "jest" to have the global jest functions (describe, etc.) available
import {} from 'jest';
import { Task, UncaughtError } from '../../src/task';
import { asUncaughtError } from '../../src/utils/as-uncaught-error';
import { assertFork, jestAssertNever, jestAssertUntypedNeverCalled } from '../jest-helper';
Expand Down