Skip to content

Commit

Permalink
Merge pull request #28943 from storybookjs/kasper/viewport
Browse files Browse the repository at this point in the history
Vitest: Fix default viewport
  • Loading branch information
kasperpeulen authored Aug 22, 2024
2 parents accf304 + 88a0059 commit 4bbfb14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions code/addons/vitest/src/plugin/viewports.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-underscore-dangle */
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';

import { page } from '@vitest/browser/context';

import { DEFAULT_VIEWPORT_DIMENSIONS, type ViewportsParam, setViewport } from './viewports';
Expand Down Expand Up @@ -42,6 +44,7 @@ describe('setViewport', () => {

it('should set the dimensions of viewport from INITIAL_VIEWPORTS', async () => {
const viewportsParam: any = {
viewports: INITIAL_VIEWPORTS,
// supported by default in addon viewports
defaultViewport: 'ipad',
};
Expand Down
6 changes: 3 additions & 3 deletions code/addons/vitest/src/plugin/viewports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UnsupportedViewportDimensionError } from 'storybook/internal/preview-er

import { page } from '@vitest/browser/context';

import { INITIAL_VIEWPORTS } from '../../../viewport/src/defaults';
import { MINIMAL_VIEWPORTS } from '../../../viewport/src/defaults';
import type { ViewportMap, ViewportStyles } from '../../../viewport/src/types';

declare global {
Expand Down Expand Up @@ -50,12 +50,12 @@ const parseDimension = (value: string, dimension: 'width' | 'height') => {
export const setViewport = async (viewportsParam: ViewportsParam = {} as ViewportsParam) => {
const defaultViewport = viewportsParam.defaultViewport;

if (!page || !globalThis.__vitest_browser__ || !defaultViewport) {
if (!page || !globalThis.__vitest_browser__) {
return;
}

const viewports = {
...INITIAL_VIEWPORTS,
...MINIMAL_VIEWPORTS,
...viewportsParam.viewports,
};

Expand Down

0 comments on commit 4bbfb14

Please sign in to comment.