Skip to content

Commit a3b5289

Browse files
authored
Support cache configuration in Jest task (microsoft#453)
* Support cache configuration in Jest task * Add change file
1 parent c9a6fdc commit a3b5289

4 files changed

Lines changed: 57 additions & 17 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/gulp-core-build",
5+
"comment": "Add cache configuration to Jest task",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/gulp-core-build",
10+
"email": "qz2017@users.noreply.github.com"
11+
}

‎common/reviews/api/gulp-core-build.api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ interface IExecutable {
190190

191191
// @alpha
192192
interface IJestConfig {
193+
cache?: boolean;
194+
cacheDirectory?: string;
193195
collectCoverageFrom?: string[];
194196
coverage?: boolean;
195197
coverageReporters?: string[];

‎core-build/gulp-core-build/src/tasks/JestTask.ts‎

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

‎core-build/gulp-core-build/src/tasks/jest.schema.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
"type": "boolean",
1414
"default": false
1515
},
16+
"cache": {
17+
"description": "Indicate whether Jest cache is enabled or not",
18+
"type": "boolean"
19+
},
20+
"cacheDirectory": {
21+
"description": "The directory where Jest should store its cached information",
22+
"type": "string"
23+
},
1624
"collectCoverageFrom": {
1725
"description": "Same as Jest CLI option collectCoverageFrom",
1826
"type": "array",

0 commit comments

Comments
 (0)