diff --git a/package.json b/package.json index 435f7168ee19..ce0115383e62 100644 --- a/package.json +++ b/package.json @@ -249,7 +249,6 @@ "@types/express": "^4.17.13", "@types/graphql-fields": "^1.3.6", "@types/graphql-upload": "^8.0.12", - "@types/jest": "^29.5.11", "@types/js-cookie": "^3.0.3", "@types/js-levenshtein": "^1.1.3", "@types/lodash.camelcase": "^4.3.7", diff --git a/packages/twenty-shared/jest.config.ts b/packages/twenty-shared/jest.config.ts new file mode 100644 index 000000000000..b285ca26e733 --- /dev/null +++ b/packages/twenty-shared/jest.config.ts @@ -0,0 +1,32 @@ +import { JestConfigWithTsJest, pathsToModuleNameMapper } from 'ts-jest'; + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const tsConfig = require('./tsconfig.json'); + +const jestConfig: JestConfigWithTsJest = { + displayName: 'twenty-ui', + preset: '../../jest.preset.js', + testEnvironment: 'jsdom', + transformIgnorePatterns: ['../../node_modules/'], + transform: { + '^.+\\.[tj]sx?$': [ + '@swc/jest', + { + jsc: { + parser: { syntax: 'typescript', tsx: true }, + transform: { react: { runtime: 'automatic' } }, + }, + }, + ], + }, + moduleNameMapper: { + '\\.(jpg|jpeg|png|gif|webp|svg|svg\\?react)$': + '/__mocks__/imageMock.js', + ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths), + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + extensionsToTreatAsEsm: ['.ts', '.tsx'], + coverageDirectory: './coverage', +}; + +export default jestConfig; diff --git a/packages/twenty-shared/package.json b/packages/twenty-shared/package.json index 8b5ff2e6bb59..8f6d615d972d 100644 --- a/packages/twenty-shared/package.json +++ b/packages/twenty-shared/package.json @@ -1,9 +1,6 @@ { "name": "twenty-shared", "version": "0.40.0-canary", - "description": "", - "author": "", - "private": true, "license": "AGPL-3.0", "main": "./dist/index.js", "scripts": { diff --git a/packages/twenty-shared/project.json b/packages/twenty-shared/project.json index a7d7c1aa262b..4d303e7a6d96 100644 --- a/packages/twenty-shared/project.json +++ b/packages/twenty-shared/project.json @@ -1,6 +1,7 @@ { "name": "twenty-shared", "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "packages/twenty-shared/src", "projectType": "library", "tags": ["scope:shared"], "targets": { @@ -11,6 +12,7 @@ } }, "typecheck": {}, + "test": {}, "lint": { "options": { "lintFilePatterns": [ diff --git a/packages/twenty-shared/src/utils/image/__tests__/getImageAbsoluteURI.test.ts b/packages/twenty-shared/src/utils/image/__tests__/getImageAbsoluteURI.test.ts index 8fba851a15fa..b617a41164f1 100644 --- a/packages/twenty-shared/src/utils/image/__tests__/getImageAbsoluteURI.test.ts +++ b/packages/twenty-shared/src/utils/image/__tests__/getImageAbsoluteURI.test.ts @@ -1,18 +1,11 @@ import { getImageAbsoluteURI } from '../getImageAbsoluteURI'; describe('getImageAbsoluteURI', () => { - it('should return null if imageUrl is empty', () => { + it('should return baseUrl if imageUrl is empty string', () => { const imageUrl = ''; const baseUrl = 'http://localhost:3000'; const result = getImageAbsoluteURI({ imageUrl, baseUrl }); - expect(result).toBeNull(); - }); - - it('should return null if baseUrl is empty', () => { - const imageUrl = 'https://XXX'; - const baseUrl = ''; - const result = getImageAbsoluteURI({ imageUrl, baseUrl }); - expect(result).toBeNull(); + expect(result).toBe('http://localhost:3000/files/'); }); it('should return absolute url if the imageUrl is an absolute url', () => { @@ -22,24 +15,24 @@ describe('getImageAbsoluteURI', () => { expect(result).toBe(imageUrl); }); - it('should return fully formed url if imageUrl is a url', () => { - const imageUrl = 'pic.png?token=XXX'; + it('should return fully formed url if imageUrl is a relative url starting with /', () => { + const imageUrl = '/path/pic.png'; const baseUrl = 'http://localhost:3000'; const result = getImageAbsoluteURI({ imageUrl, baseUrl }); - expect(result).toBe('http://localhost:3000/files/pic.png?token=XXX'); + expect(result).toBe('http://localhost:3000/files/path/pic.png'); }); - it('should return fully formed url if imageUrl is a relative url', () => { - const imageUrl = '/pic.png?token=XXX'; + it('should return fully formed url if imageUrl is a relative url nost starting with slash', () => { + const imageUrl = 'pic.png'; const baseUrl = 'http://localhost:3000'; const result = getImageAbsoluteURI({ imageUrl, baseUrl }); - expect(result).toBe('http://localhost:3000/files/pic.png?token=XXX'); + expect(result).toBe('http://localhost:3000/files/pic.png'); }); - it('should return null if imageUrl is an empty string', () => { - const imageUrl = ''; + it('should handle queryParameters in the imageUrl', () => { + const imageUrl = '/pic.png?token=XXX'; const baseUrl = 'http://localhost:3000'; const result = getImageAbsoluteURI({ imageUrl, baseUrl }); - expect(result).toBeNull(); + expect(result).toBe('http://localhost:3000/files/pic.png?token=XXX'); }); }); diff --git a/packages/twenty-shared/src/utils/image/getImageAbsoluteURI.ts b/packages/twenty-shared/src/utils/image/getImageAbsoluteURI.ts index 782bf35f0537..8f041a4e4c8e 100644 --- a/packages/twenty-shared/src/utils/image/getImageAbsoluteURI.ts +++ b/packages/twenty-shared/src/utils/image/getImageAbsoluteURI.ts @@ -11,14 +11,9 @@ export const getImageAbsoluteURI = ({ return imageUrl; } - const absoluteImageUrl = new URL(baseUrl); - if (imageUrl.startsWith('/')) { - absoluteImageUrl.pathname = `/files${imageUrl}`; - return absoluteImageUrl.toString(); + return new URL(`/files${imageUrl}`, baseUrl).toString(); } - absoluteImageUrl.pathname = `files/${imageUrl}`; - - return absoluteImageUrl.toString(); + return new URL(`/files/${imageUrl}`, baseUrl).toString(); }; diff --git a/packages/twenty-shared/tsconfig.json b/packages/twenty-shared/tsconfig.json index 9e5a7fa526d2..bf6a9dfeb968 100644 --- a/packages/twenty-shared/tsconfig.json +++ b/packages/twenty-shared/tsconfig.json @@ -18,7 +18,7 @@ }, { "path": "./tsconfig.spec.json" - }, + } ], "extends": "../../tsconfig.base.json" } diff --git a/packages/twenty-shared/tsconfig.spec.json b/packages/twenty-shared/tsconfig.spec.json index 7b115f8bbc82..9f928c13c27f 100644 --- a/packages/twenty-shared/tsconfig.spec.json +++ b/packages/twenty-shared/tsconfig.spec.json @@ -1,19 +1,17 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "module": "commonjs", "types": ["jest", "node"] }, "include": [ "**/__mocks__/**/*", "jest.config.ts", - "setupTests.ts", "src/**/*.d.ts", "src/**/*.spec.ts", "src/**/*.spec.tsx", "src/**/*.test.ts", "src/**/*.test.tsx", - "tsup.config.ts", - "tsup.ui.index.tsx", "vite.config.ts" ] } diff --git a/yarn.lock b/yarn.lock index 4df7d8ce4158..a280e481126d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15925,16 +15925,6 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:^29.5.11": - version: 29.5.12 - resolution: "@types/jest@npm:29.5.12" - dependencies: - expect: "npm:^29.0.0" - pretty-format: "npm:^29.0.0" - checksum: 10c0/25fc8e4c611fa6c4421e631432e9f0a6865a8cb07c9815ec9ac90d630271cad773b2ee5fe08066f7b95bebd18bb967f8ce05d018ee9ab0430f9dfd1d84665b6f - languageName: node - linkType: hard - "@types/js-cookie@npm:^2.2.6": version: 2.2.7 resolution: "@types/js-cookie@npm:2.2.7" @@ -26153,7 +26143,7 @@ __metadata: languageName: node linkType: hard -"expect@npm:^29.0.0, expect@npm:^29.7.0": +"expect@npm:^29.7.0": version: 29.7.0 resolution: "expect@npm:29.7.0" dependencies: @@ -38284,7 +38274,7 @@ __metadata: languageName: node linkType: hard -"pretty-format@npm:^29.0.0, pretty-format@npm:^29.5.0, pretty-format@npm:^29.7.0": +"pretty-format@npm:^29.5.0, pretty-format@npm:^29.7.0": version: 29.7.0 resolution: "pretty-format@npm:29.7.0" dependencies: @@ -44173,7 +44163,6 @@ __metadata: "@types/facepaint": "npm:^1.2.5" "@types/graphql-fields": "npm:^1.3.6" "@types/graphql-upload": "npm:^8.0.12" - "@types/jest": "npm:^29.5.11" "@types/js-cookie": "npm:^3.0.3" "@types/js-levenshtein": "npm:^1.1.3" "@types/lodash.camelcase": "npm:^4.3.7"