@@ -30,6 +30,7 @@ function configureProject<A extends pj.typescript.TypeScriptProject>(x: A): A {
3030 'eslint-plugin-import' ,
3131 'eslint-plugin-jest' ,
3232 'eslint-plugin-jsdoc' ,
33+ 'jest-junit@^16' ,
3334 ) ;
3435 x . eslint ?. addPlugins (
3536 '@typescript-eslint' ,
@@ -86,19 +87,24 @@ const CLI_SDK_V3_RANGE = '3.741';
8687 */
8788function sharedJestConfig ( ) : pj . javascript . JestConfigOptions {
8889 return {
90+ moduleFileExtensions : [
91+ // .ts first to prefer a ts over a js if present
92+ 'ts' ,
93+ 'js' ,
94+ ] ,
8995 maxWorkers : '80%' ,
9096 testEnvironment : 'node' ,
9197 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+ } ,
97103 collectCoverage : true ,
98104 coverageReporters : [
99105 'text-summary' , // for console summary
100106 '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
102108 ] ,
103109 testMatch : [ '<rootDir>/test/**/?(*.)+(test).ts' ] ,
104110 coveragePathIgnorePatterns : [ '\\.generated\\.[jt]s$' , '<rootDir>/test/' , '.warnings.jsii.js$' , '/node_modules/' ] ,
@@ -108,8 +114,29 @@ function sharedJestConfig(): pj.javascript.JestConfigOptions {
108114 // fail because they rely on shared mutable state left by other tests
109115 // (files on disk, global mocks, etc).
110116 randomize : true ,
117+ } ;
118+ }
111119
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+ } ,
113140 } ;
114141}
115142
@@ -213,6 +240,8 @@ function genericCdkProps(props: GenericProps = {}) {
213240 releasableCommits : pj . ReleasableCommits . featuresAndFixes ( '.' ) ,
214241 jestOptions : {
215242 configFilePath : 'jest.config.json' ,
243+ junitReporting : false ,
244+ coverageText : false ,
216245 jestConfig : sharedJestConfig ( ) ,
217246 preserveDefaultReporters : false ,
218247 } ,
@@ -245,6 +274,14 @@ const cloudAssemblySchema = configureProject(
245274 devDeps : [ '@types/semver' , 'mock-fs' , 'typescript-json-schema' , 'tsx' ] ,
246275 disableTsconfig : true ,
247276
277+ jestOptions : jestOptionsForProject ( {
278+ jestConfig : {
279+ coverageThreshold : {
280+ functions : 75 ,
281+ } ,
282+ } ,
283+ } ) ,
284+
248285 // Append a specific version string for testing
249286 nextVersionCommand : 'tsx ../../../projenrc/next-version.ts majorFromRevision:schema/version.json maybeRc' ,
250287 } ) ,
@@ -314,6 +351,14 @@ const cloudFormationDiff = configureProject(
314351 } ,
315352 } ,
316353
354+ jestOptions : jestOptionsForProject ( {
355+ jestConfig : {
356+ coverageThreshold : {
357+ functions : 75 ,
358+ } ,
359+ } ,
360+ } ) ,
361+
317362 // Append a specific version string for testing
318363 nextVersionCommand : 'tsx ../../../projenrc/next-version.ts maybeRc' ,
319364 } ) ,
@@ -402,6 +447,13 @@ const nodeBundle = configureProject(
402447 description : 'Tool for generating npm-shrinkwrap from yarn.lock' ,
403448 deps : [ 'esbuild' , 'fs-extra@^9' , 'license-checker' , 'madge' , 'shlex' , 'yargs' ] ,
404449 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+ } ) ,
405457 } ) ,
406458) ;
407459// Too many console statements
@@ -536,6 +588,13 @@ const cdkAssets = configureProject(
536588 prerelease : 'rc' ,
537589 majorVersion : 3 ,
538590
591+ jestOptions : jestOptionsForProject ( {
592+ jestConfig : {
593+ // We have many tests here that commonly time out
594+ testTimeout : 10_000 ,
595+ } ,
596+ } ) ,
597+
539598 // Append a specific version string for testing
540599 nextVersionCommand : 'tsx ../../projenrc/next-version.ts maybeRc' ,
541600 } ) ,
@@ -695,13 +754,32 @@ const cli = configureProject(
695754 dirs : [ 'lib' ] ,
696755 ignorePatterns : [ '*.template.ts' , '*.d.ts' , 'test/**/*.ts' ] ,
697756 } ,
698- jestOptions : {
699- ...genericCdkProps ( ) . jestOptions ,
757+ jestOptions : jestOptionsForProject ( {
700758 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+ ] ,
702779 testEnvironment : './test/jest-bufferedconsole.ts' ,
780+ setupFilesAfterEnv : [ '<rootDir>/test/jest-setup-after-env.ts' ] ,
703781 } ,
704- } ,
782+ } ) ,
705783
706784 // Append a specific version string for testing
707785 nextVersionCommand : 'tsx ../../projenrc/next-version.ts maybeRc' ,
@@ -790,15 +868,6 @@ for (const resourceCommand of includeCliResourcesCommands) {
790868 cli . postCompileTask . exec ( resourceCommand ) ;
791869}
792870
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-
802871new BundleCli ( cli , {
803872 externals : {
804873 optionalDependencies : [
@@ -855,6 +924,13 @@ const cliLib = configureProject(
855924 '*.d.ts' ,
856925 ] ,
857926 } ,
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+ } ) ,
858934 } ) ,
859935) ;
860936
@@ -1005,6 +1081,18 @@ const toolkitLib = configureProject(
10051081 '*.d.ts' ,
10061082 ] ,
10071083 } ,
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+ } ) ,
10081096 tsconfig : {
10091097 compilerOptions : {
10101098 target : 'es2022' ,
@@ -1102,6 +1190,14 @@ const cdkCliWrapper = configureProject(
11021190 nextVersionCommand : `tsx ../../../projenrc/next-version.ts copyVersion:../../../${ cliPackageJson } ` ,
11031191 // Watch 2 directories at once
11041192 releasableCommits : pj . ReleasableCommits . featuresAndFixes ( `. ../../${ cli . name } ` ) ,
1193+
1194+ jestOptions : jestOptionsForProject ( {
1195+ jestConfig : {
1196+ coverageThreshold : {
1197+ branches : 62 ,
1198+ } ,
1199+ } ,
1200+ } ) ,
11051201 } ) ,
11061202) ;
11071203
0 commit comments