2024-01-04 01:07:25 +03:00
|
|
|
import { StorybookConfig } from '@storybook/react-vite';
|
2023-12-10 18:22:43 +03:00
|
|
|
|
|
|
|
const computeStoriesGlob = () => {
|
|
|
|
if (process.env.STORYBOOK_SCOPE === 'pages') {
|
|
|
|
return [
|
|
|
|
'../src/pages/**/*.stories.@(js|jsx|ts|tsx)',
|
|
|
|
'../src/__stories__/*.stories.@(js|jsx|ts|tsx)',
|
|
|
|
'../src/pages/**/*.docs.mdx',
|
2024-01-04 01:07:25 +03:00
|
|
|
'../src/__stories__/*.docs.mdx',
|
|
|
|
];
|
2023-12-10 18:22:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.STORYBOOK_SCOPE === 'modules') {
|
2024-01-04 01:07:25 +03:00
|
|
|
return [
|
2024-05-15 23:54:51 +03:00
|
|
|
'../src/modules/**/!(perf)/*.stories.@(js|jsx|ts|tsx)',
|
2024-01-04 01:07:25 +03:00
|
|
|
'../src/modules/**/*.docs.mdx',
|
|
|
|
];
|
2023-12-10 18:22:43 +03:00
|
|
|
}
|
|
|
|
|
Generic Profiling story to wrap any component (#5341)
This PR introduces a Profiling feature for our story book tests.
It also implements a new CI job : front-sb-test-performance, that only
runs stories suffixed with `.perf.stories.tsx`
## How it works
It allows to wrap any component into an array of React Profiler
components that will run tests many times to have the most replicable
average render time possible.
It is simply used by calling the new `getProfilingStory` util.
Internally it creates a defined number of tests, separated by an
arbitrary waiting time to allow the CPU to give more stable results.
It will do 3 warm-up and 3 finishing runs of tests because the first and
last renders are always a bit erratic, so we want to measure only the
runs in-between.
On the UI side it gives a table of results :
<img width="515" alt="image"
src="https://github.com/twentyhq/twenty/assets/26528466/273d2d91-26da-437a-890e-778cb6c1f993">
On the programmatic side, it stores the result in a div that can then be
parsed by the play fonction of storybook, to expect a defined threshold.
```tsx
play: async ({ canvasElement }) => {
await findByTestId(
canvasElement,
'profiling-session-finished',
{},
{ timeout: 60000 },
);
const profilingReport = getProfilingReportFromDocument(canvasElement);
if (!isDefined(profilingReport)) {
return;
}
const p95result = profilingReport?.total.p95;
expect(
p95result,
`Component render time is more than p95 threshold (${p95ThresholdInMs}ms)`,
).toBeLessThan(p95ThresholdInMs);
},
```
2024-05-15 14:50:02 +03:00
|
|
|
if (process.env.STORYBOOK_SCOPE === 'performance') {
|
2024-05-15 23:54:51 +03:00
|
|
|
return ['../src/modules/**/perf/*.perf.stories.@(js|jsx|ts|tsx)'];
|
Generic Profiling story to wrap any component (#5341)
This PR introduces a Profiling feature for our story book tests.
It also implements a new CI job : front-sb-test-performance, that only
runs stories suffixed with `.perf.stories.tsx`
## How it works
It allows to wrap any component into an array of React Profiler
components that will run tests many times to have the most replicable
average render time possible.
It is simply used by calling the new `getProfilingStory` util.
Internally it creates a defined number of tests, separated by an
arbitrary waiting time to allow the CPU to give more stable results.
It will do 3 warm-up and 3 finishing runs of tests because the first and
last renders are always a bit erratic, so we want to measure only the
runs in-between.
On the UI side it gives a table of results :
<img width="515" alt="image"
src="https://github.com/twentyhq/twenty/assets/26528466/273d2d91-26da-437a-890e-778cb6c1f993">
On the programmatic side, it stores the result in a div that can then be
parsed by the play fonction of storybook, to expect a defined threshold.
```tsx
play: async ({ canvasElement }) => {
await findByTestId(
canvasElement,
'profiling-session-finished',
{},
{ timeout: 60000 },
);
const profilingReport = getProfilingReportFromDocument(canvasElement);
if (!isDefined(profilingReport)) {
return;
}
const p95result = profilingReport?.total.p95;
expect(
p95result,
`Component render time is more than p95 threshold (${p95ThresholdInMs}ms)`,
).toBeLessThan(p95ThresholdInMs);
},
```
2024-05-15 14:50:02 +03:00
|
|
|
}
|
|
|
|
|
2023-12-10 18:22:43 +03:00
|
|
|
if (process.env.STORYBOOK_SCOPE === 'ui-docs') {
|
2024-01-04 01:07:25 +03:00
|
|
|
return ['../src/modules/ui/**/*.docs.mdx'];
|
2023-12-10 18:22:43 +03:00
|
|
|
}
|
|
|
|
|
2024-01-04 01:07:25 +03:00
|
|
|
return ['../src/**/*.docs.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'];
|
2023-12-10 18:22:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const config: StorybookConfig = {
|
|
|
|
stories: computeStoriesGlob(),
|
|
|
|
staticDirs: ['../public'],
|
|
|
|
addons: [
|
|
|
|
'@storybook/addon-links',
|
|
|
|
'@storybook/addon-essentials',
|
|
|
|
'@storybook/addon-onboarding',
|
|
|
|
'@storybook/addon-interactions',
|
|
|
|
'@storybook/addon-coverage',
|
2024-04-11 18:28:12 +03:00
|
|
|
'storybook-dark-mode',
|
2023-12-10 18:22:43 +03:00
|
|
|
'storybook-addon-cookie',
|
|
|
|
'storybook-addon-pseudo-states',
|
|
|
|
],
|
|
|
|
framework: {
|
|
|
|
name: '@storybook/react-vite',
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
export default config;
|