diff --git a/apps/demo-app/jest.config.js b/apps/demo-app/jest.config.js index 82e82ae00..518bba263 100644 --- a/apps/demo-app/jest.config.js +++ b/apps/demo-app/jest.config.js @@ -1,7 +1,7 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), coverageThreshold: { global: { branches: 0, diff --git a/apps/drive-app/jest.config.js b/apps/drive-app/jest.config.js index 82e82ae00..518bba263 100644 --- a/apps/drive-app/jest.config.js +++ b/apps/drive-app/jest.config.js @@ -1,7 +1,7 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), coverageThreshold: { global: { branches: 0, diff --git a/apps/lux-demo-app/jest.config.js b/apps/lux-demo-app/jest.config.js index 82e82ae00..518bba263 100644 --- a/apps/lux-demo-app/jest.config.js +++ b/apps/lux-demo-app/jest.config.js @@ -1,7 +1,7 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), coverageThreshold: { global: { branches: 0, diff --git a/apps/renault-demo-app/jest.config.js b/apps/renault-demo-app/jest.config.js index 82e82ae00..518bba263 100644 --- a/apps/renault-demo-app/jest.config.js +++ b/apps/renault-demo-app/jest.config.js @@ -1,7 +1,7 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), coverageThreshold: { global: { branches: 0, diff --git a/configs/jest-config/README.md b/configs/jest-config/README.md index 201ff1110..87734030b 100644 --- a/configs/jest-config/README.md +++ b/configs/jest-config/README.md @@ -12,18 +12,31 @@ yarn add -D jest @monkvision/jest-config To use the Jest config exported by this package, simply add the following line in your `jest.config.js` : ```javascript -const { CONFIG } = require('@monkvision/jest-config'); +const { base } = require('@monkvision/jest-config'); module.exports = { -...CONFIG, + ...base(), }; ``` -And replace the `CONFIG` keyword with one of the following Jest configuration available in the package : +And replace the `base` keyword with one of the following Jest configuration available in the package : | Config Name | Usage | |-------------|---------------------------------------------------| | `base` | Base configuration for any Node.Js project . | | `react` | Base configuration used for React-based projects. | + +# Tests Setup +If you are using the [@monkvision/test-utils](https://github.com/monkvision/monkjs/tree/main/configs/test-utils) +package, and you wish to enjoy Jest automocking with the provided mocks, you can use the following test set up file : + +```js +const { base } = require('@monkvision/jest-config'); + +module.exports = { + ...base(), + setupFilesAfterEnv: ['/node_modules/@monkvision/jest-config/setupTests.js'] +}; +``` diff --git a/configs/jest-config/base.js b/configs/jest-config/base.js index f6cca5404..7b4be7f9f 100644 --- a/configs/jest-config/base.js +++ b/configs/jest-config/base.js @@ -1,4 +1,6 @@ -module.exports = { +// const esModules = ['@monkvision/test-utils', 'ky'].join('|'); + +module.exports = (options) => ({ rootDir: './', roots: ['', '/../../configs/test-utils/src/__mocks__'], preset: 'ts-jest', @@ -9,6 +11,7 @@ module.exports = { collectCoverageFrom: [ 'src/**/*.ts', ], + // transformIgnorePatterns: options?.monorepo ? [] : [`node_modules/(?!${esModules})`], coverageThreshold: { global: { branches: 60, @@ -17,4 +20,4 @@ module.exports = { statements: 60, }, }, -}; +}) diff --git a/configs/jest-config/react.js b/configs/jest-config/react.js index f2dfc636c..2ccd84cef 100644 --- a/configs/jest-config/react.js +++ b/configs/jest-config/react.js @@ -1,11 +1,11 @@ const base = require('./base'); -module.exports = { - ...base, +module.exports = (options) => ({ + ...base(options), testEnvironment: 'jsdom', testMatch: ['**/test/**/*.test.{ts,tsx}'], moduleNameMapper:{ '\\.(css|less|sass|scss)$': '@monkvision/test-utils/src/__mocks__/imports/style', '\\.(gif|ttf|eot|svg)$': '@monkvision/test-utils/src/__mocks__/imports/file' }, -}; +}); diff --git a/configs/jest-config/setupTests.js b/configs/jest-config/setupTests.js new file mode 100644 index 000000000..b7a20883a --- /dev/null +++ b/configs/jest-config/setupTests.js @@ -0,0 +1,12 @@ +const fs = require('fs'); +const path = require('path'); + +const mocks = fs.readdirSync( + path.join(__dirname, '..', 'test-utils', 'src', '__mocks__'), + { recursive: true }, +).filter((name) => !name.startsWith('imports') && !name.match(/^@[^/]+$/g)) + .map((name) => name.substring(0, name.length - (name.endsWith('x') ? 4 : 3))); + +mocks.forEach((mock) => { + jest.mock(mock, () => require('@monkvision/test-utils/src/__mocks__/' + mock)); +}); diff --git a/packages/analytics/jest.config.js b/packages/analytics/jest.config.js index a171eb578..3e85f9c2f 100644 --- a/packages/analytics/jest.config.js +++ b/packages/analytics/jest.config.js @@ -1,5 +1,5 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), }; diff --git a/packages/camera-web/jest.config.js b/packages/camera-web/jest.config.js index b3f6d90f9..3e85f9c2f 100644 --- a/packages/camera-web/jest.config.js +++ b/packages/camera-web/jest.config.js @@ -1,9 +1,5 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, - // moduleNameMapper:{ - // '\\.(css|less|sass|scss)$': '/__mocks__/styleMock.js', - // '\\.(gif|ttf|eot|svg)$': '/__mocks__/fileMock.js' - // } + ...react({ monorepo: true }), }; diff --git a/packages/common-ui-web/jest.config.js b/packages/common-ui-web/jest.config.js index a171eb578..3e85f9c2f 100644 --- a/packages/common-ui-web/jest.config.js +++ b/packages/common-ui-web/jest.config.js @@ -1,5 +1,5 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), }; diff --git a/packages/common/jest.config.js b/packages/common/jest.config.js index a171eb578..3e85f9c2f 100644 --- a/packages/common/jest.config.js +++ b/packages/common/jest.config.js @@ -1,5 +1,5 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), }; diff --git a/packages/inspection-capture-web/jest.config.js b/packages/inspection-capture-web/jest.config.js index a171eb578..3e85f9c2f 100644 --- a/packages/inspection-capture-web/jest.config.js +++ b/packages/inspection-capture-web/jest.config.js @@ -1,5 +1,5 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), }; diff --git a/packages/monitoring/jest.config.js b/packages/monitoring/jest.config.js index a171eb578..3e85f9c2f 100644 --- a/packages/monitoring/jest.config.js +++ b/packages/monitoring/jest.config.js @@ -1,5 +1,5 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), }; diff --git a/packages/network/jest.config.js b/packages/network/jest.config.js index c555a0547..22d386d07 100644 --- a/packages/network/jest.config.js +++ b/packages/network/jest.config.js @@ -1,6 +1,6 @@ const { react } = require('@monkvision/jest-config'); module.exports = { - ...react, + ...react({ monorepo: true }), modulePathIgnorePatterns: ['/lib/'], }; diff --git a/packages/sentry/src/adapter.ts b/packages/sentry/src/adapter.ts index 7aab1818f..cbc2303cf 100644 --- a/packages/sentry/src/adapter.ts +++ b/packages/sentry/src/adapter.ts @@ -123,6 +123,7 @@ export class SentryMonitoringAdapter extends DebugMonitoringAdapter implements M } override setUserId(id: string): void { + console.log('Hello'); Sentry.setUser({ id }); } diff --git a/packages/sights/jest.config.js b/packages/sights/jest.config.js index 199da95a0..d5d3907f8 100644 --- a/packages/sights/jest.config.js +++ b/packages/sights/jest.config.js @@ -1,7 +1,7 @@ const { base } = require('@monkvision/jest-config'); module.exports = { - ...base, + ...base({ monorepo: true }), coveragePathIgnorePatterns: [ 'src/lib/*', ],