Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story query params in configuration #362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = {
## `configurations`

| Name | Type | Description | Targets |
| ------------------------------------ | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| ------------------------------------ |-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| ------------ |
| **`target`** | _string_ | Target platform, possible values are `chrome.app`, `chrome.docker`, `chrome.aws-lambda`, `ios.simulator`, `android.emulator`. | All |
| **`skipStories`** | _string_ | **DEPRECATED** Same as `loki.skipStories`, but applied to only this configuration. | All |
| **`storiesFilter`** | _string_ | Same as `loki.storiesFilter`, but applied to only this configuration. | All |
Expand All @@ -126,3 +126,4 @@ module.exports = {
| **`deviceScaleFactor`** | _integer_ | Browser pixel density multiple, use `2` for retina, not supported in docker. | `chrome.app` |
| **`mobile`** | _boolean_ | Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more. | `chrome.*` |
| **`media`** | _string_ | Emulates the given media for CSS media queries. | _None_ |
| **`storyQueryParams`** | _object_ | Adds query params to story fetch URL. Example: `{theme: "dark"}` | _None_ |
15 changes: 10 additions & 5 deletions packages/target-chrome-core/src/create-chrome-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,15 @@ function createChromeTarget(
return client;
}

const getStoryUrl = (storyId) =>
`${resolvedBaseUrl}/iframe.html?id=${encodeURIComponent(
storyId
)}&viewMode=story`;
const getStoryUrl = (storyId, storyQueryParams = {}) => {
const params = new URLSearchParams({
id: storyId,
getStoryUrl: 'story',
...storyQueryParams,
});

return `${resolvedBaseUrl}/iframe.html?${params.toString()}`;
};

const launchStoriesTab = withTimeout(LOADING_STORIES_TIMEOUT)(
withRetries(
Expand Down Expand Up @@ -388,7 +393,7 @@ function createChromeTarget(
parameters.chromeSelector ||
configuration.chromeSelector ||
options.chromeSelector;
const url = getStoryUrl(storyId);
const url = getStoryUrl(storyId, configuration.storyQueryParams);

const tab = await launchNewTab(tabOptions);
let screenshot;
Expand Down