@nest-yalc-2/jest-config 2.0.0 → 2.2.0

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.
Files changed (46) hide show
  1. package/package.json +9 -18
  2. package/LICENSE +0 -661
  3. package/src/CHANGELOG.md +0 -8
  4. package/src/README.md +0 -31
  5. package/src/config/CHANGELOG.md +0 -8
  6. package/src/config/README.md +0 -31
  7. package/src/config/gql-plugin.js +0 -25
  8. package/src/config/index.d.ts +0 -2
  9. package/src/config/index.js +0 -6
  10. package/src/config/index.js.map +0 -1
  11. package/src/config/index.ts +0 -2
  12. package/src/config/jest-conf.generator.d.ts +0 -53
  13. package/src/config/jest-conf.generator.js +0 -193
  14. package/src/config/jest-conf.generator.js.map +0 -1
  15. package/src/config/jest-conf.generator.ts +0 -368
  16. package/src/config/jest-def.config.d.ts +0 -20
  17. package/src/config/jest-def.config.js +0 -140
  18. package/src/config/jest-def.config.js.map +0 -1
  19. package/src/config/jest-def.config.ts +0 -210
  20. package/src/config/jest.setup.d.ts +0 -0
  21. package/src/config/jest.setup.js +0 -9
  22. package/src/config/jest.setup.js.map +0 -1
  23. package/src/config/jest.setup.ts +0 -39
  24. package/src/config/package.json +0 -22
  25. package/src/config/tsconfig.dev.json +0 -3
  26. package/src/config/tsconfig.json +0 -9
  27. package/src/gql-plugin.js +0 -25
  28. package/src/index.d.ts +0 -2
  29. package/src/index.js +0 -6
  30. package/src/index.js.map +0 -1
  31. package/src/index.ts +0 -2
  32. package/src/jest-conf.generator.d.ts +0 -53
  33. package/src/jest-conf.generator.js +0 -193
  34. package/src/jest-conf.generator.js.map +0 -1
  35. package/src/jest-conf.generator.ts +0 -363
  36. package/src/jest-def.config.d.ts +0 -20
  37. package/src/jest-def.config.js +0 -146
  38. package/src/jest-def.config.js.map +0 -1
  39. package/src/jest-def.config.ts +0 -216
  40. package/src/jest.setup.d.ts +0 -0
  41. package/src/jest.setup.js +0 -25
  42. package/src/jest.setup.js.map +0 -1
  43. package/src/jest.setup.ts +0 -58
  44. package/src/package.json +0 -22
  45. package/src/tsconfig.dev.json +0 -3
  46. package/src/tsconfig.json +0 -9
@@ -1,216 +0,0 @@
1
- /* istanbul ignore file */
2
-
3
- import * as path from 'path';
4
- import * as readTsConfig from 'get-tsconfig';
5
- import { pathsToModuleNameMapper } from 'ts-jest';
6
- import { defaults } from 'jest-config';
7
- import type { JestConfigWithTsJest } from 'ts-jest';
8
-
9
- export const coveragePathIgnorePatterns = [
10
- '/env/dist/',
11
- '/node_modules/',
12
- '/database/seeds/',
13
- '/database/migrations/',
14
- '/test/feature/',
15
- ];
16
-
17
- export const globals = () => {
18
- return {
19
- __JEST_DISABLE_DB: true,
20
- };
21
- };
22
-
23
- export const tsJestConfigE2E = (
24
- tsConfPath = '',
25
- withGqlPlugin = true,
26
- overrideTsJestConfig?: any,
27
- ) => {
28
- const tsConfigFile = readTsConfig.getTsconfig(path.resolve(tsConfPath));
29
- const { tsconfig, ...restTsJest } = overrideTsJestConfig ?? {};
30
-
31
- const conf: any = {
32
- diagnostics: false,
33
- tsconfig: {
34
- ...(tsConfigFile?.config.compilerOptions ?? {}),
35
- ...(tsconfig ?? {}),
36
- },
37
- ...restTsJest,
38
- };
39
-
40
- if (withGqlPlugin) {
41
- conf.astTransformers = {
42
- before: [path.join(__dirname, 'gql-plugin.js')],
43
- };
44
- }
45
-
46
- return conf;
47
- };
48
-
49
- export const tsJestConfig = (tsConfPath = '', overrideTsJestConfig?: any) => {
50
- const tsConfigFile = readTsConfig.getTsconfig(
51
- path.resolve(path.dirname(tsConfPath)),
52
- path.basename(tsConfPath),
53
- );
54
-
55
- if (tsConfigFile?.path && path.resolve(tsConfigFile.path) !== path.resolve(tsConfPath)) {
56
- throw new Error(`Cannot find ${tsConfPath}`);
57
- }
58
-
59
- const { tsconfig, ...restTsJest } = overrideTsJestConfig ?? {};
60
-
61
- const config = {
62
- tsconfig: {
63
- ...(tsConfigFile?.config.compilerOptions ?? {}),
64
- ...(tsconfig ?? {}),
65
- importHelpers: true,
66
- },
67
- diagnostics: false,
68
- ...restTsJest,
69
- };
70
-
71
- return config;
72
- };
73
-
74
- export const coverageThreshold = (
75
- projects: any[] = [],
76
- defaultCoverageThreshold = {
77
- branches: 100,
78
- functions: 100,
79
- lines: 100,
80
- statements: 100,
81
- },
82
- ) => {
83
- const coverage: Record<string, any> = {
84
- global: {
85
- ...defaultCoverageThreshold,
86
- },
87
- };
88
-
89
- projects.map((project) => {
90
- // /**
91
- // * @todo should be removed and be set to 100% asap
92
- // */
93
- // switch (project.name) {
94
- // case 'unit/common/crud-gen':
95
- // branches = 92.27;
96
- // functions = 98.92;
97
- // lines = 98.75;
98
- // statements = 98.5;
99
- // break;
100
- // default:
101
- // branches = 100;
102
- // break;
103
- // }
104
-
105
- coverage[project.rootDir] = {
106
- ...defaultCoverageThreshold,
107
- };
108
-
109
- if (project?.coverageThreshold) {
110
- coverage[project.rootDir] = {
111
- ...coverage[project.rootDir],
112
- ...project?.coverageThreshold,
113
- };
114
- }
115
- });
116
-
117
- return coverage;
118
- };
119
-
120
- export interface IDefaultConfOptions {
121
- /** node modules to transform
122
- * string array -> add extra esmodule to transform
123
- * true -> transform esmodule only using the default array
124
- * false -> disable esmodule transformation (default)
125
- */
126
- transformEsModules?: string[] | boolean;
127
- tsJestConf?: any;
128
- jestConf?: any;
129
- }
130
-
131
- /**
132
- * for both unit and e2e
133
- * @param dirname
134
- * @returns
135
- */
136
- const defaultConf = (
137
- dirname: string,
138
- options: IDefaultConfOptions = {},
139
- _tsJestConfig: any = {},
140
- ): JestConfigWithTsJest => {
141
- const tsConfigFile = readTsConfig.getTsconfig(
142
- path.join(dirname, 'tsconfig.json'),
143
- );
144
- const compilerOptions = tsConfigFile?.config.compilerOptions ?? {};
145
-
146
- // We need this to make sure that some esm modules are transformed
147
- // ref: https://github.com/nrwl/nx/issues/812
148
- // ref: https://github.com/jaredpalmer/tsdx/issues/187#issuecomment-825536863
149
-
150
- const config: JestConfigWithTsJest = {
151
- rootDir: dirname,
152
- modulePathIgnorePatterns: [
153
- '<rootDir>/var/',
154
- '<rootDir>/env/',
155
- '<rootDir>/docs/',
156
- '<rootDir>/dist/',
157
- '<rootDir>/../dist/',
158
- '<rootDir>/node_modules/',
159
- '.*/dist/',
160
- ],
161
- preset: 'ts-jest/presets/default-esm',
162
- testEnvironment: 'node',
163
- moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts'], // add typescript to the default options
164
- testRegex: '.*\\.spec\\.ts$',
165
- transform: {
166
- '^.+\\.(t|j)sx?$': [
167
- 'ts-jest',
168
- {
169
- useESM: true,
170
- tsconfig: {
171
- ...compilerOptions,
172
- importHelpers: true,
173
- },
174
- ..._tsJestConfig,
175
- },
176
- ],
177
- },
178
- moduleNameMapper: {
179
- // this fixes the issue with wrong line numbers in stack traces,
180
- /** @see https://github.com/kulshekhar/ts-jest/issues/727 */
181
- 'source-map-support/register': 'identity-obj-proxy',
182
- // for ESM support
183
- '^(\\.{1,2}/.*)\\.js$': '$1.ts',
184
- ...pathsToModuleNameMapper(compilerOptions.paths ?? {}, {
185
- prefix: `${dirname}/`,
186
- useESM: true,
187
- }),
188
- },
189
- errorOnDeprecated: true,
190
- extensionsToTreatAsEsm: ['.ts'],
191
- // injectGlobals: false,
192
- ...options?.jestConf,
193
- };
194
-
195
- if (options.transformEsModules) {
196
- const esModules = [
197
- ...(Array.isArray(options.transformEsModules)
198
- ? options.transformEsModules
199
- : []),
200
- 'aggregate-error',
201
- 'clean-stack',
202
- 'escape-string-regexp',
203
- 'indent-string',
204
- 'p-map',
205
- 'lodash-es',
206
- ].join('|');
207
-
208
- config.transformIgnorePatterns = [
209
- `[/\\\\]node_modules[/\\\\](?!${esModules}).+\\.(js|jsx)$`,
210
- ];
211
- }
212
-
213
- return config;
214
- };
215
-
216
- export default defaultConf;
File without changes
package/src/jest.setup.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- process.env.NODE_ENV = 'test';
3
- if (!process.env.LISTENING_TO_UNHANDLED_REJECTION) {
4
- process.on('unhandledRejection', (err) => {
5
- throw err;
6
- });
7
- process.env.LISTENING_TO_UNHANDLED_REJECTION = 'true';
8
- }
9
- jest.mock('@nestjs/graphql', () => {
10
- const actual = jest.requireActual('@nestjs/graphql');
11
- const mockedModule = Object.assign({}, actual);
12
- const decorators = [
13
- 'Args', 'Field', 'Query', 'Mutation', 'Resolver', 'InputType', 'ObjectType',
14
- 'InterfaceType', 'ResolveField', 'HideField', 'Directive', 'registerEnumType', 'IntersectionType'
15
- ];
16
- for (const name of decorators) {
17
- if (actual[name]) {
18
- mockedModule[name] = jest.fn().mockImplementation((...args) => {
19
- return actual[name](...args);
20
- });
21
- }
22
- }
23
- return mockedModule;
24
- });
25
- //# sourceMappingURL=jest.setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jest.setup.js","sourceRoot":"","sources":["jest.setup.ts"],"names":[],"mappings":";AAGA,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC;AAI9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,EAAE,CAAC;IAClD,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,GAAG,EAAE,EAAE;QACvC,MAAM,GAAG,CAAC;IACZ,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,gCAAgC,GAAG,MAAM,CAAC;AACxD,CAAC;AA6BD,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAChC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACrD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG;QACjB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY;QAC3E,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,kBAAkB;KAClG,CAAC;IACF,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACjB,YAAY,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE;gBAC5D,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC,CAAC"}
package/src/jest.setup.ts DELETED
@@ -1,58 +0,0 @@
1
- /// <reference types="jest" />
2
- /* istanbul ignore file */
3
-
4
- process.env.NODE_ENV = 'test';
5
-
6
- // without this, jest won't fail with unhandled promises
7
- // (e.g. missing awaits)
8
- if (!process.env.LISTENING_TO_UNHANDLED_REJECTION) {
9
- process.on('unhandledRejection', (err) => {
10
- throw err;
11
- });
12
- // Avoid memory leak by adding too many listeners
13
- process.env.LISTENING_TO_UNHANDLED_REJECTION = 'true';
14
- }
15
-
16
- // try {
17
- // jest.unstable_mockModule('@nestjs/graphql', () => {
18
- // class Fake {}
19
- // return {
20
- // ...jest.requireActual<any>('@nestjs/graphql'),
21
- // InputType: () => jest.fn(),
22
- // OmitType: () => Fake,
23
- // PickType: () => Fake,
24
- // PartialType: () => Fake,
25
- // IntersectionType: () => Fake,
26
- // };
27
- // });
28
- // // eslint-disable-next-line no-console
29
- // console.debug('Mocked @nestjs/graphql');
30
- // } catch (e) {
31
- // // eslint-disable-next-line no-console
32
- // console.debug("Can't mock @nestjs/graphql. Not installed?");
33
- // }
34
-
35
- // jest.mock('@nestjs/common', () => {
36
- // return {
37
- // ...jest.requireActual<any>('@nestjs/common'),
38
- // Injectable: () => jest.fn(),
39
- // };
40
- // });
41
-
42
-
43
- jest.mock('@nestjs/graphql', () => {
44
- const actual = jest.requireActual('@nestjs/graphql');
45
- const mockedModule = Object.assign({}, actual);
46
- const decorators = [
47
- 'Args', 'Field', 'Query', 'Mutation', 'Resolver', 'InputType', 'ObjectType',
48
- 'InterfaceType', 'ResolveField', 'HideField', 'Directive', 'registerEnumType', 'IntersectionType'
49
- ];
50
- for (const name of decorators) {
51
- if (actual[name]) {
52
- mockedModule[name] = jest.fn().mockImplementation((...args) => {
53
- return actual[name](...args);
54
- });
55
- }
56
- }
57
- return mockedModule;
58
- });
package/src/package.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "name": "@nest-yalc-2/jest-config",
3
- "version": "2.0.0",
4
- "description": "",
5
- "main": "./index.ts",
6
- "exports": {
7
- ".": "./index.ts",
8
- "./*": "./*.ts"
9
- },
10
- "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1"
12
- },
13
- "author": "",
14
- "license": "MIT",
15
- "types": "./index.ts",
16
- "files": [
17
- "dist"
18
- ],
19
- "dependencies": {
20
- "tslib": "^2.6.3"
21
- }
22
- }
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.dev.json"
3
- }
package/src/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "strict": true,
4
- "esModuleInterop": false,
5
- "allowSyntheticDefaultImports": true,
6
- "moduleResolution": "node",
7
- "module": "CommonJS",
8
- }
9
- }