Skip to content

Commit b8d0f0e

Browse files
michnowakmarcinkrasowskitomaszpacior
authored
feat:storybook vite migration (#410)
* feat: migrate Storybook to use nextjs-vite and update dependencies * feat: migrate Storybook to use nextjs-vite and update dependencies * feat: integrate Vitest for testing Storybook components and update dependencies * feat: add Storybook test for article list and update notification details status * feat: enhance Storybook configuration * fix: reorder Storybook test script in package.json * fix: update Storybook configuration to use process.env as an object * fix: update Storybook build scripts for improved performance * feat: integrate SWC and Vitest for api-harmonization and sdk testing * feat: update test scripts and add PageService tests for api-harmonization * feat: add @o2s/vitest-config package and update vitest configuration for article-list * fix: correct test script syntax in package.json for proper execution * chore: remove article-list unit tests as they are no longer needed * chore: update test configurations * chore: remove unnecessary newline in vitest configuration for user account * feat: add vitest configuration and unit tests for article and ticket-details mappers * feat: add vitest test scripts and configuration to multiple package.json files * feat: add unit tests for various mappers and update vitest configuration * fix: update package-lock.json nad downgrade playwright module. * fix: add posinstall command * fix: updated build and tst scripts in some blocks * fix: added missing config files * fix: fixed client files * fix: remove postinstall script * chore: update package-lock.json and package.json for dependency management --------- Co-authored-by: Marcin Krasowski <marcin.krasowski@hycom.pl> Co-authored-by: tomaszpacior <tomasz.paciorkowski@hycom.pl>
1 parent 55fec44 commit b8d0f0e

File tree

208 files changed

+4599
-2165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+4599
-2165
lines changed

.storybook/main.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import type { StorybookConfig } from '@storybook/nextjs';
1+
import type { StorybookConfig } from '@storybook/nextjs-vite';
2+
import tailwindcss from '@tailwindcss/postcss';
3+
import react from '@vitejs/plugin-react';
24
import * as dotenv from 'dotenv';
5+
import path from 'path';
6+
import { fileURLToPath } from 'url';
7+
import { mergeConfig } from 'vite';
8+
import svgr from 'vite-plugin-svgr';
9+
import tsconfigPaths from 'vite-tsconfig-paths';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
313

414
const env: {
515
NEXT_PUBLIC_API_URL?: string;
@@ -17,9 +27,9 @@ const config: StorybookConfig = {
1727
'../packages/blocks/**/src/frontend/**/*.stories.@(js|jsx|mjs|ts|tsx)',
1828
'../packages/ui/**/*.stories.@(js|jsx|mjs|ts|tsx)',
1929
],
20-
addons: ['@storybook/addon-docs', '@storybook/addon-a11y', '@storybook/addon-themes'],
30+
addons: ['@storybook/addon-docs', '@storybook/addon-a11y', '@storybook/addon-themes', '@storybook/addon-vitest'],
2131
framework: {
22-
name: '@storybook/nextjs',
32+
name: '@storybook/nextjs-vite',
2333
options: {},
2434
},
2535
typescript: {
@@ -29,5 +39,49 @@ const config: StorybookConfig = {
2939
...config,
3040
...env,
3141
}),
42+
async viteFinal(config) {
43+
return mergeConfig(config, {
44+
plugins: [
45+
react({
46+
jsxRuntime: 'automatic',
47+
}),
48+
tsconfigPaths(),
49+
svgr({
50+
// Same behavior as @svgr/webpack
51+
svgrOptions: {
52+
exportType: 'default',
53+
ref: true,
54+
svgo: false,
55+
titleProp: true,
56+
},
57+
include: '**/*.svg',
58+
}),
59+
],
60+
define: {
61+
process: {
62+
env: env,
63+
},
64+
},
65+
optimizeDeps: {
66+
include: ['@o2s/framework/modules', '@o2s/framework/sdk'],
67+
},
68+
resolve: {
69+
conditions: ['import', 'module', 'browser', 'default'],
70+
alias: {
71+
'@o2s/configs.integrations/live-preview': path.resolve(__dirname, './mocks/live-preview.mock.ts'),
72+
'@o2s/framework/sdk': path.resolve(__dirname, '../packages/framework/src/sdk.ts'),
73+
'@o2s/framework/modules': path.resolve(__dirname, '../packages/framework/src/index.ts'),
74+
},
75+
},
76+
ssr: {
77+
noExternal: ['@o2s/**'],
78+
},
79+
css: {
80+
postcss: {
81+
plugins: [tailwindcss],
82+
},
83+
},
84+
});
85+
},
3286
};
3387
export default config;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const LivePreview = {
2+
Provider: ({ children }: { children: React.ReactNode }) => children,
3+
useInspector: () => () => ({}),
4+
};

.storybook/preview.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { NextIntlClientProvider } from 'next-intl';
3-
import type { Preview } from '@storybook/nextjs';
4-
import { createRouter } from '@storybook/nextjs/router.mock';
5-
import { createNavigation } from '@storybook/nextjs/navigation.mock';
3+
import type { Preview } from '@storybook/nextjs-vite';
4+
import { createRouter } from '@storybook/nextjs-vite/router.mock';
5+
import { createNavigation } from '@storybook/nextjs-vite/navigation.mock';
66
import { withThemeByClassName } from '@storybook/addon-themes';
77

88
import { GlobalProvider } from '@o2s/ui/providers/GlobalProvider';
@@ -20,12 +20,22 @@ createNavigation({});
2020

2121
const preview: Preview = {
2222
parameters: {
23-
controls: {
24-
matchers: {
25-
color: /(background|color)$/i,
26-
date: /Date$/i,
23+
nextjs: {
24+
appDirectory: true,
2725
},
28-
},
26+
controls: {
27+
matchers: {
28+
color: /(background|color)$/i,
29+
date: /Date$/i,
30+
},
31+
},
32+
33+
a11y: {
34+
// 'todo' - show a11y violations in the test UI only
35+
// 'error' - fail CI on a11y violations
36+
// 'off' - skip a11y checks entirely
37+
test: 'todo'
38+
}
2939
},
3040
decorators: [
3141
withThemeByClassName({

.storybook/vitest.setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as a11yAddonAnnotations from "@storybook/addon-a11y/preview";
2+
import { setProjectAnnotations } from '@storybook/nextjs-vite';
3+
import * as projectAnnotations from './preview';
4+
5+
// This is an important step to apply the right configuration when testing your stories.
6+
// More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations
7+
setProjectAnnotations([a11yAddonAnnotations, projectAnnotations]);

apps/api-harmonization/package.json

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"debug": "nest start --debug --watch --preserveWatchOutput",
1616
"build": "nest build",
1717
"start": "node dist/main",
18+
"test": "vitest run",
19+
"test:watch": "vitest",
20+
"test:cov": "vitest run --coverage",
21+
"test:debug": "vitest --inspect-brk --inspect --logHeapUsage --threads=false",
1822
"lint": "tsc --noEmit && eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
1923
"format": "prettier --write \"src/**/*.ts\"",
2024
"generate:component": "turbo gen api-component"
@@ -108,22 +112,5 @@
108112
"ts-node": "^10.9.2",
109113
"tsconfig-paths": "^4.2.0",
110114
"typescript": "^5.9.3"
111-
},
112-
"jest": {
113-
"moduleFileExtensions": [
114-
"js",
115-
"json",
116-
"ts"
117-
],
118-
"rootDir": "src",
119-
"testRegex": ".*\\.spec\\.ts$",
120-
"transform": {
121-
"^.+\\.(t|j)s$": "ts-jest"
122-
},
123-
"collectCoverageFrom": [
124-
"**/*.(t|j)s"
125-
],
126-
"coverageDirectory": "../coverage",
127-
"testEnvironment": "node"
128115
}
129116
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { HttpService } from '@nestjs/axios';
2+
import { Test, TestingModule } from '@nestjs/testing';
3+
import { beforeEach, describe, expect, it, vi } from 'vitest';
4+
5+
import { LoggerService } from '@o2s/utils.logger';
6+
7+
import { AppService } from './app.service';
8+
9+
describe('AppService', () => {
10+
let service: AppService;
11+
let httpService: HttpService;
12+
13+
beforeEach(async () => {
14+
const module: TestingModule = await Test.createTestingModule({
15+
providers: [
16+
AppService,
17+
{
18+
provide: HttpService,
19+
useValue: {
20+
axiosRef: {
21+
interceptors: {
22+
request: { use: vi.fn() },
23+
response: { use: vi.fn() },
24+
},
25+
},
26+
},
27+
},
28+
{
29+
provide: LoggerService,
30+
useValue: {
31+
apiRequest: vi.fn(),
32+
apiRequestError: vi.fn(),
33+
apiResponse: vi.fn(),
34+
apiResponseError: vi.fn(),
35+
},
36+
},
37+
],
38+
}).compile();
39+
40+
service = module.get<AppService>(AppService);
41+
httpService = module.get<HttpService>(HttpService);
42+
});
43+
44+
it('should be defined', () => {
45+
expect(service).toBeDefined();
46+
});
47+
48+
it('should configure axios interceptors on module init', () => {
49+
service.onModuleInit();
50+
expect(httpService.axiosRef.interceptors.request.use).toHaveBeenCalled();
51+
expect(httpService.axiosRef.interceptors.response.use).toHaveBeenCalled();
52+
});
53+
});

0 commit comments

Comments
 (0)