@nest-yalc-2/jest-config 2.2.0 → 2.2.2
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/LICENSE +661 -0
- package/package.json +25 -10
- package/src/CHANGELOG.md +8 -0
- package/src/README.md +31 -0
- package/src/config/CHANGELOG.md +8 -0
- package/src/config/README.md +31 -0
- package/src/config/gql-plugin.js +25 -0
- package/src/config/index.d.ts +2 -0
- package/src/config/index.js +6 -0
- package/src/config/index.js.map +1 -0
- package/src/config/index.ts +2 -0
- package/src/config/jest-conf.generator.d.ts +53 -0
- package/src/config/jest-conf.generator.js +193 -0
- package/src/config/jest-conf.generator.js.map +1 -0
- package/src/config/jest-conf.generator.ts +368 -0
- package/src/config/jest-def.config.d.ts +20 -0
- package/src/config/jest-def.config.js +145 -0
- package/src/config/jest-def.config.js.map +1 -0
- package/src/config/jest-def.config.ts +214 -0
- package/src/config/jest.setup.d.ts +1 -0
- package/src/config/jest.setup.js +10 -0
- package/src/config/jest.setup.js.map +1 -0
- package/src/config/jest.setup.ts +39 -0
- package/src/config/package.json +22 -0
- package/src/config/tsconfig.dev.json +3 -0
- package/src/config/tsconfig.json +9 -0
- package/src/gql-plugin.js +25 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +6 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +2 -0
- package/src/jest-conf.generator.d.ts +53 -0
- package/src/jest-conf.generator.js +193 -0
- package/src/jest-conf.generator.js.map +1 -0
- package/src/jest-conf.generator.ts +363 -0
- package/src/jest-def.config.d.ts +20 -0
- package/src/jest-def.config.js +151 -0
- package/src/jest-def.config.js.map +1 -0
- package/src/jest-def.config.ts +220 -0
- package/src/jest.setup.d.ts +1 -0
- package/src/jest.setup.js +26 -0
- package/src/jest.setup.js.map +1 -0
- package/src/jest.setup.ts +58 -0
- package/src/package.json +28 -0
- package/src/src/CHANGELOG.md +8 -0
- package/src/src/README.md +31 -0
- package/src/src/config/CHANGELOG.md +8 -0
- package/src/src/config/README.md +31 -0
- package/src/src/config/gql-plugin.js +25 -0
- package/src/src/config/index.d.ts +2 -0
- package/src/src/config/index.js +6 -0
- package/src/src/config/index.js.map +1 -0
- package/src/src/config/index.ts +2 -0
- package/src/src/config/jest-conf.generator.d.ts +53 -0
- package/src/src/config/jest-conf.generator.js +193 -0
- package/src/src/config/jest-conf.generator.js.map +1 -0
- package/src/src/config/jest-conf.generator.ts +368 -0
- package/src/src/config/jest-def.config.d.ts +20 -0
- package/src/src/config/jest-def.config.js +145 -0
- package/src/src/config/jest-def.config.js.map +1 -0
- package/src/src/config/jest-def.config.ts +214 -0
- package/src/src/config/jest.setup.d.ts +1 -0
- package/src/src/config/jest.setup.js +10 -0
- package/src/src/config/jest.setup.js.map +1 -0
- package/src/src/config/jest.setup.ts +39 -0
- package/src/src/config/package.json +22 -0
- package/src/src/config/tsconfig.dev.json +3 -0
- package/src/src/config/tsconfig.json +9 -0
- package/src/src/gql-plugin.js +25 -0
- package/src/src/index.d.ts +2 -0
- package/src/src/index.js +6 -0
- package/src/src/index.js.map +1 -0
- package/src/src/index.ts +2 -0
- package/src/src/jest-conf.generator.d.ts +53 -0
- package/src/src/jest-conf.generator.js +193 -0
- package/src/src/jest-conf.generator.js.map +1 -0
- package/src/src/jest-conf.generator.ts +363 -0
- package/src/src/jest-def.config.d.ts +20 -0
- package/src/src/jest-def.config.js +151 -0
- package/src/src/jest-def.config.js.map +1 -0
- package/src/src/jest-def.config.ts +220 -0
- package/src/src/jest.setup.d.ts +1 -0
- package/src/src/jest.setup.js +26 -0
- package/src/src/jest.setup.js.map +1 -0
- package/src/src/jest.setup.ts +58 -0
- package/src/src/package.json +28 -0
- package/src/src/tsconfig.dev.json +3 -0
- package/src/src/tsconfig.json +9 -0
- package/src/tsconfig.dev.json +3 -0
- package/src/tsconfig.json +9 -0
|
@@ -0,0 +1,220 @@
|
|
|
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
|
+
'^(@nest-yalc-2/.*|@node-yalc/.*|\\.{1,2}/.*)\\.js$': [
|
|
183
|
+
'$1.ts',
|
|
184
|
+
'$1/index.ts',
|
|
185
|
+
'$1.js',
|
|
186
|
+
'$1',
|
|
187
|
+
],
|
|
188
|
+
...pathsToModuleNameMapper(compilerOptions.paths ?? {}, {
|
|
189
|
+
prefix: `${dirname}/`,
|
|
190
|
+
useESM: true,
|
|
191
|
+
}),
|
|
192
|
+
},
|
|
193
|
+
errorOnDeprecated: true,
|
|
194
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
195
|
+
// injectGlobals: false,
|
|
196
|
+
...options?.jestConf,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
if (options.transformEsModules) {
|
|
200
|
+
const esModules = [
|
|
201
|
+
...(Array.isArray(options.transformEsModules)
|
|
202
|
+
? options.transformEsModules
|
|
203
|
+
: []),
|
|
204
|
+
'aggregate-error',
|
|
205
|
+
'clean-stack',
|
|
206
|
+
'escape-string-regexp',
|
|
207
|
+
'indent-string',
|
|
208
|
+
'p-map',
|
|
209
|
+
'lodash-es',
|
|
210
|
+
].join('|');
|
|
211
|
+
|
|
212
|
+
config.transformIgnorePatterns = [
|
|
213
|
+
`[/\\\\]node_modules[/\\\\](?!${esModules}).+\\.(js|jsx|ts|tsx)$`,
|
|
214
|
+
];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return config;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export default defaultConf;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
process.env.NODE_ENV = 'test';
|
|
4
|
+
if (!process.env.LISTENING_TO_UNHANDLED_REJECTION) {
|
|
5
|
+
process.on('unhandledRejection', (err) => {
|
|
6
|
+
throw err;
|
|
7
|
+
});
|
|
8
|
+
process.env.LISTENING_TO_UNHANDLED_REJECTION = 'true';
|
|
9
|
+
}
|
|
10
|
+
jest.mock('@nestjs/graphql', () => {
|
|
11
|
+
const actual = jest.requireActual('@nestjs/graphql');
|
|
12
|
+
const mockedModule = Object.assign({}, actual);
|
|
13
|
+
const decorators = [
|
|
14
|
+
'Args', 'Field', 'Query', 'Mutation', 'Resolver', 'InputType', 'ObjectType',
|
|
15
|
+
'InterfaceType', 'ResolveField', 'HideField', 'Directive', 'registerEnumType', 'IntersectionType'
|
|
16
|
+
];
|
|
17
|
+
for (const name of decorators) {
|
|
18
|
+
if (actual[name]) {
|
|
19
|
+
mockedModule[name] = jest.fn().mockImplementation((...args) => {
|
|
20
|
+
return actual[name](...args);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return mockedModule;
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=jest.setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nest-yalc-2/jest-config",
|
|
3
|
+
"version": "2.2.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./index.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/src/index.js",
|
|
8
|
+
"./*": "./dist/src/*"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"author": "Autistic_Intelligence",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"types": "./index.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"tslib": "^2.6.3"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"nestjs",
|
|
24
|
+
"yalc",
|
|
25
|
+
"framework",
|
|
26
|
+
"jest config"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @nest-yalc-2/jest-config
|
|
2
|
+
|
|
3
|
+
Reusable Jest configuration generators for YALC-style TypeScript and NestJS
|
|
4
|
+
projects.
|
|
5
|
+
|
|
6
|
+
Use this package when a consuming workspace wants the same ts-jest defaults,
|
|
7
|
+
coverage threshold handling, GraphQL AST transformer, and project generation
|
|
8
|
+
used by the YALC monorepo.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install --save-dev @nest-yalc-2/jest-config
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Main Exports
|
|
17
|
+
|
|
18
|
+
- `jestConfGenerator` for creating multi-project Jest configs.
|
|
19
|
+
- `createE2EConfig` for e2e Jest configuration.
|
|
20
|
+
- `tsJestConfig` and `tsJestConfigE2E` for ts-jest setup.
|
|
21
|
+
- `coverageThreshold`, `coveragePathIgnorePatterns`, and default globals.
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { jestConfGenerator } from '@nest-yalc-2/jest-config';
|
|
27
|
+
|
|
28
|
+
export default jestConfGenerator(rootPath, projects, appProjects, {
|
|
29
|
+
skipProjects: ['types'],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @nest-yalc-2/jest-config
|
|
2
|
+
|
|
3
|
+
Reusable Jest configuration generators for YALC-style TypeScript and NestJS
|
|
4
|
+
projects.
|
|
5
|
+
|
|
6
|
+
Use this package when a consuming workspace wants the same ts-jest defaults,
|
|
7
|
+
coverage threshold handling, GraphQL AST transformer, and project generation
|
|
8
|
+
used by the YALC monorepo.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install --save-dev @nest-yalc-2/jest-config
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Main Exports
|
|
17
|
+
|
|
18
|
+
- `jestConfGenerator` for creating multi-project Jest configs.
|
|
19
|
+
- `createE2EConfig` for e2e Jest configuration.
|
|
20
|
+
- `tsJestConfig` and `tsJestConfigE2E` for ts-jest setup.
|
|
21
|
+
- `coverageThreshold`, `coveragePathIgnorePatterns`, and default globals.
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { jestConfGenerator } from '@nest-yalc-2/jest-config';
|
|
27
|
+
|
|
28
|
+
export default jestConfGenerator(rootPath, projects, appProjects, {
|
|
29
|
+
skipProjects: ['types'],
|
|
30
|
+
});
|
|
31
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
4
|
+
const transformer = require('@nestjs/graphql/plugin');
|
|
5
|
+
|
|
6
|
+
module.exports.name = 'nestjs-graphql-transformer';
|
|
7
|
+
// you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
|
|
8
|
+
module.exports.version = 4;
|
|
9
|
+
|
|
10
|
+
module.exports.factory = (cs) => {
|
|
11
|
+
return transformer.before(
|
|
12
|
+
{
|
|
13
|
+
typeFileNameSuffix: [
|
|
14
|
+
'.input.ts',
|
|
15
|
+
'.args.ts',
|
|
16
|
+
'.arg.ts',
|
|
17
|
+
'.entity.ts',
|
|
18
|
+
'.type.ts',
|
|
19
|
+
'.dto.ts',
|
|
20
|
+
],
|
|
21
|
+
introspectComments: true,
|
|
22
|
+
},
|
|
23
|
+
cs.program, // "cs.tsCompiler.program" for older versions of Jest (<= v27)
|
|
24
|
+
);
|
|
25
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./jest-conf.generator.js"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./jest-def.config.js"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,+DAAqC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { JestConfigWithTsJest } from 'ts-jest';
|
|
2
|
+
import { IDefaultConfOptions } from './jest-def.config.js';
|
|
3
|
+
interface IAppDep {
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IAppProjSetting {
|
|
8
|
+
confOverride?: any;
|
|
9
|
+
deps: IAppDep[];
|
|
10
|
+
}
|
|
11
|
+
export interface IProjectInfo {
|
|
12
|
+
path: string;
|
|
13
|
+
sourcePath: string;
|
|
14
|
+
type: 'library' | 'application' | string;
|
|
15
|
+
}
|
|
16
|
+
export interface IOptions {
|
|
17
|
+
skipProjects?: string[];
|
|
18
|
+
confOverrides?: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
defaultCoverageThreshold?: {
|
|
22
|
+
branches: number;
|
|
23
|
+
functions: number;
|
|
24
|
+
lines: number;
|
|
25
|
+
statements: number;
|
|
26
|
+
};
|
|
27
|
+
tsConfigPath?: {
|
|
28
|
+
(proj: IProjectInfo): string;
|
|
29
|
+
};
|
|
30
|
+
coverageOutputPath?: {
|
|
31
|
+
(subProjectPath: string): string;
|
|
32
|
+
};
|
|
33
|
+
defaultConfOptions?: IDefaultConfOptions;
|
|
34
|
+
tsJestConfig?: any;
|
|
35
|
+
extraSetupFiles?: string[];
|
|
36
|
+
setupFilesAfterEnv?: string[];
|
|
37
|
+
}
|
|
38
|
+
export declare function jestConfGenerator(rootPath: string, projectList: {
|
|
39
|
+
[key: string]: IProjectInfo;
|
|
40
|
+
}, appProjectsSettings: {
|
|
41
|
+
[key: string]: IAppProjSetting;
|
|
42
|
+
}, options: IOptions): JestConfigWithTsJest;
|
|
43
|
+
export interface E2EOptions {
|
|
44
|
+
alias?: string;
|
|
45
|
+
e2eDirname: string;
|
|
46
|
+
rootDirname: string;
|
|
47
|
+
defaultConfOptions?: IDefaultConfOptions;
|
|
48
|
+
confOverride?: JestConfigWithTsJest;
|
|
49
|
+
withGqlPlugins?: boolean;
|
|
50
|
+
tsJestConfig?: any;
|
|
51
|
+
}
|
|
52
|
+
export declare const createE2EConfig: (options: E2EOptions) => JestConfigWithTsJest;
|
|
53
|
+
export {};
|