2024-04-04 16:38:01 +03:00
|
|
|
import { JestConfigWithTsJest, pathsToModuleNameMapper } from 'ts-jest';
|
|
|
|
|
2024-04-17 19:06:02 +03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
const tsConfig = require('./tsconfig.json');
|
2024-04-04 16:38:01 +03:00
|
|
|
|
|
|
|
const jestConfig: JestConfigWithTsJest = {
|
2024-03-05 19:43:31 +03:00
|
|
|
// to enable logs, comment out the following line
|
|
|
|
silent: true,
|
2024-04-04 16:38:01 +03:00
|
|
|
displayName: 'twenty-front',
|
|
|
|
preset: '../../jest.preset.js',
|
|
|
|
setupFilesAfterEnv: ['./setupTests.ts'],
|
2024-01-11 10:51:36 +03:00
|
|
|
testEnvironment: 'jsdom',
|
2024-04-04 16:38:01 +03:00
|
|
|
transformIgnorePatterns: ['../../node_modules/'],
|
2023-12-10 18:22:43 +03:00
|
|
|
transform: {
|
2024-01-11 10:51:36 +03:00
|
|
|
'^.+\\.(ts|js|tsx|jsx)$': '@swc/jest',
|
2023-12-10 18:22:43 +03:00
|
|
|
},
|
|
|
|
moduleNameMapper: {
|
2024-01-12 20:05:56 +03:00
|
|
|
'\\.(jpg|jpeg|png|gif|webp|svg|svg\\?react)$':
|
|
|
|
'<rootDir>/__mocks__/imageMock.js',
|
2024-03-31 11:53:37 +03:00
|
|
|
'\\.css$': '<rootDir>/__mocks__/styleMock.js',
|
2024-04-17 19:06:02 +03:00
|
|
|
...pathsToModuleNameMapper(tsConfig.compilerOptions.paths),
|
2023-12-10 18:22:43 +03:00
|
|
|
},
|
2024-04-04 16:38:01 +03:00
|
|
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
2023-12-10 18:22:43 +03:00
|
|
|
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
2023-12-14 22:08:03 +03:00
|
|
|
coverageThreshold: {
|
|
|
|
global: {
|
2024-07-17 15:52:17 +03:00
|
|
|
statements: 64,
|
|
|
|
lines: 63,
|
Feat/put target object identifier on use activities (#4682)
When writing to the normalized cache (record), it's crucial to use _refs
for relationships to avoid many problems. Essentially, we only deal with
level 0 and generate all fields to be comfortable with their defaults.
When writing in queries (which should be very rare, the only cases are
prefetch and the case of activities due to the nested query; I've
reduced this to a single file for activities
usePrepareFindManyActivitiesQuery 🙂), it's important to use queryFields
to avoid bugs. I've implemented them on the side of query generation and
record generation.
When doing an updateOne / createOne, etc., it's necessary to distinguish
between optimistic writing (which we actually want to do with _refs) and
the server response without refs. This allows for a clean write in the
optimistic cache without worrying about nesting (as the first point).
To simplify the whole activities part, write to the normalized cache
first. Then, base queries on it in an idempotent manner. This way,
there's no need to worry about the current page or action. The
normalized cache is up-to-date, so I update the queries. Same idea as
for optimisticEffects, actually.
Finally, I've triggered optimisticEffects rather than the manual update
of many queries.
---------
Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
2024-04-01 14:12:37 +03:00
|
|
|
functions: 55,
|
2023-12-14 22:08:03 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
|
|
|
|
coveragePathIgnorePatterns: [
|
|
|
|
'states/.+State.ts$',
|
2024-01-11 10:51:36 +03:00
|
|
|
'states/selectors/*',
|
2023-12-14 22:08:03 +03:00
|
|
|
'contexts/.+Context.ts',
|
|
|
|
'testing/*',
|
|
|
|
'tests/*',
|
|
|
|
'config/*',
|
|
|
|
'graphql/queries/*',
|
|
|
|
'graphql/mutations/*',
|
|
|
|
'graphql/fragments/*',
|
|
|
|
'types/*',
|
|
|
|
'constants/*',
|
|
|
|
'generated-metadata/*',
|
|
|
|
'generated/*',
|
|
|
|
'__stories__/*',
|
2024-01-11 10:51:36 +03:00
|
|
|
'display/icon/index.ts',
|
2023-12-14 22:08:03 +03:00
|
|
|
],
|
2024-04-04 16:38:01 +03:00
|
|
|
coverageDirectory: './coverage',
|
2024-01-11 10:51:36 +03:00
|
|
|
};
|
2024-04-04 16:38:01 +03:00
|
|
|
|
|
|
|
export default jestConfig;
|