Skip to content

Commit

Permalink
Adjust all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Dec 22, 2023
1 parent 1654326 commit 146cd79
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 62 deletions.
6 changes: 3 additions & 3 deletions code/frameworks/nextjs/template/cli/ts-3-8/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type User = {

interface HeaderProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
Expand Down
6 changes: 3 additions & 3 deletions code/frameworks/nextjs/template/cli/ts-4-9/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type User = {

interface HeaderProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
Expand Down
1 change: 0 additions & 1 deletion code/lib/cli/src/generators/configure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ describe('configurePreview', () => {
"/** @type { import('@storybook/react').Preview } */
const preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
Expand Down
23 changes: 13 additions & 10 deletions code/lib/instrumenter/src/instrumenter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-underscore-dangle */
import { addons, mockChannel } from '@storybook/preview-api';
import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest';
import { logger } from '@storybook/client-logger';
import {
FORCE_REMOUNT,
SET_CURRENT_STORY,
Expand Down Expand Up @@ -418,23 +417,23 @@ describe('Instrumenter', () => {
);
});

it('catches thrown errors and throws an ignoredException instead', () => {
it('rethrows errors', () => {
const { fn } = instrument({
fn: () => {
throw new Error('Boom!');
},
});
expect(fn).toThrow('ignoredException');
expect(fn).toThrow('Boom!');
});

it('catches nested exceptions and throws an ignoredException instead', () => {
it('catches nested exceptions and rethrows', () => {
const { fn1, fn2 } = instrument({
fn1: (_: any) => {},
fn2: () => {
throw new Error('Boom!');
},
});
expect(() => fn1(fn2())).toThrow('ignoredException');
expect(() => fn1(fn2())).toThrow('Boom!');
});

it('bubbles child exceptions up to parent (in callback)', () => {
Expand All @@ -448,15 +447,19 @@ describe('Instrumenter', () => {
vi.spyOn(instrumented, 'fn1');

const { fn1, fn2 } = instrumented;
expect(() =>
let error;
try {
fn1(() => {
fn2();
})
).toThrow('ignoredException');
});
} catch (e) {
error = e;
}

expect(fn1).toHaveBeenCalled();
expect(logger.warn).toHaveBeenCalledWith(new Error('Boom!'));
expect((logger.warn as any).mock.calls[0][0].callId).toBe('kind--story [0] fn1 [0] fn2');
expect(error).toEqual(new Error('Boom!'));
// @ts-expect-error callId is what is tested
expect(error.callId).toBe('kind--story [0] fn1 [0] fn2');
});

it("re-throws anything that isn't an error", () => {
Expand Down
22 changes: 3 additions & 19 deletions code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
FORCE_REMOUNT,
FORCE_RE_RENDER,
GLOBALS_UPDATED,
IGNORED_EXCEPTION,
PREVIEW_KEYDOWN,
RESET_STORY_ARGS,
SET_CURRENT_STORY,
Expand Down Expand Up @@ -130,6 +129,9 @@ beforeEach(() => {
projectAnnotations.decorators[0].mockClear();
docsRenderer.render.mockClear();
vi.mocked(logger.warn).mockClear();
// eslint-disable-next-line no-console
vi.mocked(console.error).mockReset();

mockStoryIndex.mockReset().mockReturnValue(storyIndex);

addons.setChannel(mockChannel as any);
Expand Down Expand Up @@ -629,24 +631,6 @@ describe('PreviewWeb', () => {

expect(mockChannel.emit).toHaveBeenCalledWith(STORY_RENDERED, 'component-one--a');
});

it('does not show error display if the render function throws IGNORED_EXCEPTION', async () => {
document.location.search = '?id=component-one--a';
projectAnnotations.renderToCanvas.mockImplementation(() => {
throw IGNORED_EXCEPTION;
});

const preview = new PreviewWeb();
await preview.initialize({ importFn, getProjectAnnotations });

await waitForRender();

expect(mockChannel.emit).toHaveBeenCalledWith(
STORY_THREW_EXCEPTION,
serializeError(IGNORED_EXCEPTION)
);
expect(preview.view.showErrorDisplay).not.toHaveBeenCalled();
});
});

describe('CSF docs entries', () => {
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-api/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default mergeConfig(
vitestCommonConfig,
defineConfig({
test: {
environment: 'node',
environment: 'jsdom',
name: __dirname.split(sep).slice(-2).join(posix.sep),
},
})
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/html/template/cli/ts-3-8/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { createButton } from './Button';

export interface HeaderProps {
user?: { name: string };
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const createHeader = ({ user, onLogout, onLogin, onCreateAccount }: HeaderProps) => {
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/html/template/cli/ts-4-9/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { createButton } from './Button';

export interface HeaderProps {
user?: { name: string };
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const createHeader = ({ user, onLogout, onLogin, onCreateAccount }: HeaderProps) => {
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/react/template/cli/ts-3-8/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type User = {

interface HeaderProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/react/template/cli/ts-4-9/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type User = {

interface HeaderProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/svelte/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function teardown(canvasElement: SvelteRenderer['canvasElement']) {
function createRoot(target: HTMLElement, props: any) {
if ((svelte as any).createRoot) {
// Svelte v5
return svelte.createRoot(PreviewRender, {
return (svelte as any).createRoot(PreviewRender, {
target,
props,
});
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/web-components/template/cli/ts-3-8/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type User = {

export interface HeaderProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => html`
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/web-components/template/cli/ts-3-8/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type User = {

export interface PageProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Page = ({ user, onLogin, onLogout, onCreateAccount }: PageProps) => html`
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/web-components/template/cli/ts-4-9/Header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ type User = {

export interface HeaderProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => html`
Expand Down
6 changes: 3 additions & 3 deletions code/renderers/web-components/template/cli/ts-4-9/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type User = {

export interface PageProps {
user?: User;
onLogin: () => void;
onLogout: () => void;
onCreateAccount: () => void;
onLogin?: () => void;
onLogout?: () => void;
onCreateAccount?: () => void;
}

export const Page = ({ user, onLogin, onLogout, onCreateAccount }: PageProps) => html`
Expand Down
2 changes: 2 additions & 0 deletions code/ui/manager/src/components/layout/Layout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useState } from 'react';

import { styled } from '@storybook/theming';
import type { Meta, StoryObj } from '@storybook/react';
import { fn } from '@storybook/test';
import { Layout } from './Layout';
import { LayoutProvider } from './LayoutProvider';
import MobileNavigationStoriesMeta from '../mobile/navigation/MobileNavigation.stories';
Expand Down Expand Up @@ -58,6 +59,7 @@ const meta = {
slotSidebar: <MockSidebar />,
slotPanel: <MockPanel />,
slotPages: <MockPage />,
setManagerLayoutState: fn(),
},
parameters: {
theme: 'light',
Expand Down

0 comments on commit 146cd79

Please sign in to comment.