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

fix: support index.html URLs #139

Merged
merged 1 commit into from
Jul 8, 2022
Merged
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
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