Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/tidy-stories-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fluentui-react-native/storybook-desktop": patch
---

Separate cold first-render waiting from service startup in the reusable smoke lifecycle, and report story navigation deadlines with their underlying causes.
15 changes: 15 additions & 0 deletions .changeset/warm-carpets-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@fluentui-react-native/avatar": patch
"@fluentui-react-native/badge": patch
"@fluentui-react-native/button": patch
"@fluentui-react-native/checkbox": patch
"@fluentui-react-native/menu": patch
"@fluentui-react-native/radio-group": patch
"@fluentui-react-native/switch": patch
"@fluentui-react-native/tablist": patch
"@fluentui-react-native/text": patch
"@fluentui-react-native/experimental-shimmer": patch
"@fluentui-react-native/spinner": patch
---

Use Win32 styling and token values as the shared default for Windows and Win32.
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,103 @@ describe('DesktopStorybookCli', () => {
}
});

test.each([undefined, 150_000])(
'allows a cold development bundle to take longer than the service startup timeout (initialRenderTimeoutMs: %s)',
async (initialRenderTimeoutMs) => {
jest.useFakeTimers();
try {
const runner = new RecordingRunner();
const readyAt = Date.now() + 130_000;
const output = { write: jest.fn() };
const fetch: typeof globalThis.fetch = async (input) => {
if (String(input).includes('select-story-sync')) {
await new Promise((resolve) => setTimeout(resolve, 1000));
if (Date.now() < readyAt) {
return new Response(JSON.stringify({ error: 'Storybook runtime is not connected yet.' }), { status: 408 });
}
return new Response('{}');
}
return new Response(JSON.stringify({ entries: { first: { id: 'first--story', type: 'story' } } }));
};
const cli = new DesktopStorybookCli(
makeConfig({
macos: { run: { command: 'launch-storybook' }, smoke: { initialRenderTimeoutMs, stop: { command: 'stop-storybook' } } },
}),
{ ...nativeDriverTestOptions, runner, fetch, output, errorOutput: { write: () => true }, isPortAvailable: async () => true },
);

const result = cli.smoke('macos').catch((error: unknown) => error);
await jest.advanceTimersByTimeAsync(131_000);
expect(await result).toBeUndefined();
expect(output.write).toHaveBeenCalledWith('Rendered 1 stories.\n');
expect(runner.stopped).toBe(2);
} finally {
jest.useRealTimers();
}
},
);

test.each([
{ smokeOptions: {}, firstRenders: false, timeoutMs: 300_000 },
{ smokeOptions: { startupTimeoutMs: 2000 }, firstRenders: false, timeoutMs: 2000 },
{ smokeOptions: { startupTimeoutMs: 10_000, initialRenderTimeoutMs: 2000 }, firstRenders: false, timeoutMs: 2000 },
{ smokeOptions: { initialRenderTimeoutMs: 60_000 }, firstRenders: true, timeoutMs: 15_000 },
])('bounds navigation and preserves the cause (%j)', async ({ smokeOptions, firstRenders, timeoutMs }) => {
jest.useFakeTimers();
try {
const runner = new RecordingRunner();
const fetch: typeof globalThis.fetch = async (input, init) => {
const url = String(input);
if (url.includes('select-story-sync')) {
if (firstRenders && url.endsWith('first--story')) {
return new Response('{}');
}
return new Promise((_resolve, reject) => {
init!.signal!.addEventListener('abort', () => reject(init!.signal!.reason), { once: true });
});
}
return new Response(
JSON.stringify({
entries: {
first: { id: 'first--story', type: 'story' },
second: { id: 'second--story', type: 'story' },
},
}),
);
};
const cli = new DesktopStorybookCli(
makeConfig({
macos: { run: { command: 'launch-storybook' }, smoke: { ...smokeOptions, stop: { command: 'stop-storybook' } } },
}),
{
...nativeDriverTestOptions,
runner,
fetch,
output: { write: () => true },
errorOutput: { write: () => true },
isPortAvailable: async () => true,
},
);

const result = cli.smoke('macos').catch((error: unknown) => error);
await jest.advanceTimersByTimeAsync(timeoutMs);
const error = await result;
expect(error).toBeInstanceOf(AggregateError);
if (!(error instanceof AggregateError)) {
throw new Error('Expected smoke to report a navigation failure.');
}
expect(error.errors).toHaveLength(1);
expect(error.errors[0].cause).toMatchObject({
message: `Timed out after ${timeoutMs} ms waiting for Storybook story "${firstRenders ? 'second' : 'first'}--story" to render.`,
cause: { name: 'AbortError' },
});
expect(runner.foreground.at(-1)?.command).toBe('stop-storybook');
expect(runner.stopped).toBe(2);
} finally {
jest.useRealTimers();
}
});

test('runs authored tests after traversing the complete story index', async () => {
const runner = new RecordingRunner();
const resolveNativeDriver = jest.fn(async () => nativeDriverArtifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export class DesktopStorybookCli {
}
await this.writeMacOSApplicationLease(instance.driverManifestPath, smoke.startupTimeoutMs ?? 120_000);
}
await this.renderEveryStory(serverUrl, smoke.settleMs ?? 0, smoke.startupTimeoutMs);
await this.renderEveryStory(serverUrl, smoke.settleMs ?? 0, smoke.initialRenderTimeoutMs ?? smoke.startupTimeoutMs);
if (mode === 'stories-and-tests') {
const result = await this.runSmokeTests({
config: this.config,
Expand Down Expand Up @@ -532,7 +532,7 @@ export class DesktopStorybookCli {
};
}

private async renderEveryStory(serverUrl: string, settleMs: number, startupTimeoutMs = 120_000): Promise<void> {
private async renderEveryStory(serverUrl: string, settleMs: number, initialRenderTimeoutMs = 300_000): Promise<void> {
const storyIndex = await this.getJson(new URL('/index.json', serverUrl));
const entries = Object.values((storyIndex.entries ?? {}) as Record<string, { id?: string; type?: string }>).filter(
(entry) => entry.type === 'story' && entry.id,
Expand All @@ -545,7 +545,7 @@ export class DesktopStorybookCli {
let consecutiveFailures = 0;
for (const [entryIndex, { id }] of entries.entries()) {
try {
await this.selectStory(serverUrl, id!, entryIndex === 0 ? startupTimeoutMs : 15_000);
await this.selectStory(serverUrl, id!, entryIndex === 0 ? initialRenderTimeoutMs : 15_000);
consecutiveFailures = 0;
if (settleMs > 0) {
await delay(settleMs);
Expand Down Expand Up @@ -586,7 +586,7 @@ export class DesktopStorybookCli {
}
}
} while (Date.now() < deadline);
throw lastError;
throw new Error(`Timed out after ${timeoutMs} ms waiting for Storybook story "${storyId}" to render.`, { cause: lastError });
}

private async waitForUrl(url: string, process: RunningDesktopCommand, timeoutMs = 120_000): Promise<void> {
Expand Down
9 changes: 9 additions & 0 deletions packages/agentic/storybook-desktop/src/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ app stop command. For Windows Fabric and the prebuilt REX Win32 host, configure
`createWindowsSmokeOptions`, `createWin32RunCommand`, and
`createWin32SmokeCommand`; do not copy lifecycle scripts into the consumer.

The reusable lifecycle waits up to two minutes for its services, then up to
five minutes for the first story after native launch. Metro's status endpoint
can be ready before a cold development bundle finishes, and a successful
release bundle does not prewarm the Debug app's development bundle. First
render therefore has a separate budget. Set `platformOptions.macos.smoke.initialRenderTimeoutMs`
to override it; an explicitly configured `startupTimeoutMs` remains its
fallback. Later stories retain their 15-second navigation deadline. A timeout
reports the story, elapsed budget, and underlying request failure.

For a broader E2E suite, let the test coordinator own the service processes:

1. Start `storybook server` and Metro with one platform environment.
Expand Down
7 changes: 7 additions & 0 deletions packages/agentic/storybook-desktop/src/config/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ export type DesktopSmokeOptions = {
*/
startupTimeoutMs?: number;

/**
* Maximum time to wait for the first story, including cold development bundling and runtime startup.
* Falls back to an explicitly configured startupTimeoutMs.
* @default 300000
*/
initialRenderTimeoutMs?: number;

/**
* Delay after selecting each story.
* @default 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createColorPinningTheme, resolveV1ColorTokens } from '@fluentui-react-native/test-tools';

import { stylingSettings } from './Avatar.styling';

it('pins Avatar color tokens on Windows', () => {
const theme = createColorPinningTheme();

expect(resolveV1ColorTokens(stylingSettings.tokens, theme)).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getNamedColorSet, type NamedColorSet } from './Avatar.colors';

export const defaultAvatarTokens: TokenSettings<AvatarTokens, Theme> = (t: Theme) =>
({
badgeSize: 'tiny',
badgeSize: 'small',
color: t.colors.neutralForeground3,
backgroundColor: t.colors.neutralBackground6,
avatarOpacity: 1,
Expand Down Expand Up @@ -191,27 +191,25 @@ export const defaultAvatarTokens: TokenSettings<AvatarTokens, Theme> = (t: Theme
* @returns object of props - backgroundColor, color and ringColor
*/
function getColorProps(color: NamedColorSet, theme: Theme) {
const themeAppearance = theme.name;
const colorSet = getNamedColorSet(color);
const themeAppearance = theme.host.appearance;
switch (themeAppearance) {
case 'White':
case 'Colorful':
case 'light':
default:
return {
backgroundColor: colorSet.tint40,
color: colorSet.shade30,
iconColor: colorSet.shade30,
ringColor: colorSet.primary,
};
case 'DarkGray':
case 'Black':
case 'dark':
return {
backgroundColor: colorSet.shade30,
color: colorSet.tint40,
iconColor: colorSet.tint40,
ringColor: colorSet.tint30,
};
case 'HighContrast':
case 'highContrast':
return {
backgroundColor: theme.colors.neutralBackground6,
color: theme.colors.neutralForeground3,
Expand Down
12 changes: 7 additions & 5 deletions packages/components/Avatar/src/AvatarTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getNamedColorSet, type NamedColorSet } from './Avatar.colors';

export const defaultAvatarTokens: TokenSettings<AvatarTokens, Theme> = (t: Theme) =>
({
badgeSize: 'small',
badgeSize: 'tiny',
color: t.colors.neutralForeground3,
backgroundColor: t.colors.neutralBackground6,
avatarOpacity: 1,
Expand Down Expand Up @@ -191,25 +191,27 @@ export const defaultAvatarTokens: TokenSettings<AvatarTokens, Theme> = (t: Theme
* @returns object of props - backgroundColor, color and ringColor
*/
function getColorProps(color: NamedColorSet, theme: Theme) {
const themeAppearance = theme.name;
const colorSet = getNamedColorSet(color);
const themeAppearance = theme.host.appearance;
switch (themeAppearance) {
case 'light':
case 'White':
case 'Colorful':
default:
return {
backgroundColor: colorSet.tint40,
color: colorSet.shade30,
iconColor: colorSet.shade30,
ringColor: colorSet.primary,
};
case 'dark':
case 'DarkGray':
case 'Black':
return {
backgroundColor: colorSet.shade30,
color: colorSet.tint40,
iconColor: colorSet.tint40,
ringColor: colorSet.tint30,
};
case 'highContrast':
case 'HighContrast':
return {
backgroundColor: theme.colors.neutralBackground6,
color: theme.colors.neutralForeground3,
Expand Down
Loading
Loading