Skip to content

The open alternative to Salesforce, designed for AI.

Run twenty-ui unit tests on vitest and add a component conformance helper (#25548)

Raphaël Bosif8be00469ebd
diff --git a/CLAUDE.md b/CLAUDE.md
index f8bf3598da5..4f24b2df03c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -28,6 +28,7 @@ bash packages/twenty-utils/setup-dev-env.sh # Postgres/Redis + DB init; only f
yarn start # front + server + worker
npx jest path/to/file.spec.ts --config=packages/<pkg>/jest.config.mjs # single test file (preferred)
+npx vitest run --root packages/twenty-ui --project unit <file> # twenty-ui runs on vitest, not jest
npx nx test twenty-server # package unit tests (same for twenty-front, ...)
npx nx run twenty-server:test:integration:with-db-reset
npx nx storybook:build twenty-front && npx nx storybook:test twenty-front
diff --git a/packages/twenty-ui/README.md b/packages/twenty-ui/README.md
index 923a53a29c7..9df9f8c1b14 100644
--- a/packages/twenty-ui/README.md
+++ b/packages/twenty-ui/README.md
@@ -72,6 +72,7 @@ import { Button } from 'twenty-ui/input';
npx nx build twenty-ui # Build the library (dual ESM/CJS + types)
npx nx storybook:serve:dev twenty-ui # Run Storybook
npx nx test twenty-ui # Run unit tests
+npx vitest run --root packages/twenty-ui --project unit <file> # Run a single test file
```
# License
diff --git a/packages/twenty-ui/__mocks__/imageMockUi.js b/packages/twenty-ui/__mocks__/imageMockUi.js
deleted file mode 100644
index 602eb23ee2e..00000000000
--- a/packages/twenty-ui/__mocks__/imageMockUi.js
+++ /dev/null
@@ -1 +0,0 @@
-export default 'test-file-stub';
diff --git a/packages/twenty-ui/__mocks__/styleMock.js b/packages/twenty-ui/__mocks__/styleMock.js
deleted file mode 100644
index 4eaf68f45d4..00000000000
--- a/packages/twenty-ui/__mocks__/styleMock.js
+++ /dev/null
@@ -1,7 +0,0 @@
-// Proxy so `styles.anyClassName` resolves to its key when SCSS is imported in Jest.
-module.exports = new Proxy(
- {},
- {
- get: (_target, key) => (key === '__esModule' ? false : String(key)),
- },
-);
diff --git a/packages/twenty-ui/jest.config.mjs b/packages/twenty-ui/jest.config.mjs
deleted file mode 100644
index 2955b0d6f44..00000000000
--- a/packages/twenty-ui/jest.config.mjs
+++ /dev/null
@@ -1,42 +0,0 @@
-import { readFileSync } from 'fs';
-import { dirname, resolve } from 'path';
-import { pathsToModuleNameMapper } from 'ts-jest';
-import { fileURLToPath } from 'url';
-
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = dirname(__filename);
-
-const tsConfigPath = resolve(__dirname, './tsconfig.json');
-const tsConfig = JSON.parse(readFileSync(tsConfigPath, 'utf8'));
-
-const jestConfig = {
- displayName: 'twenty-ui',
- preset: '../../jest.preset.js',
- setupFilesAfterEnv: ['./setupTests.ts'],
- testEnvironment: 'jsdom',
- transformIgnorePatterns: ['../../node_modules/'],
- transform: {
- '^.+\\.[tj]sx?$': [
- '@swc/jest',
- {
- jsc: {
- parser: { syntax: 'typescript', tsx: true },
- transform: { react: { runtime: 'automatic' } },
- },
- },
- ],
- },
- moduleNameMapper: {
- '^@assets/(.*)\\.svg\\?react$': '<rootDir>/__mocks__/imageMockUi.js',
- '\\.(jpg|jpeg|png|gif|webp|svg|svg)$': '<rootDir>/__mocks__/imageMockUi.js',
- '\\.(scss|css)$': '<rootDir>/__mocks__/styleMock.js',
- ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths, {
- prefix: '<rootDir>/',
- }),
- },
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
- extensionsToTreatAsEsm: ['.ts', '.tsx'],
- coverageDirectory: './coverage',
-};
-
-export default jestConfig;
diff --git a/packages/twenty-ui/package.json b/packages/twenty-ui/package.json
index db1c4b6aad8..ebc61d274a6 100644
--- a/packages/twenty-ui/package.json
+++ b/packages/twenty-ui/package.json
@@ -40,19 +40,17 @@
"@storybook/addon-vitest": "^10.4.6",
"@storybook/react-vite": "^10.4.6",
"@swc/core": "^1.15.11",
- "@swc/jest": "^0.2.39",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
- "@types/jest": "^30.0.0",
+ "@testing-library/user-event": "^14.6.1",
"@types/react": "^19.2.0",
"@types/react-dom": "^19.2.0",
"@vitejs/plugin-react-swc": "^4.3.1",
"@vitest/browser-playwright": "^4.1.0",
"esbuild": "^0.28.1",
"glob": "^11.1.0",
- "jest": "29.7.0",
- "jest-environment-jsdom": "30.0.0-beta.3",
+ "jsdom": "^30.0.1",
"prettier": "^3.1.1",
"react": "^19.2.0",
"react-dom": "^19.2.0",
@@ -61,7 +59,6 @@
"size-limit": "^12.1.0",
"slash": "^5.1.0",
"storybook-addon-pseudo-states": "^10.3.3",
- "ts-jest": "^29.1.1",
"tsx": "^4.19.3",
"typescript": "^5.9.3",
"vite-plugin-checker": "^0.10.2",
diff --git a/packages/twenty-ui/project.json b/packages/twenty-ui/project.json
index a1f0342210b..0a0053d3be9 100644
--- a/packages/twenty-ui/project.json
+++ b/packages/twenty-ui/project.json
@@ -97,7 +97,18 @@
},
"lint": {},
"fmt": { "options": { "files": "src" }, "configurations": { "fix": {} } },
- "test": {},
+ "test": {
+ "executor": "nx:run-commands",
+ "cache": true,
+ "inputs": ["default", "^default"],
+ "options": {
+ "cwd": "{projectRoot}",
+ "command": "npx vitest run --project unit"
+ },
+ "configurations": {
+ "watch": { "command": "npx vitest --project unit" }
+ }
+ },
"typecheck": {},
"storybook:build": { "configurations": { "test": {} } },
"storybook:serve:dev": { "options": { "port": 6008 } },
@@ -105,8 +116,16 @@
"options": { "buildTarget": "twenty-ui:storybook:build", "port": 6008 },
"configurations": { "test": {} }
},
- "storybook:test": {},
- "storybook:test:no-coverage": {},
+ "storybook:test": {
+ "options": {
+ "command": "vitest run --coverage --shard={args.shard} --project storybook"
+ }
+ },
+ "storybook:test:no-coverage": {
+ "options": {
+ "command": "vitest run --shard={args.shard} --project storybook"
+ }
+ },
"storybook:visual-diff": {
"executor": "nx:run-commands",
"dependsOn": ["storybook:build"],
diff --git a/packages/twenty-ui/setupTests.ts b/packages/twenty-ui/setupTests.ts
index 7b0828bfa80..bb02c60cd05 100644
--- a/packages/twenty-ui/setupTests.ts
+++ b/packages/twenty-ui/setupTests.ts
@@ -1 +1 @@
-import '@testing-library/jest-dom';
+import '@testing-library/jest-dom/vitest';
diff --git a/packages/twenty-ui/src/icon/__tests__/TwentyIconDictionary.test.ts b/packages/twenty-ui/src/icon/__tests__/TwentyIconDictionary.test.ts
index 669eebd04ed..cc474328eba 100644
--- a/packages/twenty-ui/src/icon/__tests__/TwentyIconDictionary.test.ts
+++ b/packages/twenty-ui/src/icon/__tests__/TwentyIconDictionary.test.ts
@@ -1,5 +1,6 @@
import { readFileSync } from 'node:fs';
-import { resolve } from 'node:path';
+import { dirname, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { TWENTY_ICON_DICTIONARY } from '@ui/icon/constants/TwentyIconDictionary';
import {
@@ -7,6 +8,8 @@ import {
generateTwentyIconDictionaryMarkdown,
} from '@ui/icon/internal/generateTwentyIconDictionaryMarkdown';
+const TEST_DIRECTORY = dirname(fileURLToPath(import.meta.url));
+
describe('TwentyIconDictionary', () => {
it('escapes Markdown table delimiters without losing backslashes', () => {
expect(
@@ -22,7 +25,7 @@ describe('TwentyIconDictionary', () => {
it('references icons exported by twenty-ui/icon', () => {
const publicIconBarrel = readFileSync(
- resolve(__dirname, '../index.ts'),
+ resolve(TEST_DIRECTORY, '../index.ts'),
'utf8',
);
@@ -33,7 +36,7 @@ describe('TwentyIconDictionary', () => {
it('references icons available to string-based icon resolution', () => {
const dynamicIconCatalog = readFileSync(
- resolve(__dirname, '../providers/internal/AllIcons.ts'),
+ resolve(TEST_DIRECTORY, '../providers/internal/AllIcons.ts'),
'utf8',
);
@@ -51,7 +54,7 @@ describe('TwentyIconDictionary', () => {
});
it('keeps the generated Markdown synchronized with the manifest', () => {
- const markdownPath = resolve(__dirname, '../icon-dictionary.md');
+ const markdownPath = resolve(TEST_DIRECTORY, '../icon-dictionary.md');
expect(readFileSync(markdownPath, 'utf8')).toBe(
generateTwentyIconDictionaryMarkdown(),
diff --git a/packages/twenty-ui/src/icon/icon-dictionary.md b/packages/twenty-ui/src/icon/icon-dictionary.md
index 6649c1b8cc4..a15db93869d 100644
--- a/packages/twenty-ui/src/icon/icon-dictionary.md
+++ b/packages/twenty-ui/src/icon/icon-dictionary.md
@@ -127,4 +127,4 @@ import { IconHierarchy } from 'twenty-ui/icon';
2. Confirm the visual choice in the linked Figma dictionary.
3. Run `npx nx generateIconDictionary twenty-ui`.
4. Review the `UI/Icon/Icon Dictionary` Storybook story.
-5. Run `npx jest packages/twenty-ui/src/icon/__tests__/TwentyIconDictionary.test.ts --config=packages/twenty-ui/jest.config.mjs`.
+5. Run `npx vitest run --root packages/twenty-ui --project unit src/icon/__tests__/TwentyIconDictionary.test.ts`.
diff --git a/packages/twenty-ui/src/icon/internal/generateTwentyIconDictionaryMarkdown.ts b/packages/twenty-ui/src/icon/internal/generateTwentyIconDictionaryMarkdown.ts
index 5ba4b1591ac..3ca0245f01d 100644
--- a/packages/twenty-ui/src/icon/internal/generateTwentyIconDictionaryMarkdown.ts
+++ b/packages/twenty-ui/src/icon/internal/generateTwentyIconDictionaryMarkdown.ts
@@ -54,6 +54,6 @@ ${categorySections}
2. Confirm the visual choice in the linked Figma dictionary.
3. Run \`npx nx generateIconDictionary twenty-ui\`.
4. Review the \`UI/Icon/Icon Dictionary\` Storybook story.
-5. Run \`npx jest packages/twenty-ui/src/icon/__tests__/TwentyIconDictionary.test.ts --config=packages/twenty-ui/jest.config.mjs\`.
+5. Run \`npx vitest run --root packages/twenty-ui --project unit src/icon/__tests__/TwentyIconDictionary.test.ts\`.
`;
};
diff --git a/packages/twenty-ui/src/input/Checkbox/__tests__/Checkbox.test.tsx b/packages/twenty-ui/src/input/Checkbox/__tests__/Checkbox.test.tsx
index e0afb1ef060..85b25513e7e 100644
--- a/packages/twenty-ui/src/input/Checkbox/__tests__/Checkbox.test.tsx
+++ b/packages/twenty-ui/src/input/Checkbox/__tests__/Checkbox.test.tsx
@@ -1,28 +1,13 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
+import { vi } from 'vitest';
import { Checkbox } from '../Checkbox';
describe('Checkbox', () => {
- const originalPointerEvent = window.PointerEvent;
-
- beforeAll(() => {
- Object.defineProperty(window, 'PointerEvent', {
- configurable: true,
- value: MouseEvent,
- });
- });
-
- afterAll(() => {
- Object.defineProperty(window, 'PointerEvent', {
- configurable: true,
- value: originalPointerEvent,
- });
- });
-
it('keeps the rendered state controlled by the checked prop', async () => {
const user = userEvent.setup();
- const onCheckedChange = jest.fn();
+ const onCheckedChange = vi.fn();
const { rerender } = render(
<Checkbox
checked={false}
diff --git a/packages/twenty-ui/src/input/Field/__tests__/Field.test.tsx b/packages/twenty-ui/src/input/Field/__tests__/Field.test.tsx
new file mode 100644
index 00000000000..283fce94e7c
--- /dev/null
+++ b/packages/twenty-ui/src/input/Field/__tests__/Field.test.tsx
@@ -0,0 +1,61 @@
+import { render } from '@testing-library/react';
+import { type ReactNode } from 'react';
+import { vi } from 'vitest';
+
+import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
+
+import { Field } from '../Field';
+import descriptionStyles from '../internal/FieldDescription.module.scss';
+import errorStyles from '../internal/FieldError.module.scss';
+import labelStyles from '../internal/FieldLabel.module.scss';
+
+const FieldRootWrapper = ({ children }: { children: ReactNode }) => (
+ <Field.Root>{children}</Field.Root>
+);
+
+runComponentConformance({
+ name: 'Field.Root',
+ element: <Field.Root />,
+ refInstanceOf: HTMLDivElement,
+});
+
+runComponentConformance({
+ name: 'Field.Label',
+ element: <Field.Label>Label</Field.Label>,
+ refInstanceOf: HTMLLabelElement,
+ wrapper: FieldRootWrapper,
+ ownClassName: labelStyles.label,
+ renderPropTagName: 'label',
+});
+
+runComponentConformance({
+ name: 'Field.Description',
+ element: <Field.Description>Description</Field.Description>,
+ refInstanceOf: HTMLParagraphElement,
+ wrapper: FieldRootWrapper,
+ ownClassName: descriptionStyles.description,
+});
+
+runComponentConformance({
+ name: 'Field.Error',
+ element: <Field.Error match>Required</Field.Error>,
+ refInstanceOf: HTMLDivElement,
+ wrapper: FieldRootWrapper,
+ ownClassName: errorStyles.error,
+});
+
+describe('Field.Label', () => {
+ it('throws outside Field.Root', () => {
+ const consoleErrorSpy = vi
+ .spyOn(console, 'error')
+ .mockImplementation(() => undefined);
+
+ try {
+ expect(() => render(<Field.Label>Label</Field.Label>)).toThrow(
+ 'Base UI: FieldRootContext is missing',
+ );
+ } finally {
+ consoleErrorSpy.mockRestore();
+ }
+ });
+});
diff --git a/packages/twenty-ui/src/theme-constants/__tests__/ThemeProvider.test.tsx b/packages/twenty-ui/src/theme-constants/__tests__/ThemeProvider.test.tsx
index a1d173f1a5b..caf2ad313ff 100644
--- a/packages/twenty-ui/src/theme-constants/__tests__/ThemeProvider.test.tsx
+++ b/packages/twenty-ui/src/theme-constants/__tests__/ThemeProvider.test.tsx
@@ -1,4 +1,5 @@
import { render } from '@testing-library/react';
+import { vi } from 'vitest';
import { ThemeProvider } from '../ThemeProvider';
import { type ThemeType } from '../themeTypes';
@@ -92,7 +93,7 @@ describe('ThemeProvider token resolution', () => {
};
const mockResolvedTokens = (resolvedTokens: Record<string, string>) => {
- jest.spyOn(window, 'getComputedStyle').mockReturnValue({
+ vi.spyOn(window, 'getComputedStyle').mockReturnValue({
getPropertyValue: (property: string) => resolvedTokens[property] ?? '',
} as CSSStyleDeclaration);
};
@@ -109,7 +110,7 @@ describe('ThemeProvider token resolution', () => {
});
afterEach(() => {
- jest.restoreAllMocks();
+ vi.restoreAllMocks();
});
it('should keep the CSS variable reference when no custom property resolves', () => {
diff --git a/packages/twenty-ui/src/typography/Text/__tests__/Text.test.tsx b/packages/twenty-ui/src/typography/Text/__tests__/Text.test.tsx
new file mode 100644
index 00000000000..dfca9dc890b
--- /dev/null
+++ b/packages/twenty-ui/src/typography/Text/__tests__/Text.test.tsx
@@ -0,0 +1,66 @@
+import { render, screen } from '@testing-library/react';
+
+import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
+
+import { Text } from '../Text';
+import styles from '../Text.module.scss';
+
+runComponentConformance({
+ name: 'Text',
+ element: <Text>Body</Text>,
+ refInstanceOf: HTMLDivElement,
+});
+
+describe('Text', () => {
+ it('adds the truncate class when truncate is set', () => {
+ render(
+ <Text truncate data-testid="text">
+ Body
+ </Text>,
+ );
+
+ expect(screen.getByTestId('text')).toHaveClass(styles.truncate);
+ });
+
+ it('adds the line clamp class and custom property when lineClamp is set', () => {
+ render(
+ <Text lineClamp={2} data-testid="text">
+ Body
+ </Text>,
+ );
+
+ const text = screen.getByTestId('text');
+
+ expect(text).toHaveClass(styles.lineClamp);
+ expect(text.style.getPropertyValue('--text-line-clamp')).toBe('2');
+ });
+
+ it('renders the element given to render with the merged className', () => {
+ render(
+ <Text
+ render={<span className="from-render" />}
+ className="consumer"
+ data-testid="text"
+ >
+ Body
+ </Text>,
+ );
+
+ const text = screen.getByTestId('text');
+
+ expect(text.tagName).toBe('SPAN');
+ expect(text).toHaveClass('from-render', 'consumer');
+ });
+
+ it('places the consumer className last', () => {
+ render(
+ <Text truncate className="consumer" data-testid="text">
+ Body
+ </Text>,
+ );
+
+ expect(screen.getByTestId('text').className).toBe(
+ `${styles.truncate} consumer`,
+ );
+ });
+});
diff --git a/packages/twenty-ui/src/utilities/device/__tests__/getOsControlSymbol.test.ts b/packages/twenty-ui/src/utilities/device/__tests__/getOsControlSymbol.test.ts
index bd97e08a356..ab3cd5d1080 100644
--- a/packages/twenty-ui/src/utilities/device/__tests__/getOsControlSymbol.test.ts
+++ b/packages/twenty-ui/src/utilities/device/__tests__/getOsControlSymbol.test.ts
@@ -1,10 +1,12 @@
+import { type MockInstance, vi } from 'vitest';
+
import { getOsControlSymbol } from '../getOsControlSymbol';
describe('getOsControlSymbol', () => {
- let userAgentSpy: jest.SpyInstance;
+ let userAgentSpy: MockInstance<() => string>;
beforeEach(() => {
- userAgentSpy = jest.spyOn(window.navigator, 'userAgent', 'get');
+ userAgentSpy = vi.spyOn(window.navigator, 'userAgent', 'get');
});
afterEach(() => {
diff --git a/packages/twenty-ui/src/utilities/device/__tests__/getOsShortcutSeparator.test.ts b/packages/twenty-ui/src/utilities/device/__tests__/getOsShortcutSeparator.test.ts
index 16205be1425..60c725066aa 100644
--- a/packages/twenty-ui/src/utilities/device/__tests__/getOsShortcutSeparator.test.ts
+++ b/packages/twenty-ui/src/utilities/device/__tests__/getOsShortcutSeparator.test.ts
@@ -1,10 +1,12 @@
+import { type MockInstance, vi } from 'vitest';
+
import { getOsShortcutSeparator } from '../getOsShortcutSeparator';
describe('getOsShortcutSeparator', () => {
- let userAgentSpy: jest.SpyInstance;
+ let userAgentSpy: MockInstance<() => string>;
beforeEach(() => {
- userAgentSpy = jest.spyOn(window.navigator, 'userAgent', 'get');
+ userAgentSpy = vi.spyOn(window.navigator, 'userAgent', 'get');
});
afterEach(() => {
diff --git a/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx b/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx
new file mode 100644
index 00000000000..23edff913e4
--- /dev/null
+++ b/packages/twenty-ui/test-utilities/conformance/runComponentConformance.tsx
@@ -0,0 +1,237 @@
+import { render, screen } from '@testing-library/react';
+import {
+ cloneElement,
+ createElement,
+ createRef,
+ type HTMLAttributes,
+ type ReactElement,
+} from 'react';
+import { renderToString } from 'react-dom/server';
+import {
+ afterEach,
+ beforeEach,
+ describe,
+ expect,
+ it,
+ type MockInstance,
+ vi,
+} from 'vitest';
+
+import { ThemeProvider } from '@ui/theme-constants/ThemeProvider';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type ComponentConformanceCase } from './types/ComponentConformanceCase';
+import { type ComponentConformanceOptions } from './types/ComponentConformanceOptions';
+import { hideGlobals } from './utils/hideGlobals';
+
+const CONFORMANCE_TEST_ID = 'conformance-root';
+const CONFORMANCE_CLASS_NAME = 'conformance-consumer-class';
+const CONFORMANCE_RENDER_CLASS_NAME = 'conformance-render-class';
+const CONFORMANCE_DATA_ATTRIBUTE_VALUE = 'conformance-data-value';
+const CONFORMANCE_ARIA_LABEL = 'conformance-aria-label';
+const CONFORMANCE_STYLE = { marginTop: '7px' };
+const SERVER_HIDDEN_GLOBALS = [
+ 'window',
+ 'document',
+ 'navigator',
+ 'CSS',
+ 'Node',
+ 'Element',
+ 'HTMLElement',
+] as const;
+
+export const runComponentConformance = ({
+ name,
+ element,
+ refInstanceOf,
+ wrapper: Wrapper,
+ ownClassName,
+ renderPropTagName = 'span',
+ skip = [],
+}: ComponentConformanceOptions) => {
+ const compose = (probeProps: Record<string, unknown>): ReactElement => {
+ const probe = cloneElement(element, {
+ 'data-testid': CONFORMANCE_TEST_ID,
+ ...probeProps,
+ });
+
+ return (
+ <ThemeProvider colorScheme="light">
+ {isDefined(Wrapper) ? <Wrapper>{probe}</Wrapper> : probe}
+ </ThemeProvider>
+ );
+ };
+
+ const itUnlessSkipped = (
+ conformanceCase: ComponentConformanceCase,
+ title: string,
+ run: () => void,
+ ) => {
+ const register = skip.includes(conformanceCase) ? it.skip : it;
+
+ register(title, run);
+ };
+
+ describe(`${name} conformance`, () => {
+ let consoleErrorSpy: MockInstance;
+ let consoleWarnSpy: MockInstance;
+
+ beforeEach(() => {
+ consoleErrorSpy = vi
+ .spyOn(console, 'error')
+ .mockImplementation(() => undefined);
+ consoleWarnSpy = vi
+ .spyOn(console, 'warn')
+ .mockImplementation(() => undefined);
+ });
+
+ afterEach(() => {
+ consoleErrorSpy.mockRestore();
+ consoleWarnSpy.mockRestore();
+ });
+
+ itUnlessSkipped(
+ 'consoleErrorsAndWarnings',
+ 'renders without console errors or warnings',
+ () => {
+ render(compose({}));
+
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
+ expect(consoleWarnSpy).not.toHaveBeenCalled();
+ },
+ );
+
+ itUnlessSkipped('ref', 'forwards ref to the root DOM node', () => {
+ const ref = createRef<Element>();
+
+ render(compose({ ref }));
+
+ expect(ref.current).toBeInstanceOf(refInstanceOf);
+ expect(ref.current).toBe(screen.getByTestId(CONFORMANCE_TEST_ID));
+ });
+
+ itUnlessSkipped('dataAttributes', 'passes data attributes through', () => {
+ render(compose({ 'data-conformance': CONFORMANCE_DATA_ATTRIBUTE_VALUE }));
+
+ expect(screen.getByTestId(CONFORMANCE_TEST_ID)).toHaveAttribute(
+ 'data-conformance',
+ CONFORMANCE_DATA_ATTRIBUTE_VALUE,
+ );
+ });
+
+ itUnlessSkipped('ariaAttributes', 'passes aria attributes through', () => {
+ render(compose({ 'aria-label': CONFORMANCE_ARIA_LABEL }));
+
+ expect(screen.getByTestId(CONFORMANCE_TEST_ID)).toHaveAttribute(
+ 'aria-label',
+ CONFORMANCE_ARIA_LABEL,
+ );
+ });
+
+ itUnlessSkipped('className', 'merges the consumer className', () => {
+ render(compose({ className: CONFORMANCE_CLASS_NAME }));
+
+ const rootNode = screen.getByTestId(CONFORMANCE_TEST_ID);
+
+ expect(rootNode).toHaveClass(CONFORMANCE_CLASS_NAME);
+
+ if (isDefined(ownClassName)) {
+ expect(rootNode).toHaveClass(ownClassName);
+ }
+ });
+
+ itUnlessSkipped(
+ 'style',
+ 'applies the consumer style to the root node',
+ () => {
+ render(compose({ style: CONFORMANCE_STYLE }));
+
+ expect(screen.getByTestId(CONFORMANCE_TEST_ID)).toHaveStyle(
+ CONFORMANCE_STYLE,
+ );
+ },
+ );
+
+ itUnlessSkipped('renderProp', 'renders the element given to render', () => {
+ const ref = createRef<Element>();
+
+ render(
+ compose({
+ ref,
+ className: CONFORMANCE_CLASS_NAME,
+ render: createElement(renderPropTagName, {
+ className: CONFORMANCE_RENDER_CLASS_NAME,
+ 'data-conformance-render': CONFORMANCE_DATA_ATTRIBUTE_VALUE,
+ }),
+ }),
+ );
+
+ const rootNode = screen.getByTestId(CONFORMANCE_TEST_ID);
+
+ expect(rootNode.localName).toBe(renderPropTagName);
+ expect(rootNode).toHaveAttribute(
+ 'data-conformance-render',
+ CONFORMANCE_DATA_ATTRIBUTE_VALUE,
+ );
+ expect(rootNode).toHaveClass(
+ CONFORMANCE_CLASS_NAME,
+ CONFORMANCE_RENDER_CLASS_NAME,
+ );
+ expect(ref.current).toBe(rootNode);
+
+ if (isDefined(ownClassName)) {
+ expect(rootNode).toHaveClass(ownClassName);
+ }
+ });
+
+ itUnlessSkipped(
+ 'renderProp',
+ 'renders the element returned by the render function',
+ () => {
+ const ref = createRef<Element>();
+
+ render(
+ compose({
+ ref,
+ className: CONFORMANCE_CLASS_NAME,
+ render: (renderProps: HTMLAttributes<HTMLElement>) =>
+ createElement(renderPropTagName, {
+ ...renderProps,
+ 'data-conformance-render': CONFORMANCE_DATA_ATTRIBUTE_VALUE,
+ }),
+ }),
+ );
+
+ const rootNode = screen.getByTestId(CONFORMANCE_TEST_ID);
+
+ expect(rootNode.localName).toBe(renderPropTagName);
+ expect(rootNode).toHaveAttribute(
+ 'data-conformance-render',
+ CONFORMANCE_DATA_ATTRIBUTE_VALUE,
+ );
+ expect(rootNode).toHaveClass(CONFORMANCE_CLASS_NAME);
+ expect(ref.current).toBe(rootNode);
+ },
+ );
+
+ itUnlessSkipped('unmount', 'unmounts cleanly', () => {
+ const { unmount } = render(compose({}));
+
+ expect(() => unmount()).not.toThrow();
+ expect(screen.queryByTestId(CONFORMANCE_TEST_ID)).toBeNull();
+ });
+
+ itUnlessSkipped('serverRender', 'renders to a string without a DOM', () => {
+ const restoreGlobals = hideGlobals(SERVER_HIDDEN_GLOBALS);
+
+ try {
+ expect(() => renderToString(compose({}))).not.toThrow();
+ } finally {
+ restoreGlobals();
+ }
+
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
+ expect(consoleWarnSpy).not.toHaveBeenCalled();
+ });
+ });
+};
diff --git a/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceCase.ts b/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceCase.ts
new file mode 100644
index 00000000000..9dd6b48e344
--- /dev/null
+++ b/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceCase.ts
@@ -0,0 +1,10 @@
+export type ComponentConformanceCase =
+ | 'consoleErrorsAndWarnings'
+ | 'ref'
+ | 'dataAttributes'
+ | 'ariaAttributes'
+ | 'className'
+ | 'style'
+ | 'renderProp'
+ | 'unmount'
+ | 'serverRender';
diff --git a/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceOptions.ts b/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceOptions.ts
new file mode 100644
index 00000000000..edffe6a76e5
--- /dev/null
+++ b/packages/twenty-ui/test-utilities/conformance/types/ComponentConformanceOptions.ts
@@ -0,0 +1,18 @@
+import {
+ type ComponentType,
+ type JSX,
+ type ReactElement,
+ type ReactNode,
+} from 'react';
+
+import { type ComponentConformanceCase } from './ComponentConformanceCase';
+
+export type ComponentConformanceOptions = {
+ name: string;
+ element: ReactElement<Record<string, unknown>>;
+ refInstanceOf: new () => Element;
+ wrapper?: ComponentType<{ children: ReactNode }>;
+ ownClassName?: string;
+ renderPropTagName?: keyof JSX.IntrinsicElements;
+ skip?: ComponentConformanceCase[];
+};
diff --git a/packages/twenty-ui/test-utilities/conformance/utils/hideGlobals.ts b/packages/twenty-ui/test-utilities/conformance/utils/hideGlobals.ts
new file mode 100644
index 00000000000..07e314a6d46
--- /dev/null
+++ b/packages/twenty-ui/test-utilities/conformance/utils/hideGlobals.ts
@@ -0,0 +1,50 @@
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+type HiddenGlobal = {
+ globalName: string;
+ descriptor: PropertyDescriptor | undefined;
+};
+
+const restoreGlobal = ({ globalName, descriptor }: HiddenGlobal) => {
+ if (isDefined(descriptor)) {
+ Object.defineProperty(globalThis, globalName, descriptor);
+
+ return;
+ }
+
+ Reflect.deleteProperty(globalThis, globalName);
+};
+
+const hideGlobal = (globalName: string): HiddenGlobal => {
+ const descriptor = Object.getOwnPropertyDescriptor(globalThis, globalName);
+
+ Object.defineProperty(globalThis, globalName, {
+ configurable: true,
+ writable: true,
+ value: undefined,
+ });
+
+ return { globalName, descriptor };
+};
+
+export const hideGlobals = (globalNames: readonly string[]) => {
+ const hiddenGlobals: HiddenGlobal[] = [];
+
+ const restoreGlobals = () => {
+ for (const hiddenGlobal of [...hiddenGlobals].reverse()) {
+ restoreGlobal(hiddenGlobal);
+ }
+ };
+
+ try {
+ for (const globalName of globalNames) {
+ hiddenGlobals.push(hideGlobal(globalName));
+ }
+ } catch (error) {
+ restoreGlobals();
+
+ throw error;
+ }
+
+ return restoreGlobals;
+};
diff --git a/packages/twenty-ui/tsconfig.json b/packages/twenty-ui/tsconfig.json
index 7935e5c6a67..986ff2b32cf 100644
--- a/packages/twenty-ui/tsconfig.json
+++ b/packages/twenty-ui/tsconfig.json
@@ -9,12 +9,13 @@
"moduleResolution": "bundler",
"esModuleInterop": true,
"noEmit": true,
- "types": ["node", "jest"],
+ "types": ["node", "vitest/globals"],
"outDir": "../../.cache/tsc",
"paths": {
"@ui/*": ["./src/*"],
"@assets/*": ["./src/assets/*"],
- "@styles/*": ["./src/styles/*"]
+ "@styles/*": ["./src/styles/*"],
+ "@test-utilities/*": ["./test-utilities/*"]
}
},
"include": [
@@ -25,7 +26,9 @@
"scripts/generateThemeTokens.ts",
".storybook/*.ts",
".storybook/*.tsx",
- "jest.config.mjs",
+ "test-utilities/**/*.ts",
+ "test-utilities/**/*.tsx",
+ "vitest.config.ts",
"setupTests.ts",
"vite.config.ts"
]
diff --git a/packages/twenty-ui/vite.config.ts b/packages/twenty-ui/vite.config.ts
index cbfdc0c7710..8cdd2070b75 100644
--- a/packages/twenty-ui/vite.config.ts
+++ b/packages/twenty-ui/vite.config.ts
@@ -11,6 +11,9 @@ type Checkers = Parameters<typeof checker>[0];
import { THEME_CSS_FILE_NAME_BY_SCHEME } from './design-tokens/themeCssFileNameByScheme';
import packageJson from './package.json';
+import { isDefined } from './src/utilities/utils/isDefined';
+
+const isVitest = isDefined(process.env.VITEST);
const entries = Object.keys(packageJson.exports)
.filter((el) => !el.endsWith('.css'))
@@ -110,9 +113,10 @@ export default defineConfig(({ command }) => {
// sass-embedded). CI/build relies on the ambient src/scss-modules.d.ts.
sassDts({ esmExport: true, legacyFileFormat: true }),
dts(dtsConfig),
- checker(checkersConfig),
+ ...(isVitest ? [] : [checker(checkersConfig)]),
{
name: 'copy-theme-css',
+ apply: 'build',
closeBundle() {
const distDir = path.resolve(__dirname, 'dist');
fs.mkdirSync(distDir, { recursive: true });
diff --git a/packages/twenty-ui/vitest.config.ts b/packages/twenty-ui/vitest.config.ts
index a13517123cc..b9535a71bca 100644
--- a/packages/twenty-ui/vitest.config.ts
+++ b/packages/twenty-ui/vitest.config.ts
@@ -15,6 +15,20 @@ const dirname =
export default defineConfig({
test: {
projects: [
+ {
+ extends: './vite.config.ts',
+ test: {
+ name: 'unit',
+ environment: 'jsdom',
+ globals: true,
+ include: [
+ 'src/**/*.{test,spec}.{ts,tsx}',
+ 'design-tokens/**/*.{test,spec}.{ts,tsx}',
+ ],
+ setupFiles: ['./setupTests.ts'],
+ css: { modules: { classNameStrategy: 'non-scoped' } },
+ },
+ },
{
extends: './vite.config.ts',
plugins: [
diff --git a/yarn.lock b/yarn.lock
index f2c3387f9d3..408201e907c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -50020,12 +50020,11 @@ __metadata:
"@storybook/addon-vitest": "npm:^10.4.6"
"@storybook/react-vite": "npm:^10.4.6"
"@swc/core": "npm:^1.15.11"
- "@swc/jest": "npm:^0.2.39"
"@tabler/icons-react": "npm:^3.31.0"
"@testing-library/dom": "npm:^10.4.0"
"@testing-library/jest-dom": "npm:^6.6.3"
"@testing-library/react": "npm:^16.3.0"
- "@types/jest": "npm:^30.0.0"
+ "@testing-library/user-event": "npm:^14.6.1"
"@types/react": "npm:^19.2.0"
"@types/react-dom": "npm:^19.2.0"
"@vitejs/plugin-react-swc": "npm:^4.3.1"
@@ -50033,8 +50032,7 @@ __metadata:
clsx: "npm:^2.1.1"
esbuild: "npm:^0.28.1"
glob: "npm:^11.1.0"
- jest: "npm:29.7.0"
- jest-environment-jsdom: "npm:30.0.0-beta.3"
+ jsdom: "npm:^30.0.1"
prettier: "npm:^3.1.1"
react: "npm:^19.2.0"
react-dom: "npm:^19.2.0"
@@ -50045,7 +50043,6 @@ __metadata:
size-limit: "npm:^12.1.0"
slash: "npm:^5.1.0"
storybook-addon-pseudo-states: "npm:^10.3.3"
- ts-jest: "npm:^29.1.1"
tsx: "npm:^4.19.3"
type-fest: "npm:^4.10.1"
typescript: "npm:^5.9.3"