Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated jest configs to allow external developments #830

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/demo-app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
coverageThreshold: {
global: {
branches: 0,
Expand Down
2 changes: 1 addition & 1 deletion apps/drive-app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
coverageThreshold: {
global: {
branches: 0,
Expand Down
2 changes: 1 addition & 1 deletion apps/lux-demo-app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
coverageThreshold: {
global: {
branches: 0,
Expand Down
2 changes: 1 addition & 1 deletion apps/renault-demo-app/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
coverageThreshold: {
global: {
branches: 0,
Expand Down
19 changes: 16 additions & 3 deletions configs/jest-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: ['<rootDir>/node_modules/@monkvision/jest-config/setupTests.js']
};
```
7 changes: 5 additions & 2 deletions configs/jest-config/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
// const esModules = ['@monkvision/test-utils', 'ky'].join('|');

module.exports = (options) => ({
rootDir: './',
roots: ['<rootDir>', '<rootDir>/../../configs/test-utils/src/__mocks__'],
preset: 'ts-jest',
Expand All @@ -9,6 +11,7 @@ module.exports = {
collectCoverageFrom: [
'src/**/*.ts',
],
// transformIgnorePatterns: options?.monorepo ? [] : [`node_modules/(?!${esModules})`],
coverageThreshold: {
global: {
branches: 60,
Expand All @@ -17,4 +20,4 @@ module.exports = {
statements: 60,
},
},
};
})
6 changes: 3 additions & 3 deletions configs/jest-config/react.js
Original file line number Diff line number Diff line change
@@ -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'
},
};
});
12 changes: 12 additions & 0 deletions configs/jest-config/setupTests.js
Original file line number Diff line number Diff line change
@@ -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));
});
2 changes: 1 addition & 1 deletion packages/analytics/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
};
6 changes: 1 addition & 5 deletions packages/camera-web/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
// moduleNameMapper:{
// '\\.(css|less|sass|scss)$': '<rootDir>/__mocks__/styleMock.js',
// '\\.(gif|ttf|eot|svg)$': '<rootDir>/__mocks__/fileMock.js'
// }
...react({ monorepo: true }),
};
2 changes: 1 addition & 1 deletion packages/common-ui-web/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
};
2 changes: 1 addition & 1 deletion packages/common/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
};
2 changes: 1 addition & 1 deletion packages/inspection-capture-web/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
};
2 changes: 1 addition & 1 deletion packages/monitoring/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
};
2 changes: 1 addition & 1 deletion packages/network/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { react } = require('@monkvision/jest-config');

module.exports = {
...react,
...react({ monorepo: true }),
modulePathIgnorePatterns: ['<rootDir>/lib/'],
};
1 change: 1 addition & 0 deletions packages/sentry/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class SentryMonitoringAdapter extends DebugMonitoringAdapter implements M
}

override setUserId(id: string): void {
console.log('Hello');
Sentry.setUser({ id });
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sights/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { base } = require('@monkvision/jest-config');

module.exports = {
...base,
...base({ monorepo: true }),
coveragePathIgnorePatterns: [
'src/lib/*',
],
Expand Down