Skip to content

Commit

Permalink
Fix E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Oct 25, 2024
1 parent 018cb2f commit 3b870cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions code/e2e-tests/addon-interactions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { expect, test } from '@playwright/test';
import process from 'process';

import { SbPage } from './util';
import { SbPage, hasVitestIntegration } from './util';

const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';

test.describe('addon-interactions', () => {
// TODO: fix the skip statement below when we introduce a sandbox that tests interactions
test.skip(
templateName !== 'todo-sandbox-with-addon-interactions',
hasVitestIntegration,
`Skipping ${templateName}, which does not have addon-interactions set up.`
);

test.beforeEach(async ({ page }) => {
await page.goto(storybookUrl);
await new SbPage(page, expect).waitUntilLoaded();
Expand Down
7 changes: 6 additions & 1 deletion code/e2e-tests/addon-test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { expect, test } from '@playwright/test';
import process from 'process';

import { SbPage } from './util';
import { SbPage, hasVitestIntegration } from './util';

const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';

test.describe('addon-test', () => {
test.skip(
!hasVitestIntegration,
`Skipping ${templateName}, which does not have addon-test set up.`
);

test.beforeEach(async ({ page }) => {
await page.goto(storybookUrl);
await new SbPage(page, expect).waitUntilLoaded();
Expand Down
10 changes: 7 additions & 3 deletions code/e2e-tests/preview-api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from '@playwright/test';
import process from 'process';

import { SbPage } from './util';
import { SbPage, hasVitestIntegration } from './util';

const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME || '';
Expand All @@ -26,8 +26,12 @@ test.describe('preview-api', () => {
await expect(sbPage.page.locator('.sidebar-container')).toBeVisible();

// wait for the play function to complete
await sbPage.viewAddonPanel('Component tests');
const interactionsTab = page.locator('#tabbutton-storybook-test-panel');
await sbPage.viewAddonPanel(hasVitestIntegration ? 'Component tests' : 'Interactions');
const interactionsTab = page.locator(
hasVitestIntegration
? '#tabbutton-storybook-test-panel'
: '#tabbutton-storybook-interactions-panel'
);
await expect(interactionsTab).toBeVisible();
const panel = sbPage.panelContent();
const runStatusBadge = panel.locator('[aria-label="Status of the test run"]');
Expand Down
8 changes: 8 additions & 0 deletions code/e2e-tests/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { toId } from '@storybook/csf';

import type { Expect, Page } from '@playwright/test';

import { allTemplates } from '../lib/cli-storybook/src/sandbox-templates';

export class SbPage {
readonly page: Page;

Expand Down Expand Up @@ -142,3 +144,9 @@ export class SbPage {
return this.previewIframe().locator('body');
}
}

const templateName: keyof typeof allTemplates = process.env.STORYBOOK_TEMPLATE_NAME || ('' as any);

const templates = allTemplates;
export const hasVitestIntegration =
!templates[templateName]?.skipTasks?.includes('vitest-integration');

0 comments on commit 3b870cc

Please sign in to comment.