-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply transformers, parsers and source loader to the Error parser
- Loading branch information
1 parent
6eaace2
commit 05d0612
Showing
2 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* youch | ||
* | ||
* (c) Poppinss | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { test } from '@japa/runner' | ||
import { Youch } from '../src/youch.js' | ||
import { stripAnsi } from '../src/helpers.js' | ||
|
||
test.group('Youch', () => { | ||
test('convert error toJSON', async ({ assert }) => { | ||
const parsedError = await new Youch().toJSON(new Error('Something went wrong')) | ||
assert.equal(parsedError.message, 'Something went wrong') | ||
assert.equal(parsedError.frames[0].lineNumber, 16) | ||
}) | ||
|
||
test('apply parser to the error', async ({ assert }) => { | ||
const parsedError = await new Youch() | ||
.useParser((source) => { | ||
return new Error('Wrapped', { cause: source }) | ||
}) | ||
.toJSON(new Error('Something went wrong')) | ||
|
||
assert.equal(parsedError.message, 'Wrapped') | ||
assert.equal((parsedError.cause as any).message, 'Something went wrong') | ||
assert.equal(parsedError.frames[0].lineNumber, 24) | ||
}) | ||
|
||
test('apply transformer to the error', async ({ assert }) => { | ||
const parsedError = await new Youch() | ||
.useTransformer((error) => { | ||
error.frames = error.frames.filter((frame) => { | ||
return frame.type === 'app' | ||
}) | ||
}) | ||
.toJSON(new Error('Something went wrong')) | ||
|
||
assert.lengthOf(parsedError.frames, 1) | ||
}) | ||
|
||
test('convert error to ANSI output', async ({ assert }) => { | ||
const output = await new Youch().toANSI(new Error('Something went wrong')) | ||
assert.include(stripAnsi(output), 'at Object.executor (tests/youch.spec.ts:45:45)') | ||
}) | ||
|
||
test('convert error to HTML output', async ({ assert }) => { | ||
const output = await new Youch().toHTML(new Error('Something went wrong')) | ||
assert.include(output, 'at Object.executor (tests/youch.spec.ts:51:45)') | ||
}) | ||
}) |