-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ #4 - test: reduce flakyness of tests
- Loading branch information
1 parent
a444195
commit 6b7c5bd
Showing
4 changed files
with
43 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { getStoryContext } = require("@storybook/test-runner"); | ||
const { MINIMAL_VIEWPORTS } = require("@storybook/addon-viewport"); | ||
|
||
const DEFAULT_VP_SIZE = { width: 1280, height: 720 }; | ||
|
||
module.exports = { | ||
/** | ||
* This makes sure the test runner respects the viewport. | ||
* @see {@link https://github.com/storybookjs/test-runner/issues/85#issuecomment-1576465128|[Bug] Tests always run in the default viewport} | ||
* @param page | ||
* @param story | ||
*/ | ||
async preRender(page, story) { | ||
const context = await getStoryContext(page, story); | ||
const vpName = | ||
context.parameters?.viewport?.defaultViewport ?? "responsive"; | ||
const vpParams = MINIMAL_VIEWPORTS[vpName]; | ||
|
||
if (vpParams) { | ||
const width = parseInt(vpParams.styles.width); | ||
const height = parseInt(vpParams.styles.height); | ||
page.setViewportSize({ width, height }); | ||
} else { | ||
page.setViewportSize(DEFAULT_VP_SIZE); | ||
} | ||
}, | ||
}; |
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