@@ -18,6 +18,16 @@ export interface IJestConfig {
1818 */
1919 isEnabled ?: boolean ;
2020
21+ /**
22+ * Indicate whether Jest cache is enabled or not.
23+ */
24+ cache ?: boolean ;
25+
26+ /**
27+ * The directory where Jest should store its cached information.
28+ */
29+ cacheDirectory ?: string ;
30+
2131 /**
2232 * Same as Jest CLI option collectCoverageFrom
2333 */
@@ -65,6 +75,7 @@ export class JestTask extends GulpTask<IJestConfig> {
6575 constructor ( ) {
6676 super ( 'jest' ,
6777 {
78+ cache : true ,
6879 collectCoverageFrom : [ 'lib/**/*.js?(x)' , '!lib/**/test/**' ] ,
6980 coverage : true ,
7081 coverageReporters : [ 'json' , 'html' ] ,
@@ -92,23 +103,31 @@ export class JestTask extends GulpTask<IJestConfig> {
92103
93104 this . _copySnapshots ( this . buildConfig . srcFolder , this . buildConfig . libFolder ) ;
94105
95- Jest . runCLI (
96- {
97- ci : this . buildConfig . production ,
98- config : configFileFullPath ,
99- collectCoverageFrom : this . taskConfig . collectCoverageFrom ,
100- coverage : this . taskConfig . coverage ,
101- coverageReporters : this . taskConfig . coverageReporters ,
102- coverageDirectory : path . join ( this . buildConfig . tempFolder , 'coverage' ) ,
103- maxWorkers : 1 ,
104- moduleDirectories : [ 'node_modules' , this . buildConfig . libFolder ] ,
105- reporters : [ path . join ( __dirname , 'JestReporter.js' ) ] ,
106- rootDir : this . buildConfig . rootPath ,
107- runInBand : true ,
108- testMatch : [ '**/*.test.js?(x)' ] ,
109- testPathIgnorePatterns : this . taskConfig . testPathIgnorePatterns ,
110- updateSnapshot : ! this . buildConfig . production
111- } ,
106+ // tslint:disable-next-line:no-any
107+ const jestConfig : any = {
108+ ci : this . buildConfig . production ,
109+ cache : ! ! this . taskConfig . cache ,
110+ config : configFileFullPath ,
111+ collectCoverageFrom : this . taskConfig . collectCoverageFrom ,
112+ coverage : this . taskConfig . coverage ,
113+ coverageReporters : this . taskConfig . coverageReporters ,
114+ coverageDirectory : path . join ( this . buildConfig . tempFolder , 'coverage' ) ,
115+ maxWorkers : 1 ,
116+ moduleDirectories : [ 'node_modules' , this . buildConfig . libFolder ] ,
117+ reporters : [ path . join ( __dirname , 'JestReporter.js' ) ] ,
118+ rootDir : this . buildConfig . rootPath ,
119+ runInBand : true ,
120+ testMatch : [ '**/*.test.js?(x)' ] ,
121+ testPathIgnorePatterns : this . taskConfig . testPathIgnorePatterns ,
122+ updateSnapshot : ! this . buildConfig . production
123+ } ;
124+
125+ if ( this . taskConfig . cacheDirectory ) {
126+ // tslint:disable-next-line:no-string-literal
127+ jestConfig [ 'cacheDirectory' ] = this . taskConfig . cacheDirectory ;
128+ }
129+
130+ Jest . runCLI ( jestConfig ,
112131 [ this . buildConfig . rootPath ] ,
113132 ( result ) => {
114133 if ( result . numFailedTests || result . numFailedTestSuites ) {
0 commit comments