Skip to content

Commit

Permalink
Merge pull request #139 from storybookjs/fix/support-indexhtml-in-url
Browse files Browse the repository at this point in the history
fix: support index.html URLs
  • Loading branch information
yannbf authored Jul 8, 2022
2 parents 1f82ebd + c0a01a2 commit 78c77c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 7 additions & 2 deletions bin/test-storybook.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ function sanitizeURL(url) {
// remove iframe.html if present
finalURL = finalURL.replace(/iframe.html\s*$/, '');

// remove index.html if present
finalURL = finalURL.replace(/index.html\s*$/, '');

// add forward slash at the end if not there
if (finalURL.slice(-1) !== '/') {
finalURL = finalURL + '/';
Expand Down Expand Up @@ -230,8 +233,10 @@ const main = async () => {
// set this flag to skip reporting coverage in watch mode
isWatchMode = jestOptions.watch;

const targetURL = sanitizeURL(process.env.TARGET_URL || runnerOptions.url);
await checkStorybook(targetURL);
const rawTargetURL = process.env.TARGET_URL || runnerOptions.url || 'http://localhost:6006';
await checkStorybook(rawTargetURL);

const targetURL = sanitizeURL(rawTargetURL)

process.env.TARGET_URL = targetURL;

Expand Down
7 changes: 5 additions & 2 deletions src/setup-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const sanitizeURL = (url) => {
// remove iframe.html if present
finalURL = finalURL.replace(/iframe.html\s*$/, '');

// remove index.html if present
finalURL = finalURL.replace(/index.html\s*$/, '');

// add forward slash at the end if not there
if (finalURL.slice(-1) !== '/') {
finalURL = finalURL + '/';
Expand All @@ -18,7 +21,7 @@ const sanitizeURL = (url) => {
};

export const setupPage = async (page) => {
const targetURL = sanitizeURL(process.env.TARGET_URL || `http://localhost:6006`);
const targetURL = new URL('iframe.html', process.env.TARGET_URL).toString();
const viewMode = process.env.VIEW_MODE || 'story';
const renderedEvent = viewMode === 'docs' ? 'docsRendered' : 'storyRendered';

Expand All @@ -33,7 +36,7 @@ export const setupPage = async (page) => {
);
}

await page.goto(`${targetURL}iframe.html`, { waitUntil: 'load' }).catch((err) => {
await page.goto(targetURL, { waitUntil: 'load' }).catch((err) => {
if (err.message?.includes('ERR_CONNECTION_REFUSED')) {
const errorMessage = `Could not access the Storybook instance at ${targetURL}. Are you sure it's running?\n\n${err.message}`;
throw new Error(errorMessage);
Expand Down

0 comments on commit 78c77c0

Please sign in to comment.