@equisoft/jest-utils 0.0.1-snapshot.20230613025310

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @equisoft/jest-utils
2
+
3
+ This package regroup utils to help write tests with Jest and create a standard config.
4
+
5
+ ## How to install
6
+
7
+ ```
8
+ yarn add -DE @equisoft/jest-utils
9
+ ```
10
+
11
+ ## How to use
12
+ ### Create a jest config
13
+ Create your `jest.config.js` file and import the `createJestConfig` function. The `createJestConfig` uses a deep merge that allow you to extend from the base Equisoft's config.
14
+
15
+ ```javascript
16
+ // jest.config.js
17
+
18
+ const { createJestConfig } = require('@equisoft/jest-utils');
19
+ const { pathsToModuleNameMapper } = require('ts-jest');
20
+ const { compilerOptions } = require('./tsconfig.json');
21
+
22
+ const config = {
23
+ moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths || [], { prefix: '<rootDir>/src/test' }),
24
+
25
+ roots: [
26
+ '<rootDir>/src/browser',
27
+ '<rootDir>/src/test',
28
+ ],
29
+ setupFilesAfterEnv: [
30
+ 'jest-extended',
31
+ './src/test/setup-tests.ts',
32
+ ],
33
+
34
+ collectCoverageFrom: ['<rootDir>/src/browser/**/*.{js,jsx,ts,tsx}'],
35
+
36
+ transform: {
37
+ '^.+.m?[t]sx?$': ['ts-jest', {
38
+ tsconfig: 'src/test/tsconfig.json',
39
+ babelConfig: {
40
+ presets: [
41
+ ['@babel/preset-env', { targets: { node: 'current' } }],
42
+ '@babel/preset-react',
43
+ ],
44
+ plugins: [
45
+ '@babel/plugin-transform-react-display-name',
46
+ ['babel-plugin-styled-components', { fileName: false }],
47
+ ],
48
+ },
49
+ },
50
+ ],
51
+ },
52
+ };
53
+
54
+ module.exports = createJestConfig(config);
55
+ ```
@@ -0,0 +1,2 @@
1
+ import { NewPlugin } from 'pretty-format';
2
+ export declare const tsMockitoSerializer: NewPlugin;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsMockitoSerializer = void 0;
4
+ exports.tsMockitoSerializer = {
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ test(arg) {
7
+ // eslint-disable-next-line no-underscore-dangle
8
+ return !!(arg && arg._isMockFunction && !('_isMockFunction' in arg));
9
+ },
10
+ serialize() {
11
+ return 'MockedInstance';
12
+ },
13
+ };
@@ -0,0 +1,2 @@
1
+ import type { Config } from '@jest/types';
2
+ export declare function createJestConfig(config: Partial<Config.InitialOptions>): Config.InitialOptions;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createJestConfig = void 0;
4
+ function isObject(obj) {
5
+ return obj !== null && obj !== undefined && typeof obj === 'object';
6
+ }
7
+ /* eslint-disable no-param-reassign */
8
+ function mergeDeep(...objects) {
9
+ return objects.reduce((prev, obj) => {
10
+ Object.keys(obj).forEach((key) => {
11
+ const previousValue = prev[key];
12
+ const otherValue = obj[key];
13
+ if (Array.isArray(previousValue) && Array.isArray(otherValue)) {
14
+ prev[key] = previousValue.concat(...otherValue);
15
+ }
16
+ else if (isObject(previousValue) && isObject(otherValue)) {
17
+ prev[key] = mergeDeep(previousValue, otherValue);
18
+ }
19
+ else {
20
+ prev[key] = otherValue;
21
+ }
22
+ });
23
+ return prev;
24
+ }, {});
25
+ }
26
+ function createJestConfig(config) {
27
+ return Object.assign({}, mergeDeep({
28
+ clearMocks: true,
29
+ errorOnDeprecated: true,
30
+ collectCoverage: true,
31
+ coverageDirectory: '<rootDir>/build/jest/coverage',
32
+ coveragePathIgnorePatterns: [
33
+ '/index\\.[jt]sx?$',
34
+ '.+\\.d\\.ts$',
35
+ ],
36
+ coverageProvider: 'v8',
37
+ coverageReporters: [
38
+ // Supported reporters: https://istanbul.js.org/docs/advanced/alternative-reporters/
39
+ 'text',
40
+ 'html',
41
+ 'clover', // ADR-05
42
+ ],
43
+ extensionsToTreatAsEsm: ['.jsx', '.ts', '.tsx'],
44
+ reporters: [
45
+ 'default',
46
+ [
47
+ 'jest-junit',
48
+ {
49
+ outputDirectory: 'build/jest/',
50
+ outputName: 'junit.xml',
51
+ suiteNameTemplate: '{filepath}',
52
+ classNameTemplate: '{classname}',
53
+ titleTemplate: '{title}',
54
+ },
55
+ ],
56
+ ],
57
+ resetMocks: true,
58
+ snapshotSerializers: [require.resolve('@equisoft/jest-utils/serializer')],
59
+ testEnvironment: 'jsdom',
60
+ transformIgnorePatterns: [],
61
+ }, config));
62
+ }
63
+ exports.createJestConfig = createJestConfig;
@@ -0,0 +1,5 @@
1
+ import { createJestConfig } from './config/createJestConfig';
2
+ declare const _default: {
3
+ createJestConfig: typeof createJestConfig;
4
+ };
5
+ export = _default;
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ const createJestConfig_1 = require("./config/createJestConfig");
3
+ module.exports = {
4
+ createJestConfig: createJestConfig_1.createJestConfig,
5
+ };
@@ -0,0 +1,2 @@
1
+ import { tsMockitoSerializer } from './TsMockitoSerializer';
2
+ export = tsMockitoSerializer;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ const TsMockitoSerializer_1 = require("./TsMockitoSerializer");
3
+ module.exports = TsMockitoSerializer_1.tsMockitoSerializer;
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@equisoft/jest-utils",
3
+ "version": "0.0.1-snapshot.20230613025310",
4
+ "dependencies": {
5
+ "pretty-format": "29.5.0"
6
+ },
7
+ "devDependencies": {
8
+ "@equisoft/eslint-config-typescript": "3.0.3",
9
+ "@equisoft/typescript-config": "2.0.0",
10
+ "@jest/types": "29.5.0",
11
+ "@microsoft/eslint-formatter-sarif": "3.0.0",
12
+ "@types/node": "18.11.9",
13
+ "@typescript-eslint/eslint-plugin": "5.59.11",
14
+ "@typescript-eslint/parser": "5.59.11",
15
+ "eslint": "8.40.0",
16
+ "eslint-import-resolver-node": "0.3.7",
17
+ "eslint-import-resolver-typescript": "3.5.5",
18
+ "eslint-plugin-import": "2.27.5",
19
+ "globby": "13.1.4",
20
+ "ts-jest": "29.1.0",
21
+ "typescript": "5.0.4",
22
+ "yargs": "17.7.2"
23
+ },
24
+ "exports": {
25
+ ".": "./dist/index.js",
26
+ "./serializer": "./dist/serializer.js",
27
+ "./serializer.js": "./dist/serializer.js"
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "peerDependencies": {
33
+ "jest-junit": "*",
34
+ "ts-jest": "*"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "eslint": "eslint src",
39
+ "eslint:ci": "yarn eslint"
40
+ }
41
+ }