-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into shilman/add-tag-exclusion
- Loading branch information
Showing
24 changed files
with
550 additions
and
1,306 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
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,49 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import process from 'process'; | ||
import { SbPage } from './util'; | ||
|
||
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; | ||
|
||
test.describe('module-mocking', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto(storybookUrl); | ||
|
||
await new SbPage(page).waitUntilLoaded(); | ||
}); | ||
|
||
test('should assert story lifecycle order', async ({ page }) => { | ||
const sbPage = new SbPage(page); | ||
|
||
await sbPage.navigateToStory('lib/test/before-each', 'before-each-order'); | ||
|
||
await sbPage.viewAddonPanel('Actions'); | ||
const logItem = await page.locator('#storybook-panel-root #panel-tab-content'); | ||
await expect(logItem).toBeVisible(); | ||
|
||
const expectedTexts = [ | ||
'1 - [from loaders]', | ||
'2 - [from meta beforeEach]', | ||
'3 - [from story beforeEach]', | ||
'4 - [from decorator]', | ||
'5 - [from onClick]', | ||
]; | ||
|
||
// Assert that each LI text content contains the expected text in order | ||
for (let i = 0; i < expectedTexts.length; i++) { | ||
const nthText = await logItem.locator(`li >> nth=${i}`).innerText(); | ||
expect(nthText).toMatch(expectedTexts[i]); | ||
} | ||
}); | ||
|
||
test('should assert that utils import is mocked', async ({ page }) => { | ||
const sbPage = new SbPage(page); | ||
|
||
await sbPage.navigateToStory('lib/test/module-mocking', 'basic'); | ||
|
||
await sbPage.viewAddonPanel('Actions'); | ||
const logItem = await page.locator('#storybook-panel-root #panel-tab-content', { | ||
hasText: 'foo: []', | ||
}); | ||
await expect(logItem).toBeVisible(); | ||
}); | ||
}); |
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
32 changes: 32 additions & 0 deletions
32
code/frameworks/nextjs/src/compatibility/compatibility-map.ts
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,32 @@ | ||
import type { Configuration as WebpackConfig } from 'webpack'; | ||
import semver from 'semver'; | ||
import { getNextjsVersion, addScopedAlias } from '../utils'; | ||
|
||
const mapping: Record<string, Record<string, string>> = { | ||
'<14.0.0': { | ||
'next/dist/shared/lib/segment': '@storybook/nextjs/dist/compatibility/segment.compat', | ||
'next/dist/client/components/redirect-status-code': | ||
'@storybook/nextjs/dist/compatibility/redirect-status-code.compat', | ||
}, | ||
}; | ||
|
||
export const getCompatibilityAliases = () => { | ||
const version = getNextjsVersion(); | ||
const result: Record<string, string> = {}; | ||
|
||
Object.keys(mapping).filter((key) => { | ||
if (semver.intersects(version, key)) { | ||
Object.assign(result, mapping[key]); | ||
} | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export const configureCompatibilityAliases = (baseConfig: WebpackConfig): void => { | ||
const aliases = getCompatibilityAliases(); | ||
|
||
Object.entries(aliases).forEach(([name, alias]) => { | ||
addScopedAlias(baseConfig, name, alias); | ||
}); | ||
}; |
6 changes: 6 additions & 0 deletions
6
code/frameworks/nextjs/src/compatibility/redirect-status-code.compat.ts
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,6 @@ | ||
// Compatibility for Next 13 | ||
export enum RedirectStatusCode { | ||
SeeOther = 303, | ||
TemporaryRedirect = 307, | ||
PermanentRedirect = 308, | ||
} |
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,8 @@ | ||
// Compatibility for Next 13 | ||
// from https://github.com/vercel/next.js/blob/606f9ff7903b58da51aa043bfe71cd7b6ea306fd/packages/next/src/shared/lib/segment.ts#L4 | ||
export function isGroupSegment(segment: string) { | ||
return segment[0] === '(' && segment.endsWith(')'); | ||
} | ||
|
||
export const PAGE_SEGMENT_KEY = '__PAGE__'; | ||
export const DEFAULT_SEGMENT_KEY = '__DEFAULT__'; |
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
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
Oops, something went wrong.