Skip to content

Commit

Permalink
Merge pull request #1497 from github/koesie10/storybook
Browse files Browse the repository at this point in the history
Setup Storybook for testing UI components
  • Loading branch information
koesie10 committed Sep 8, 2022
2 parents 7c4eac8 + 2ee46cf commit 24652a8
Show file tree
Hide file tree
Showing 28 changed files with 58,628 additions and 10,582 deletions.
6 changes: 5 additions & 1 deletion .gitattributes
Expand Up @@ -18,4 +18,8 @@ yarn.lock merge=binary
# https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitattributes.html
# suggests that this might interleave lines arbitrarily, but empirically
# it keeps added chunks contiguous
CHANGELOG.md merge=union
CHANGELOG.md merge=union

# Mark some JSON files containing test data as generated so they are not included
# as part of diffs or language statistics.
extensions/ql-vscode/src/stories/remote-queries/data/*.json linguist-generated
8 changes: 8 additions & 0 deletions .vscode/launch.json
Expand Up @@ -124,6 +124,14 @@
"outFiles": [
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
],
},
{
"name": "Launch Storybook",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}/extensions/ql-vscode",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "storybook"]
}
]
}
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -77,6 +77,20 @@ $ vscode/scripts/code-cli.sh --install-extension dist/vscode-codeql-*.vsix # if

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.

### Storybook

You can use [Storybook](https://storybook.js.org/) to preview React components outside VSCode. Inside the `extensions/ql-vscode` directory, run:

```shell
npm run storybook
```

Your browser should automatically open to the Storybook UI. Stories live in the `src/stories` directory.

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.

More information about Storybook can be found inside the **Overview** page once you have launched Storybook.

### Running the unit tests and integration tests that do not require a CLI instance

Unit tests and many integration tests do not require a copy of the CodeQL CLI.
Expand Down
2 changes: 2 additions & 0 deletions extensions/ql-vscode/.npmrc
@@ -0,0 +1,2 @@
# Storybook requires this option to be set. See https://github.com/storybookjs/storybook/issues/18298
legacy-peer-deps=true
19 changes: 19 additions & 0 deletions extensions/ql-vscode/.storybook/main.ts
@@ -0,0 +1,19 @@
import type { StorybookConfig } from '@storybook/core-common';

const config: StorybookConfig = {
stories: [
'../src/**/*.stories.mdx',
'../src/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions'
],
framework: '@storybook/react',
core: {
builder: '@storybook/builder-webpack5'
}
};

module.exports = config;
7 changes: 7 additions & 0 deletions extensions/ql-vscode/.storybook/manager.ts
@@ -0,0 +1,7 @@
import { addons } from '@storybook/addons';
import { themes } from '@storybook/theming';

addons.setConfig({
theme: themes.dark,
enableShortcuts: false,
});
37 changes: 37 additions & 0 deletions extensions/ql-vscode/.storybook/preview.ts
@@ -0,0 +1,37 @@
import { themes } from '@storybook/theming';
import { action } from '@storybook/addon-actions';

// Allow all stories/components to use Codicons
import '@vscode/codicons/dist/codicon.css';

import '../src/stories/vscode-theme.css';

// https://storybook.js.org/docs/react/configure/overview#configure-story-rendering
export const parameters = {
// All props starting with `on` will automatically receive an action as a prop
actions: { argTypesRegex: "^on[A-Z].*" },
// All props matching these names will automatically get the correct control
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
// Use a dark theme to be aligned with VSCode
docs: {
theme: themes.dark,
},
backgrounds: {
default: 'dark',
values: [
{
name: 'dark',
value: '#1e1e1e',
},
],
}
};

(window as any).acquireVsCodeApi = () => ({
postMessage: action('post-vscode-message')
});

0 comments on commit 24652a8

Please sign in to comment.