Skip to content

Commit 6018eba

Browse files
committed
Setup Storybook for testing UI components
This sets up Storybook for testing of React components. It adds stories for some of the MRVA components. It does not add stories for the main MRVA views since those are not independent of VSCode and need to be run from within VSCode.
1 parent da90651 commit 6018eba

22 files changed

+42897
-10581
lines changed

.vscode/launch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
"outFiles": [
125125
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
126126
],
127+
},
128+
{
129+
"name": "Launch Storybook",
130+
"type": "node",
131+
"request": "launch",
132+
"cwd": "${workspaceFolder}/extensions/ql-vscode",
133+
"runtimeExecutable": "npm",
134+
"runtimeArgs": ["run-script", "storybook"]
127135
}
128136
]
129137
}

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ $ vscode/scripts/code-cli.sh --install-extension dist/vscode-codeql-*.vsix # if
7777

7878
You can use VS Code to debug the extension without explicitly installing it. Just open this directory as a workspace in VS Code, and hit `F5` to start a debugging session.
7979

80+
### Storybook
81+
82+
You can use [Storybook](https://storybook.js.org/) to preview React components outside VSCode. Inside the `extensions/ql-vscode` directory, run:
83+
84+
```shell
85+
npm run storybook
86+
```
87+
88+
Your browser should automatically open to the Storybook UI. Stories live in the `src/stories` directory.
89+
90+
Alternatively, you can start Storybook inside of VSCode. There is a VSCode launch configuration for starting Storybook. It can be found in the debug view.
91+
8092
### Running the unit tests and integration tests that do not require a CLI instance
8193

8294
Unit tests and many integration tests do not require a copy of the CodeQL CLI.

extensions/ql-vscode/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
"stories": [
3+
"../src/**/*.stories.mdx",
4+
"../src/**/*.stories.@(js|jsx|ts|tsx)"
5+
],
6+
"addons": [
7+
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
9+
"@storybook/addon-interactions"
10+
],
11+
"framework": "@storybook/react",
12+
"core": {
13+
"builder": "@storybook/builder-webpack5"
14+
}
15+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { addons } from '@storybook/addons';
2+
import { themes } from '@storybook/theming';
3+
4+
addons.setConfig({
5+
theme: themes.dark,
6+
enableShortcuts: false,
7+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { themes } from '@storybook/theming';
2+
3+
// Allow all stories/components to use Codicons
4+
import '@vscode/codicons/dist/codicon.css';
5+
6+
import '../src/stories/vscode-theme.css';
7+
8+
export const parameters = {
9+
actions: { argTypesRegex: "^on[A-Z].*" },
10+
controls: {
11+
matchers: {
12+
color: /(background|color)$/i,
13+
date: /Date$/,
14+
},
15+
},
16+
docs: {
17+
theme: themes.dark,
18+
},
19+
backgrounds: {
20+
default: 'dark',
21+
values: [
22+
{
23+
name: 'dark',
24+
value: '#1e1e1e',
25+
},
26+
],
27+
},
28+
options: {
29+
storySort: {
30+
order: ['WebView UI Toolkit', 'MRVA'],
31+
},
32+
},
33+
};

0 commit comments

Comments
 (0)