Skip to content

Commit

Permalink
Merge pull request #1013 from gemini-testing/sp.storybook-example
Browse files Browse the repository at this point in the history
chore(storybook-example): add example with storybook screenshot tests
  • Loading branch information
sipayRT authored Sep 13, 2024
2 parents 1b26b25 + 8c6f100 commit aafcf23
Show file tree
Hide file tree
Showing 56 changed files with 15,472 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/storybook-autoscreenshots/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# dependencies
/node_modules

# misc
.DS_Store

# reports
/testplane-report
.testplane
*storybook.log
1 change: 1 addition & 0 deletions examples/storybook-autoscreenshots/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
17 changes: 17 additions & 0 deletions examples/storybook-autoscreenshots/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/react-vite",
options: {},
},
};
export default config;
14 changes: 14 additions & 0 deletions examples/storybook-autoscreenshots/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
55 changes: 55 additions & 0 deletions examples/storybook-autoscreenshots/.testplane.conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import path from "path";
import {getStoryFile} from "@testplane/storybook"

export default {
gridUrl: "http://localhost:4444/wd/hub",
baseUrl: "http://localhost",
pageLoadTimeout: 0,
httpTimeout: 60000,
testTimeout: 90000,
resetCursor: false,
// allows you to store references next to your story files
screenshotsDir: (test) => {
const storyFilePath = getStoryFile(test);
const storyFileDirPath = path.dirname(storyFilePath);
const storyFileName = path.basename(storyFilePath);

return path.join(
storyFileDirPath,
`${storyFileName}-screens`,
test.id,
test.browserId
);
},
sets: {
desktop: {
files: [
"testplane-tests/**/*.testplane.(t|j)s"
],
browsers: [
"chrome"
]
}
},
browsers: {
chrome: {
automationProtocol: "devtools",
headless: true,
desiredCapabilities: {
browserName: "chrome"
}
}
},
plugins: {
// https://github.com/gemini-testing/testplane-storybook
"@testplane/storybook": {},

// https://github.com/gemini-testing/html-reporter
"html-reporter/testplane": {
enabled: true,
path: "testplane-report",
defaultView: "all",
diffMode: "3-up-scaled"
}
}
};
42 changes: 42 additions & 0 deletions examples/storybook-autoscreenshots/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Visual testing with Storybook

A project with an example of using automatic screenshot testing of Storybook components.

## How to start

Install dependencies:

```bash
nvm use
npm ci
```

Run storybook-tests with `--update-refs` option to generate reference image at first time:

```
npx testplane --storybook --update-refs
```

You can also use GUI-mode to view results, launch/relaunch tests and accept/update screenshots:

```
npx testplane gui --storybook
```

Storybook examples will be available at `http://localhost:6006/` after the `npm run storybook` command has been run.

## Project structure


```
|____.storybook // storybook config
|____.testplane.conf.ts // file with testplane configuration
|____testplane-tests // directory with testplane test example (without storybook)
|____src
| |____stories // directory with your stories
| | |____Button.stories.ts // file with a single story for the Button component
| | |____Button.stories.ts-screens // directory where your screenshots for the Button tests will be stored
| | |____Page.stories.ts
| | |____Page.stories.ts-screens
```
13 changes: 13 additions & 0 deletions examples/storybook-autoscreenshots/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit aafcf23

Please sign in to comment.