-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This required several changes to jest and storybook config to have the storyshots tests execute without errors. It also includes some cleanup in some of the storybooks and components that were generating errors or warnings in tests.
- Loading branch information
1 parent
2367adf
commit bb27390
Showing
17 changed files
with
979 additions
and
804 deletions.
There are no files selected for viewing
18 changes: 11 additions & 7 deletions
18
server/zanata-frontend/src/frontend/.storybook-editor/config.js
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
27 changes: 27 additions & 0 deletions
27
server/zanata-frontend/src/frontend/.storybook-editor/storyshots-editor.test.js
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,27 @@ | ||
import initStoryshots from '@storybook/addon-storyshots' | ||
import { | ||
mockAddons, | ||
notNoTestRegex, | ||
snapshotWithoutDecorators | ||
} from './storyshots-util' | ||
|
||
initStoryshots({ | ||
suite: 'Editor Storyshots', | ||
configPath: '.storybook-editor', | ||
framework: 'react', | ||
|
||
/* add components here that should not have their stories tested | ||
* (e.g. when they are under development and not used in the app yet) | ||
* | ||
* Regex structure: | ||
* ^ start of component name | ||
* (?! negative lookahead, don't match anything in this group | ||
* (EditorSearchInput|SettingOption|SettingsOptions)$ | ||
* component names to not match, add yours in here to not test it | ||
* the $ ensures that excluding Foo does not block testing FooBar. | ||
* ).*$ match any other characters to the end of the string | ||
*/ | ||
storyKindRegex: /^(?!(EditorSearchInput|SettingOption|SettingsOptions)$).*$/, | ||
storyNameRegex: notNoTestRegex, | ||
test: snapshotWithoutDecorators | ||
}) |
37 changes: 37 additions & 0 deletions
37
server/zanata-frontend/src/frontend/.storybook-editor/storyshots-util.js
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,37 @@ | ||
/* global jest expect */ | ||
import renderer from 'react-test-renderer' | ||
|
||
/* | ||
* Test function that renders stories into snapshots. | ||
* | ||
* This custom test function strips the decorating icon and other components | ||
* so that the tests are cleaner and not dependent on the wrapping decorators. | ||
*/ | ||
export function snapshotWithoutDecorators ({ story, context }) { | ||
const storyElement = story.render(context) | ||
const tree = renderer.create(storyElement, {}).toJSON() | ||
|
||
// strip off the padding div and the <Icons /> | ||
// tree structure is: <div><Icons />{story()}</div> | ||
const storyJSON = tree.children[1] | ||
|
||
expect(storyJSON).toMatchSnapshot() | ||
} | ||
|
||
/* | ||
* Mock any addons that would add cruft to the snapshots. This keeps the | ||
* snapshots cleaner. | ||
*/ | ||
export function mockAddons () { | ||
jest.mock('storybook-host', () => ({ | ||
// ignore host options, just render the inner story | ||
host: (options) => (story) => story() | ||
})) | ||
jest.mock('@storybook/addon-info', () => ({ | ||
// without info, muahahahaha! 😈 | ||
withInfo: (info) => (story) => story | ||
})) | ||
} | ||
|
||
/* Matches any story name that does not include "(no test)" */ | ||
export const notNoTestRegex = /^((?!.*?\(no test\)).)*$/ |
30 changes: 17 additions & 13 deletions
30
server/zanata-frontend/src/frontend/.storybook-frontend/config.js
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
27 changes: 27 additions & 0 deletions
27
server/zanata-frontend/src/frontend/.storybook-frontend/storyshots-frontend.test.js
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,27 @@ | ||
import initStoryshots from '@storybook/addon-storyshots' | ||
import { | ||
mockAddons, | ||
notNoTestRegex, | ||
snapshotWithoutDecorators | ||
} from '../.storybook-editor/storyshots-util' | ||
|
||
initStoryshots({ | ||
suite: 'Frontend Storyshots', | ||
configPath: '.storybook-frontend', | ||
framework: 'react', | ||
|
||
/* add components here that should not have their stories tested | ||
* (e.g. when they are under development and not used in the app yet) | ||
* | ||
* Regex structure: | ||
* ^ start of component name | ||
* (?! negative lookahead, don't match anything in this group | ||
* (EditorSearchInput|SettingOption|SettingsOptions)$ | ||
* component names to not match, add yours in here to not test it | ||
* the $ ensures that excluding Foo does not block testing FooBar. | ||
* ).*$ match any other characters to the end of the string | ||
*/ | ||
storyKindRegex: /^(?!(NOTHING|NOTHINGELSE)$).*$/, | ||
storyNameRegex: notNoTestRegex, | ||
test: snapshotWithoutDecorators | ||
}) |
File renamed without changes.
8 changes: 5 additions & 3 deletions
8
server/zanata-frontend/src/frontend/app/components/Icon/Icon.story.js
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
Oops, something went wrong.