diff --git a/nx.json b/nx.json index 924657e4f4..882345c8be 100644 --- a/nx.json +++ b/nx.json @@ -39,6 +39,24 @@ "{workspaceRoot}/.eslintrc.js", "{workspaceRoot}/tools/eslint-rules/**/*" ] + }, + "@nx/vite:test": { + "cache": true, + "inputs": ["default", "^default"] + }, + "@nx/vite:build": { + "cache": true, + "dependsOn": ["^build"], + "inputs": ["default", "^default"] + }, + "storybook:build": { + "cache": true, + "inputs": [ + "default", + "^default", + "{projectRoot}/.storybook/**/*", + "{projectRoot}/tsconfig.storybook.json" + ] } }, "installation": { @@ -54,21 +72,10 @@ } } }, - "plugins": [ - { - "plugin": "@nx/storybook/plugin", - "options": { - "buildStorybookTargetName": "build-storybook", - "serveStorybookTargetName": "storybook", - "testStorybookTargetName": "test-storybook", - "staticStorybookTargetName": "static-storybook" - } - } - ], "tasksRunnerOptions": { "default": { "options": { - "cacheableOperations": ["build-storybook"] + "cacheableOperations": ["storybook:build"] } } }, diff --git a/packages/twenty-ui/.storybook/main.tsx b/packages/twenty-ui/.storybook/main.ts similarity index 75% rename from packages/twenty-ui/.storybook/main.tsx rename to packages/twenty-ui/.storybook/main.ts index 793a8ab757..27f1649f89 100644 --- a/packages/twenty-ui/.storybook/main.tsx +++ b/packages/twenty-ui/.storybook/main.ts @@ -3,17 +3,18 @@ import { StorybookConfig } from '@storybook/react-vite'; const config: StorybookConfig = { stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'], addons: [ + '@storybook/addon-links', '@storybook/addon-essentials', + '@storybook/addon-onboarding', '@storybook/addon-interactions', + '@storybook/addon-coverage', '@storybook/addon-themes', + 'storybook-addon-cookie', + 'storybook-addon-pseudo-states', ], framework: { name: '@storybook/react-vite', - options: { - builder: { - viteConfigPath: 'vite.config.ts', - }, - }, + options: {}, }, }; diff --git a/packages/twenty-ui/.storybook/preview.tsx b/packages/twenty-ui/.storybook/preview.ts similarity index 100% rename from packages/twenty-ui/.storybook/preview.tsx rename to packages/twenty-ui/.storybook/preview.ts diff --git a/packages/twenty-ui/jest.config.ts b/packages/twenty-ui/jest.config.ts index 36a625c5b3..39ca6f80e5 100644 --- a/packages/twenty-ui/jest.config.ts +++ b/packages/twenty-ui/jest.config.ts @@ -1,11 +1,23 @@ -/* eslint-disable */ -export default { +import { JestConfigWithTsJest } from 'ts-jest'; + +const jestConfig: JestConfigWithTsJest = { displayName: 'twenty-ui', preset: '../../jest.preset.js', - testEnvironment: 'node', + setupFilesAfterEnv: ['./setupTests.ts'], + transformIgnorePatterns: ['../../node_modules/'], transform: { - '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], + '^.+\\.[tj]sx?$': [ + '@swc/jest', + { + jsc: { + parser: { syntax: 'typescript', tsx: true }, + transform: { react: { runtime: 'automatic' } }, + }, + }, + ], }, - moduleFileExtensions: ['ts', 'js', 'html'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], coverageDirectory: '../../coverage/packages/twenty-ui', }; + +export default jestConfig; diff --git a/packages/twenty-ui/project.json b/packages/twenty-ui/project.json index 46b5cf5b41..c32123554f 100644 --- a/packages/twenty-ui/project.json +++ b/packages/twenty-ui/project.json @@ -17,6 +17,7 @@ ], "outputs": ["{projectRoot}/src/index.ts", "{projectRoot}/src/*/index.ts"], "options": { + "outputPath": "{projectRoot}/dist", "command": "npx ts-node --esm {projectRoot}/scripts/generateBarrels.ts" } }, @@ -37,9 +38,38 @@ }, "test": { "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "outputs": ["{projectRoot}/coverage"], "options": { - "jestConfig": "packages/twenty-ui/jest.config.ts" + "jestConfig": "{projectRoot}/jest.config.ts" + } + }, + "storybook:dev": { + "executor": "@nx/storybook:storybook", + "options": { + "port": 6007, + "configDir": "{projectRoot}/.storybook" + }, + "configurations": { + "ci": { "quiet": true } + } + }, + "storybook:build": { + "executor": "@nx/storybook:build", + "outputs": ["{options.outputDir}"], + "options": { + "outputDir": "{projectRoot}/storybook-static", + "configDir": "{projectRoot}/.storybook" + }, + "configurations": { + "ci": { + "quiet": true + } + } + }, + "storybook:test": { + "executor": "nx:run-commands", + "options": { + "command": "test-storybook -c {projectRoot}/.storybook --url=http://localhost:6007" } } }, diff --git a/packages/twenty-ui/setupTests.ts b/packages/twenty-ui/setupTests.ts new file mode 100644 index 0000000000..8f2609b7b3 --- /dev/null +++ b/packages/twenty-ui/setupTests.ts @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; diff --git a/packages/twenty-ui/src/components/Pill/Pill.stories.ts b/packages/twenty-ui/src/components/Pill/__stories__/Pill.stories.ts similarity index 56% rename from packages/twenty-ui/src/components/Pill/Pill.stories.ts rename to packages/twenty-ui/src/components/Pill/__stories__/Pill.stories.ts index d657334cf3..d7f099efa1 100644 --- a/packages/twenty-ui/src/components/Pill/Pill.stories.ts +++ b/packages/twenty-ui/src/components/Pill/__stories__/Pill.stories.ts @@ -1,20 +1,18 @@ import { Meta, StoryObj } from '@storybook/react'; -import { ComponentDecorator } from '../../testing/decorators/ComponentDecorator'; - -import { Pill } from './Pill'; +import { ComponentDecorator } from '../../../testing/decorators/ComponentDecorator'; +import { Pill } from '../Pill'; const meta: Meta = { - title: 'UI/Display/Pill/Pill', + title: 'UI/Display/Pill', component: Pill, + decorators: [ComponentDecorator], + args: { + label: 'Soon', + }, }; export default meta; type Story = StoryObj; -export const Default: Story = { - args: { - label: 'Soon', - }, - decorators: [ComponentDecorator], -}; +export const Default: Story = {}; diff --git a/packages/twenty-ui/src/nx-react.d.ts b/packages/twenty-ui/src/nx-react.d.ts new file mode 100644 index 0000000000..639a9eed3a --- /dev/null +++ b/packages/twenty-ui/src/nx-react.d.ts @@ -0,0 +1,3 @@ +/// +/// +/// diff --git a/packages/twenty-ui/src/vite-env.d.ts b/packages/twenty-ui/src/vite-env.d.ts new file mode 100644 index 0000000000..b1f45c7866 --- /dev/null +++ b/packages/twenty-ui/src/vite-env.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/packages/twenty-ui/tsconfig.json b/packages/twenty-ui/tsconfig.json index 9b941a1f23..70fb1ad50d 100644 --- a/packages/twenty-ui/tsconfig.json +++ b/packages/twenty-ui/tsconfig.json @@ -9,7 +9,7 @@ "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "jsx": "react" + "jsx": "react-jsx" }, "files": [], "include": [], diff --git a/packages/twenty-ui/tsconfig.spec.json b/packages/twenty-ui/tsconfig.spec.json index 8cf4b5eb89..445324dc3f 100644 --- a/packages/twenty-ui/tsconfig.spec.json +++ b/packages/twenty-ui/tsconfig.spec.json @@ -9,7 +9,9 @@ "jest.config.ts", "src/**/*.d.ts", "src/**/*.spec.ts", + "src/**/*.spec.tsx", "src/**/*.test.ts", + "src/**/*.test.tsx", "vite.config.ts" ] } diff --git a/packages/twenty-ui/vite.config.ts b/packages/twenty-ui/vite.config.ts index 44ea37dadd..635bce6ef6 100644 --- a/packages/twenty-ui/vite.config.ts +++ b/packages/twenty-ui/vite.config.ts @@ -1,5 +1,6 @@ /// import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin'; +import react from '@vitejs/plugin-react-swc'; import * as path from 'path'; import { defineConfig } from 'vite'; import dts from 'vite-plugin-dts'; @@ -9,6 +10,7 @@ export default defineConfig({ cacheDir: '../../node_modules/.vite/packages/twenty-ui', plugins: [ + react(), nxViteTsPaths(), dts({ entryRoot: 'src',