-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
19 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
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,80 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
|
||
import { type Task, modifyErrorMessage } from './setup-file'; | ||
|
||
describe('modifyErrorMessage', () => { | ||
const originalUrl = import.meta.env.__STORYBOOK_URL__; | ||
beforeEach(() => { | ||
import.meta.env.__STORYBOOK_URL__ = 'http://localhost:6006'; | ||
}); | ||
|
||
afterEach(() => { | ||
import.meta.env.__STORYBOOK_URL__ = originalUrl; | ||
}); | ||
|
||
it('should modify the error message if the test is failing and there is a storyId in the task meta', () => { | ||
const task: Task = { | ||
type: 'test', | ||
result: { | ||
state: 'fail', | ||
errors: [{ message: 'Original error message' }], | ||
}, | ||
meta: { storyId: 'my-story' }, | ||
}; | ||
|
||
modifyErrorMessage({ task }); | ||
|
||
expect(task.result?.errors?.[0].message).toMatchInlineSnapshot(` | ||
" | ||
[34mClick to debug the error directly in Storybook: http://localhost:6006/?path=/story/my-story&addonPanel=storybook/interactions/panel[39m | ||
Original error message" | ||
`); | ||
expect(task.result?.errors?.[0].message).toContain('Original error message'); | ||
}); | ||
|
||
it('should not modify the error message if task type is not "test"', () => { | ||
const task: Task = { | ||
type: 'custom', | ||
result: { | ||
state: 'fail', | ||
errors: [{ message: 'Original error message' }], | ||
}, | ||
meta: { storyId: 'my-story' }, | ||
}; | ||
|
||
modifyErrorMessage({ task }); | ||
|
||
expect(task.result?.errors?.[0].message).toBe('Original error message'); | ||
}); | ||
|
||
it('should not modify the error message if task result state is not "fail"', () => { | ||
const task: Task = { | ||
type: 'test', | ||
result: { | ||
state: 'pass', | ||
}, | ||
meta: { storyId: 'my-story' }, | ||
}; | ||
|
||
modifyErrorMessage({ task }); | ||
|
||
expect(task.result?.errors).toBeUndefined(); | ||
}); | ||
|
||
it('should not modify the error message if meta.storyId is not present', () => { | ||
const task: Task = { | ||
type: 'test', | ||
result: { | ||
state: 'fail', | ||
errors: [{ message: 'Non story test failure' }], | ||
}, | ||
meta: {}, | ||
}; | ||
|
||
modifyErrorMessage({ task }); | ||
|
||
expect(task.result?.errors?.[0].message).toBe('Non story test failure'); | ||
}); | ||
}); |
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