Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tmkx/storybook-playwright-ct

Storybook <3 Playwright
https://github.com/tmkx/storybook-playwright-ct

automation e2e playwright storybook test

Last synced: 3 months ago
JSON representation

Storybook <3 Playwright

Awesome Lists containing this project

README

        

## Get Started

> [!IMPORTANT]
> Requirements:
> **`storybook`** v8

```ts
// playwright-ct.config.ts
import { defineConfig } from 'storybook-playwright-ct';

export default defineConfig({
testMatch: '**/*.stories.spec.{ts,tsx}',
webServer: {
command: 'npm run storybook',
url: 'http://localhost:6006/',
reuseExistingServer: true,
},
});
```

```ts
// stories/Button.stories.spec.tsx
import { composeStories } from '@storybook/react';
import { expect, test } from 'storybook-playwright-ct';
import * as stories from './Button.stories';

const { Primary } = composeStories(stories);

test('Screenshot', async ({ mount }) => {
const component = await mount();

await expect(component).toHaveScreenshot();
});

test('Event callback', async ({ mount }) => {
let eventType;
const component = await mount( (eventType = ev.type)} />);

await component.click();
await expect(eventType).toBe('click');
});
```

```json
{
"scripts": {
"test:ct": "playwright test --config playwright-ct.config.ts"
}
}
```

## Credits

- Playwright CT: https://playwright.dev/docs/test-components
- Prior art: https://github.com/storybookjs/playwright-ct