Skip to content

Commit 2b5d377

Browse files
committed
feat: add coverage panel
1 parent 703a8f4 commit 2b5d377

31 files changed

+2206
-1811
lines changed

.babelrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = {
44
"@babel/preset-typescript",
55
"@babel/preset-react",
66
],
7+
ignore: ["./src/typings.d.ts"],
78
env: {
89
esm: {
910
presets: [

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules/
33
storybook-static/
44
build-storybook.log
55
.DS_Store
6-
.env
6+
.env
7+
yarn-*.log

.storybook/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@ module.exports = {
33
"../stories/**/*.stories.mdx",
44
"../stories/**/*.stories.@(js|jsx|ts|tsx)",
55
],
6-
addons: ["../preset.js", "@storybook/addon-essentials"],
6+
addons: [
7+
{
8+
name: "../preset.js",
9+
options: { useExternalInstrumentation: false }
10+
},
11+
"@storybook/addon-essentials",
12+
"@storybook/addon-interactions",
13+
],
14+
features: {
15+
interactionsDebugger: true
16+
}
717
};

README.md

Lines changed: 3 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,8 @@
1-
# Storybook Addon Addon coverage
2-
Tools to support code coverage in Storybook
1+
# Storybook Addon Coverage
32

3+
Tools to support code coverage in Storybook and the [test runner](https://github.com/storybookjs/test-runner)
4+
45
### Development scripts
56

67
- `yarn start` runs babel in watch mode and starts Storybook
78
- `yarn build` build and package your addon code
8-
9-
### Switch from TypeScript to JavaScript
10-
11-
Don't want to use TypeScript? We offer a handy eject command: `yarn eject-ts`
12-
13-
This will convert all code to JS. It is a destructive process, so we recommended running this before you start writing any code.
14-
15-
## What's included?
16-
17-
![Demo](https://user-images.githubusercontent.com/42671/107857205-e7044380-6dfa-11eb-8718-ad02e3ba1a3f.gif)
18-
19-
The addon code lives in `src`. It demonstrates all core addon related concepts. The three [UI paradigms](https://storybook.js.org/docs/react/addons/addon-types#ui-based-addons)
20-
21-
- `src/Tool.js`
22-
- `src/Panel.js`
23-
- `src/Tab.js`
24-
25-
Which, along with the addon itself, are registered in `src/preset/manager.js`.
26-
27-
Managing State and interacting with a story:
28-
29-
- `src/withGlobals.js` & `src/Tool.js` demonstrates how to use `useGlobals` to manage global state and modify the contents of a Story.
30-
- `src/withRoundTrip.js` & `src/Panel.js` demonstrates two-way communication using channels.
31-
- `src/Tab.js` demonstrates how to use `useParameter` to access the current story's parameters.
32-
33-
Your addon might use one or more of these patterns. Feel free to delete unused code. Update `src/preset/manager.js` and `src/preset/preview.js` accordingly.
34-
35-
Lastly, configure you addon name in `src/constants.js`.
36-
37-
### Metadata
38-
39-
Storybook addons are listed in the [catalog](https://storybook.js.org/addons) and distributed via npm. The catalog is populated by querying npm's registry for Storybook-specific metadata in `package.json`. This project has been configured with sample data. Learn more about available options in the [Addon metadata docs](https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata).
40-
41-
## Release Management
42-
43-
### Setup
44-
45-
This project is configured to use [auto](https://github.com/intuit/auto) for release management. It generates a changelog and pushes it to both GitHub and npm. Therefore, you need to configure access to both:
46-
47-
- [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens) Create a token with both _Read and Publish_ permissions.
48-
- [`GH_TOKEN`](https://github.com/settings/tokens) Create a token with the `repo` scope.
49-
50-
Then open your `package.json` and edit the following fields:
51-
52-
- `name`
53-
- `author`
54-
- `repository`
55-
56-
#### Local
57-
58-
To use `auto` locally create a `.env` file at the root of your project and add your tokens to it:
59-
60-
```bash
61-
GH_TOKEN=<value you just got from GitHub>
62-
NPM_TOKEN=<value you just got from npm>
63-
```
64-
65-
Lastly, **create labels on GitHub**. You’ll use these labels in the future when making changes to the package.
66-
67-
```bash
68-
npx auto create-labels
69-
```
70-
71-
If you check on GitHub, you’ll now see a set of labels that `auto` would like you to use. Use these to tag future pull requests.
72-
73-
#### GitHub Actions
74-
75-
This template comes with GitHub actions already set up to publish your addon anytime someone pushes to your repository.
76-
77-
Go to `Settings > Secrets`, click `New repository secret`, and add your `NPM_TOKEN`.
78-
79-
### Creating a release
80-
81-
To create a release locally you can run the following command, otherwise the GitHub action will make the release for you.
82-
83-
```sh
84-
yarn release
85-
```
86-
87-
That will:
88-
89-
- Build and package the addon code
90-
- Bump the version
91-
- Push a release to GitHub and npm
92-
- Push a changelog to GitHub

babel-plugin-source.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = function ({ types: t }) {
2+
return {
3+
visitor: {
4+
ExportDefaultDeclaration: {
5+
enter({ node }) {
6+
// set default.parameters.coverage
7+
/**
8+
* {
9+
* coverage: {
10+
* fileName: '',
11+
* filePath: '',
12+
* source: '' <- raw source
13+
* }
14+
* }
15+
*/
16+
},
17+
},
18+
},
19+
};
20+
};

package.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
"version": "0.0.0",
44
"description": "Tools to support code coverage in Storybook",
55
"keywords": [
6-
"storybook-addons", "coverage", "test", "testing", "test-runner", "storybook-addons"
6+
"storybook-addons",
7+
"coverage",
8+
"test",
9+
"testing",
10+
"test-runner",
11+
"storybook-addons"
712
],
813
"repository": {
914
"type": "git",
@@ -43,27 +48,29 @@
4348
"@babel/preset-env": "^7.12.1",
4449
"@babel/preset-react": "^7.12.5",
4550
"@babel/preset-typescript": "^7.13.0",
46-
"@storybook/addon-essentials": "^6.4.0",
47-
"@storybook/react": "^6.4.0",
51+
"@storybook/addon-essentials": "^6.5.9",
52+
"@storybook/addon-interactions": "^6.5.9",
53+
"@storybook/react": "^6.5.9",
54+
"@storybook/testing-library": "^0.0.12",
4855
"auto": "^10.3.0",
4956
"babel-loader": "^8.1.0",
5057
"boxen": "^5.0.1",
5158
"concurrently": "^6.2.0",
5259
"dedent": "^0.7.0",
5360
"prettier": "^2.3.1",
5461
"prop-types": "^15.7.2",
62+
"raw-loader": "^4.0.2",
5563
"react": "^17.0.1",
5664
"react-dom": "^17.0.1",
5765
"rimraf": "^3.0.2",
5866
"typescript": "^4.2.4",
5967
"zx": "^1.14.1"
6068
},
6169
"peerDependencies": {
62-
"@storybook/addons": "^6.4.0",
63-
"@storybook/api": "^6.4.0",
64-
"@storybook/components": "^6.4.0",
65-
"@storybook/core-events": "^6.4.0",
66-
"@storybook/theming": "^6.4.0",
70+
"@storybook/addons": "^6",
71+
"@storybook/api": "^6",
72+
"@storybook/components": "^6",
73+
"@storybook/core-events": "^6",
6774
"react": "^16.8.0 || ^17.0.0",
6875
"react-dom": "^16.8.0 || ^17.0.0"
6976
},
@@ -81,7 +88,7 @@
8188
"storybook": {
8289
"displayName": "Addon coverage",
8390
"supportedFrameworks": [
84-
"react", "vue", "angular", "web-components", "ember", "html", "svelte", "preact", "react-native"
91+
"react"
8592
],
8693
"icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
8794
}

preset.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,33 @@ function managerEntries(entry = []) {
66
return [...entry, require.resolve("./dist/esm/preset/manager")];
77
}
88

9+
const defaultIstanbulOptions = {
10+
cwd: __dirname,
11+
exclude: [
12+
"**/*.d.ts",
13+
"**/*{.,-}{spec,stories,types}.{js,jsx,ts,tsx}",
14+
]
15+
}
16+
17+
const babel = async (babelConfig, options) => {
18+
if (options.useExternalInstrumentation) {
19+
return babelConfig
20+
}
21+
22+
babelConfig.plugins.push(
23+
[
24+
"istanbul",
25+
{
26+
...defaultIstanbulOptions,
27+
...options.istanbul,
28+
},
29+
],
30+
)
31+
return babelConfig
32+
};
33+
934
module.exports = {
1035
managerEntries,
1136
config,
37+
babel
1238
};

src/Panel.tsx

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Tab.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Tool.tsx

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)