@@ -30,6 +30,7 @@ function configureProject<A extends pj.typescript.TypeScriptProject>(x: A): A {
30
30
'eslint-plugin-import' ,
31
31
'eslint-plugin-jest' ,
32
32
'eslint-plugin-jsdoc' ,
33
+ 'jest-junit@^16' ,
33
34
) ;
34
35
x . eslint ?. addPlugins (
35
36
'@typescript-eslint' ,
@@ -86,19 +87,24 @@ const CLI_SDK_V3_RANGE = '3.741';
86
87
*/
87
88
function sharedJestConfig ( ) : pj . javascript . JestConfigOptions {
88
89
return {
90
+ moduleFileExtensions : [
91
+ // .ts first to prefer a ts over a js if present
92
+ 'ts' ,
93
+ 'js' ,
94
+ ] ,
89
95
maxWorkers : '80%' ,
90
96
testEnvironment : 'node' ,
91
97
coverageThreshold : {
92
- global : {
93
- branches : 80 ,
94
- statements : 80 ,
95
- } ,
96
- } as any ,
98
+ statements : 80 ,
99
+ branches : 80 ,
100
+ functions : 80 ,
101
+ lines : 80 ,
102
+ } ,
97
103
collectCoverage : true ,
98
104
coverageReporters : [
99
105
'text-summary' , // for console summary
100
106
'cobertura' , // for codecov. see https://docs.codecov.com/docs/code-coverage-with-javascript
101
- 'html' , // for local deep dive
107
+ [ 'html' , { subdir : 'html-report' } ] as any , // for local deep dive
102
108
] ,
103
109
testMatch : [ '<rootDir>/test/**/?(*.)+(test).ts' ] ,
104
110
coveragePathIgnorePatterns : [ '\\.generated\\.[jt]s$' , '<rootDir>/test/' , '.warnings.jsii.js$' , '/node_modules/' ] ,
@@ -108,8 +114,29 @@ function sharedJestConfig(): pj.javascript.JestConfigOptions {
108
114
// fail because they rely on shared mutable state left by other tests
109
115
// (files on disk, global mocks, etc).
110
116
randomize : true ,
117
+ } ;
118
+ }
111
119
112
- testTimeout : 60_000 ,
120
+ /**
121
+ * Extend default jest options for a project
122
+ */
123
+ function jestOptionsForProject ( options : pj . javascript . JestOptions ) : pj . javascript . JestOptions {
124
+ const generic = genericCdkProps ( ) . jestOptions ;
125
+ return {
126
+ ...generic ,
127
+ ...options ,
128
+ jestConfig : {
129
+ ...generic . jestConfig ,
130
+ ...( options . jestConfig ?? { } ) ,
131
+ coveragePathIgnorePatterns : [
132
+ ...( generic . jestConfig ?. coveragePathIgnorePatterns ?? [ ] ) ,
133
+ ...( options . jestConfig ?. coveragePathIgnorePatterns ?? [ ] ) ,
134
+ ] ,
135
+ coverageThreshold : {
136
+ ...( generic . jestConfig ?. coverageThreshold ?? { } ) ,
137
+ ...( options . jestConfig ?. coverageThreshold ?? { } ) ,
138
+ } ,
139
+ } ,
113
140
} ;
114
141
}
115
142
@@ -213,6 +240,8 @@ function genericCdkProps(props: GenericProps = {}) {
213
240
releasableCommits : pj . ReleasableCommits . featuresAndFixes ( '.' ) ,
214
241
jestOptions : {
215
242
configFilePath : 'jest.config.json' ,
243
+ junitReporting : false ,
244
+ coverageText : false ,
216
245
jestConfig : sharedJestConfig ( ) ,
217
246
preserveDefaultReporters : false ,
218
247
} ,
@@ -245,6 +274,14 @@ const cloudAssemblySchema = configureProject(
245
274
devDeps : [ '@types/semver' , 'mock-fs' , 'typescript-json-schema' , 'tsx' ] ,
246
275
disableTsconfig : true ,
247
276
277
+ jestOptions : jestOptionsForProject ( {
278
+ jestConfig : {
279
+ coverageThreshold : {
280
+ functions : 75 ,
281
+ } ,
282
+ } ,
283
+ } ) ,
284
+
248
285
// Append a specific version string for testing
249
286
nextVersionCommand : 'tsx ../../../projenrc/next-version.ts majorFromRevision:schema/version.json maybeRc' ,
250
287
} ) ,
@@ -314,6 +351,14 @@ const cloudFormationDiff = configureProject(
314
351
} ,
315
352
} ,
316
353
354
+ jestOptions : jestOptionsForProject ( {
355
+ jestConfig : {
356
+ coverageThreshold : {
357
+ functions : 75 ,
358
+ } ,
359
+ } ,
360
+ } ) ,
361
+
317
362
// Append a specific version string for testing
318
363
nextVersionCommand : 'tsx ../../../projenrc/next-version.ts maybeRc' ,
319
364
} ) ,
@@ -402,6 +447,13 @@ const nodeBundle = configureProject(
402
447
description : 'Tool for generating npm-shrinkwrap from yarn.lock' ,
403
448
deps : [ 'esbuild' , 'fs-extra@^9' , 'license-checker' , 'madge' , 'shlex' , 'yargs' ] ,
404
449
devDeps : [ '@types/license-checker' , '@types/madge' , '@types/fs-extra@^9' , 'jest-junit' , 'standard-version' ] ,
450
+ jestOptions : jestOptionsForProject ( {
451
+ jestConfig : {
452
+ coverageThreshold : {
453
+ branches : 75 ,
454
+ } ,
455
+ } ,
456
+ } ) ,
405
457
} ) ,
406
458
) ;
407
459
// Too many console statements
@@ -536,6 +588,13 @@ const cdkAssets = configureProject(
536
588
prerelease : 'rc' ,
537
589
majorVersion : 3 ,
538
590
591
+ jestOptions : jestOptionsForProject ( {
592
+ jestConfig : {
593
+ // We have many tests here that commonly time out
594
+ testTimeout : 10_000 ,
595
+ } ,
596
+ } ) ,
597
+
539
598
// Append a specific version string for testing
540
599
nextVersionCommand : 'tsx ../../projenrc/next-version.ts maybeRc' ,
541
600
} ) ,
@@ -695,13 +754,32 @@ const cli = configureProject(
695
754
dirs : [ 'lib' ] ,
696
755
ignorePatterns : [ '*.template.ts' , '*.d.ts' , 'test/**/*.ts' ] ,
697
756
} ,
698
- jestOptions : {
699
- ...genericCdkProps ( ) . jestOptions ,
757
+ jestOptions : jestOptionsForProject ( {
700
758
jestConfig : {
701
- ...genericCdkProps ( ) . jestOptions . jestConfig ,
759
+ coverageThreshold : {
760
+ // We want to improve our test coverage
761
+ // DO NOT LOWER THESE VALUES!
762
+ // If you need to break glass, open an issue to re-up the values with additional test coverage
763
+ statements : 84 ,
764
+ branches : 74 ,
765
+ functions : 87 ,
766
+ lines : 84 ,
767
+ } ,
768
+ // We have many tests here that commonly time out
769
+ testTimeout : 60_000 ,
770
+ coveragePathIgnorePatterns : [
771
+ // Mostly wrappers around the SDK, which get mocked in unit tests
772
+ '<rootDir>/lib/api/aws-auth/sdk.ts' ,
773
+
774
+ // Files generated by cli-args-gen
775
+ '<rootDir>/lib/parse-command-line-arguments.ts' ,
776
+ '<rootDir>/lib/user-input.ts' ,
777
+ '<rootDir>/lib/convert-to-user-input.ts' ,
778
+ ] ,
702
779
testEnvironment : './test/jest-bufferedconsole.ts' ,
780
+ setupFilesAfterEnv : [ '<rootDir>/test/jest-setup-after-env.ts' ] ,
703
781
} ,
704
- } ,
782
+ } ) ,
705
783
706
784
// Append a specific version string for testing
707
785
nextVersionCommand : 'tsx ../../projenrc/next-version.ts maybeRc' ,
@@ -790,15 +868,6 @@ for (const resourceCommand of includeCliResourcesCommands) {
790
868
cli . postCompileTask . exec ( resourceCommand ) ;
791
869
}
792
870
793
- Object . assign ( cli . jest ?. config ?? { } , {
794
- coveragePathIgnorePatterns : [
795
- ...( cli . jest ?. config . coveragePathIgnorePatterns ?? [ ] ) ,
796
- // Mostly wrappers around the SDK, which get mocked in unit tests
797
- '<rootDir>/lib/api/aws-auth/sdk.ts' ,
798
- ] ,
799
- setupFilesAfterEnv : [ '<rootDir>/test/jest-setup-after-env.ts' ] ,
800
- } ) ;
801
-
802
871
new BundleCli ( cli , {
803
872
externals : {
804
873
optionalDependencies : [
@@ -855,6 +924,13 @@ const cliLib = configureProject(
855
924
'*.d.ts' ,
856
925
] ,
857
926
} ,
927
+ jestOptions : jestOptionsForProject ( {
928
+ jestConfig : {
929
+ // cli-lib-alpha cannot deal with the ts files for some reason
930
+ // we can revisit this once toolkit-lib work has progressed
931
+ moduleFileExtensions : undefined ,
932
+ } ,
933
+ } ) ,
858
934
} ) ,
859
935
) ;
860
936
@@ -1005,6 +1081,18 @@ const toolkitLib = configureProject(
1005
1081
'*.d.ts' ,
1006
1082
] ,
1007
1083
} ,
1084
+ jestOptions : jestOptionsForProject ( {
1085
+ jestConfig : {
1086
+ testEnvironment : './test/_helpers/jest-bufferedconsole.ts' ,
1087
+ coverageThreshold : {
1088
+ // this is very sad but we will get better
1089
+ statements : 85 ,
1090
+ branches : 77 ,
1091
+ functions : 77 ,
1092
+ lines : 85 ,
1093
+ } ,
1094
+ } ,
1095
+ } ) ,
1008
1096
tsconfig : {
1009
1097
compilerOptions : {
1010
1098
target : 'es2022' ,
@@ -1102,6 +1190,14 @@ const cdkCliWrapper = configureProject(
1102
1190
nextVersionCommand : `tsx ../../../projenrc/next-version.ts copyVersion:../../../${ cliPackageJson } ` ,
1103
1191
// Watch 2 directories at once
1104
1192
releasableCommits : pj . ReleasableCommits . featuresAndFixes ( `. ../../${ cli . name } ` ) ,
1193
+
1194
+ jestOptions : jestOptionsForProject ( {
1195
+ jestConfig : {
1196
+ coverageThreshold : {
1197
+ branches : 62 ,
1198
+ } ,
1199
+ } ,
1200
+ } ) ,
1105
1201
} ) ,
1106
1202
) ;
1107
1203
0 commit comments