Skip to content

Commit 9ca7e59

Browse files
committed
apply prettier on all files
1 parent f5728e0 commit 9ca7e59

18 files changed

+73
-75
lines changed

.github/workflows/nightly.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,21 @@ jobs:
123123
- name: Fix local @storybook/csf version
124124
run: |
125125
yarn add @storybook/[email protected]
126-
126+
127127
- name: Run test runner and expect failure
128128
uses: mathiasvr/command-output@v1
129129
with:
130130
run: |
131131
yarn build
132132
yarn test-storybook:ci-failures
133-
133+
134134
- name: Process test results
135135
if: ${{ always() }}
136136
id: tests
137137
uses: sergeysova/jq-action@v2
138138
with:
139139
cmd: 'jq .numPassedTests test-results.json -r'
140-
140+
141141
- name: Set failure check to env
142142
if: ${{ always() }}
143143
run: |

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2626
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2727
run: |
28-
yarn release
28+
yarn release

.github/workflows/stress-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Stress Tests
22

33
on:
44
pull_request:
5-
types: [ labeled ]
5+
types: [labeled]
66

77
jobs:
88
test:

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: |
2525
yarn build
2626
yarn test-storybook:ci-coverage
27-
27+
2828
- name: Generate code coverage
2929
uses: codecov/codecov-action@v2
3030
with:

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
npm test
4+
npx lint-staged

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
dist
2+
node_modules
3+
storybook-static
4+
.cache
5+
.env
6+
*.snap
7+
__snapshots__
8+
CHANGELOG.md

.storybook/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ if (process.env.STRESS_TEST) {
1818
stories.push('../stories/stress-test/*.stories.@(js|jsx|ts|tsx)');
1919
}
2020

21-
if(process.env.TEST_FAILURES) {
21+
if (process.env.TEST_FAILURES) {
2222
stories = ['../stories/expected-failures/*.stories.@(js|jsx|ts|tsx)'];
2323
}
2424

2525
const addons = [
2626
process.env.WITHOUT_DOCS
2727
? {
28-
name: '@storybook/addon-essentials',
29-
options: {
30-
docs: false,
31-
},
32-
}
28+
name: '@storybook/addon-essentials',
29+
options: {
30+
docs: false,
31+
},
32+
}
3333
: '@storybook/addon-essentials',
3434
'@storybook/addon-interactions',
3535
'@storybook/addon-coverage',
@@ -43,6 +43,6 @@ module.exports = {
4343
buildStoriesJson: true,
4444
},
4545
core: {
46-
disableTelemetry: true
47-
}
46+
disableTelemetry: true,
47+
},
4848
};

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"titleBar.activeBackground": "#004752",
66
"titleBar.activeForeground": "#ECFCFF"
77
}
8-
}
8+
}

README.md

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ See the announcement of Interaction Testing with Storybook in detail in [this bl
5050
The Storybook test runner uses Jest as a runner, and Playwright as a testing framework. Each one of your `.stories` files is transformed into a spec file, and each story becomes a test, which is run in a headless browser.
5151

5252
The test runner is simple in design – it just visits each story from a running Storybook instance and makes sure the component is not failing:
53+
5354
- For stories without a `play` function, it verifies whether the story rendered without any errors. This is essentially a smoke test.
5455
- For those with a `play` function, it also checks for errors in the `play` function and that all assertions passed. This is essentially an [interaction test](https://storybook.js.org/docs/react/writing-tests/interaction-testing#write-an-interaction-test).
5556

@@ -299,7 +300,7 @@ The test runner supports code coverage with the `--coverage` flag or `STORYBOOK_
299300

300301
### 1 - Instrument the code
301302

302-
Given that your components' code runs in the context of a real browser, they have to be instrumented so that the test runner is able to collect coverage. This is done by configuring [istanbul](https://istanbul.js.org/) in your Storybook. You can achieve that in two different ways:
303+
Given that your components' code runs in the context of a real browser, they have to be instrumented so that the test runner is able to collect coverage. This is done by configuring [istanbul](https://istanbul.js.org/) in your Storybook. You can achieve that in two different ways:
303304

304305
#### Using @storybook/addon-coverage
305306

@@ -317,9 +318,7 @@ And register it in your `.storybook/main.js` file:
317318
// .storybook/main.js
318319
module.exports = {
319320
// ...rest of your code here
320-
addons: [
321-
"@storybook/addon-coverage",
322-
]
321+
addons: ['@storybook/addon-coverage'],
323322
};
324323
```
325324

@@ -359,7 +358,7 @@ If you want certain parts of your code to be deliberately ignored, you can use i
359358

360359
### 3 - Merging code coverage with coverage from other tools
361360

362-
The test runner reports coverage related to the `coverage/storybook/coverage-storybook.json` file. This is by design, showing you the coverage which is tested while running Storybook.
361+
The test runner reports coverage related to the `coverage/storybook/coverage-storybook.json` file. This is by design, showing you the coverage which is tested while running Storybook.
363362

364363
Now, you might have other tests (e.g. unit tests) which are _not_ covered in Storybook but are covered when running tests with Jest, which you might also generate coverage files from, for instance. In such cases, if you are using tools like [Codecov](https://codecov.io/) to automate reporting, the coverage files will be detected automatically and if there are multiple files in the coverage folder, they will be merged automatically.
365364

@@ -487,40 +486,43 @@ You can use it for multiple use cases, and here's an example that combines the s
487486
// .storybook/test-runner.js
488487
const { getStoryContext } = require('@storybook/test-runner');
489488
const { injectAxe, checkA11y } = require('axe-playwright');
490-
489+
491490
module.exports = {
492-
async preRender(page, context) {
493-
await injectAxe(page);
494-
},
495-
async postRender(page, context) {
496-
// Get entire context of a story, including parameters, args, argTypes, etc.
497-
const storyContext = await getStoryContext(page, context);
498-
499-
// Do not test a11y for stories that disable a11y
500-
if (storyContext.parameters?.a11y?.disable) {
501-
return;
502-
}
503-
504-
await checkA11y(page, '#root', {
505-
detailedReport: true,
506-
detailedReportOptions: {
507-
html: true,
508-
},
509-
// pass axe options defined in @storybook/addon-a11y
510-
axeOptions: storyContext.parameters?.a11y?.options
511-
})
512-
},
491+
async preRender(page, context) {
492+
await injectAxe(page);
493+
},
494+
async postRender(page, context) {
495+
// Get entire context of a story, including parameters, args, argTypes, etc.
496+
const storyContext = await getStoryContext(page, context);
497+
498+
// Do not test a11y for stories that disable a11y
499+
if (storyContext.parameters?.a11y?.disable) {
500+
return;
501+
}
502+
503+
await checkA11y(page, '#root', {
504+
detailedReport: true,
505+
detailedReportOptions: {
506+
html: true,
507+
},
508+
// pass axe options defined in @storybook/addon-a11y
509+
axeOptions: storyContext.parameters?.a11y?.options,
510+
});
511+
},
513512
};
514513
```
515514
516515
## Troubleshooting
517516
518517
#### Errors with Jest 28
518+
519519
Jest 28 has been released, but unfortunately `jest-playwright` is not yet compatible with it, therefore the test-runner is also not compatible. You likely are having an issue that looks like this:
520+
520521
```sh
521522
TypeError: Jest: Got error running globalSetup
522523
reason: Class extends value #<Object> is not a constructor or null
523524
```
525+
524526
As soon as `jest-playwright` is compatible, so the test-runner will be too. Please follow [this issue](https://github.com/storybookjs/test-runner/issues/99) for updates.
525527

526528
#### The error output in the CLI is too short

playwright/custom-environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const PlaywrightEnvironment = require('jest-playwright-preset/lib/PlaywrightEnvi
66
class CustomEnvironment extends PlaywrightEnvironment {
77
async setup() {
88
await super.setup();
9-
await setupPage(this.global.page)
9+
await setupPage(this.global.page);
1010
}
1111

1212
async teardown() {

playwright/jest-setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ if (testRunnerConfig) {
1313
}
1414
}
1515

16-
global.__sbCollectCoverage = process.env.STORYBOOK_COLLECT_COVERAGE === 'true'
16+
global.__sbCollectCoverage = process.env.STORYBOOK_COLLECT_COVERAGE === 'true';

playwright/test-runner-jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ module.exports = {
66
/** Add your own overrides below
77
* @see https://jestjs.io/docs/configuration
88
*/
9-
}
9+
};

playwright/transform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
'@babel/preset-react',
1616
],
1717
});
18-
18+
1919
return result ? result.code : src;
2020
},
2121
};

stories/atoms/Button.jsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import React from "react";
2-
import PropTypes from "prop-types";
3-
import "./button.css";
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import './button.css';
44

55
/**
66
* Primary UI component for user interaction
77
*/
88
export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
9-
const mode = primary
10-
? "storybook-button--primary"
11-
: "storybook-button--secondary";
9+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
1210
return (
1311
<button
1412
type="button"
15-
className={["storybook-button", `storybook-button--${size}`, mode].join(
16-
" "
17-
)}
13+
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
1814
style={backgroundColor && { backgroundColor }}
1915
{...props}
2016
>
@@ -35,7 +31,7 @@ Button.propTypes = {
3531
/**
3632
* How large should the button be?
3733
*/
38-
size: PropTypes.oneOf(["small", "medium", "large"]),
34+
size: PropTypes.oneOf(['small', 'medium', 'large']),
3935
/**
4036
* Button contents
4137
*/
@@ -49,6 +45,6 @@ Button.propTypes = {
4945
Button.defaultProps = {
5046
backgroundColor: null,
5147
primary: false,
52-
size: "medium",
48+
size: 'medium',
5349
onClick: undefined,
5450
};

stories/atoms/Button.stories.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import React from 'react';
22
import { expect } from '@storybook/jest';
3-
import {
4-
within,
5-
waitFor,
6-
userEvent,
7-
waitForElementToBeRemoved,
8-
} from '@storybook/testing-library';
3+
import { within, waitFor, userEvent, waitForElementToBeRemoved } from '@storybook/testing-library';
94

105
import { Button } from './Button';
116

@@ -31,9 +26,9 @@ Secondary.args = {
3126
};
3227
Secondary.parameters = {
3328
tests: {
34-
disableSnapshots: true
35-
}
36-
}
29+
disableSnapshots: true,
30+
},
31+
};
3732

3833
export const Demo = (args) => (
3934
<button type="button" onClick={() => args.onSubmit('clicked')}>
@@ -113,4 +108,4 @@ WithLoaders.play = async ({ args, canvasElement }) => {
113108
const todoItem = await canvas.findByText('Todo: delectus aut autem');
114109
await userEvent.click(todoItem);
115110
await expect(args.onSubmit).toHaveBeenCalledWith('delectus aut autem');
116-
};
111+
};

stories/expected-failures/Failure.stories.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Template = (args) => <Page {...args} />;
1212

1313
export const ComponentThrowsErrors = () => {
1414
throw new Error('Component has a failure');
15-
}
15+
};
1616

1717
export const PlayFnThrowsErrors = Template.bind({});
1818
PlayFnThrowsErrors.play = () => {
@@ -24,4 +24,4 @@ PlayFnAssertionFails.play = async ({ canvasElement }) => {
2424
const canvas = within(canvasElement);
2525
const unexistentButton = await canvas.getByRole('button', { name: /I do not exist/i });
2626
await userEvent.click(unexistentButton);
27-
};
27+
};

test-runner-jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ module.exports = {
1616
setupFilesAfterEnv: ['./playwright/jest-setup.js'],
1717
// use local build when the package is referred
1818
moduleNameMapper: {
19-
'@storybook/test-runner': '<rootDir>/dist/cjs/index.js'
19+
'@storybook/test-runner': '<rootDir>/dist/cjs/index.js',
2020
},
2121
};

tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
"types": ["jest", "node"],
1818
"moduleResolution": "node"
1919
},
20-
"include": [
21-
"src/**/*.ts"
22-
],
20+
"include": ["src/**/*.ts"],
2321
"exclude": ["src/**/*.test.ts"]
24-
}
22+
}

0 commit comments

Comments
 (0)