Skip to content

Commit ebbf0be

Browse files
author
Nicholas Pape
authored
Karma should only fail production builds (microsoft#117)
* Only fail the karma task when in production, otherwise just write a warning. * API Changes * Changefile * Fixup some unrelated stuff * Changefile
1 parent 947f0be commit ebbf0be

File tree

7 files changed

+32
-13
lines changed

7 files changed

+32
-13
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/gulp-core-build-karma",
5+
"comment": "The KarmaTask should only cause the build to fail if we are in production, otherwise treat failing tests as a warning.",
6+
"type": "minor"
7+
},
8+
{
9+
"comment": "",
10+
"packageName": "@microsoft/gulp-core-build",
11+
"type": "none"
12+
}
13+
],
14+
"email": "nickpape@users.noreply.github.com"
15+
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GulpTask<TASK_CONFIG> implements IExecutable {
4949
public fileExists(localPath: string): boolean;
5050
public fileWarning(filePath: string, line: number, column: number, warningCode: string, message: string): void;
5151
public getCleanMatch(buildConfig: IBuildConfig, taskConfig: TASK_CONFIG = this.taskConfig): string[];
52-
public isEnabled(config?: IBuildConfig): boolean;
52+
public isEnabled(buildConfig: IBuildConfig): boolean;
5353
protected loadSchema(): Object;
5454
public log(message: string): void;
5555
public logError(message: string): void;
@@ -109,11 +109,9 @@ interface ICustomGulpTask {
109109

110110
// (undocumented)
111111
interface IExecutable {
112-
// (undocumented)
113-
enabled?: boolean;
114112
execute: (config: IBuildConfig) => Promise<void>;
115113
getCleanMatch?: (config: IBuildConfig, taskConfig?: any) => string[];
116-
isEnabled?: (config?: IBuildConfig) => boolean;
114+
isEnabled?: (buildConfig: IBuildConfig) => boolean;
117115
name?: string;
118116
onRegister?: () => void;
119117
}

common/reviews/api/node-library-build.api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GulpTask<TASK_CONFIG> implements IExecutable {
5151
buildConfig: IBuildConfig;
5252
cleanMatch: string[];
5353
copyFile(localSourcePath: string, localDestPath?: string): void;
54+
enabled: boolean;
5455
execute(config: IBuildConfig): Promise<void>;
5556
abstract executeTask(gulp: gulp.Gulp | GulpProxy, completeCallback?: (result?: Object) => void): Promise<Object> | NodeJS.ReadWriteStream | void;
5657
fileError(filePath: string, line: number, column: number, errorCode: string, message: string): void;
@@ -119,7 +120,7 @@ interface ICustomGulpTask {
119120
interface IExecutable {
120121
execute: (config: IBuildConfig) => Promise<void>;
121122
getCleanMatch?: (config: IBuildConfig, taskConfig?: any) => string[];
122-
isEnabled?: (config?: IBuildConfig) => boolean;
123+
isEnabled?: (buildConfig: IBuildConfig) => boolean;
123124
name?: string;
124125
onRegister?: () => void;
125126
}

common/reviews/api/web-library-build.api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GulpTask<TASK_CONFIG> implements IExecutable {
5151
buildConfig: IBuildConfig;
5252
cleanMatch: string[];
5353
copyFile(localSourcePath: string, localDestPath?: string): void;
54+
enabled: boolean;
5455
execute(config: IBuildConfig): Promise<void>;
5556
abstract executeTask(gulp: gulp.Gulp | GulpProxy, completeCallback?: (result?: Object) => void): Promise<Object> | NodeJS.ReadWriteStream | void;
5657
fileError(filePath: string, line: number, column: number, errorCode: string, message: string): void;
@@ -119,7 +120,7 @@ interface ICustomGulpTask {
119120
interface IExecutable {
120121
execute: (config: IBuildConfig) => Promise<void>;
121122
getCleanMatch?: (config: IBuildConfig, taskConfig?: any) => string[];
122-
isEnabled?: (config?: IBuildConfig) => boolean;
123+
isEnabled?: (buildConfig: IBuildConfig) => boolean;
123124
name?: string;
124125
onRegister?: () => void;
125126
}

gulp-core-build-karma/src/KarmaTask.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ export class KarmaTask extends GulpTask<IKarmaTaskConfig> {
134134
singleRun: singleRun
135135
}, (exitCode) => {
136136
if (exitCode) {
137-
completeCallback('Error(s) occured during karma.');
137+
const message: string = 'Error(s) occured during karma.';
138+
if (this.buildConfig.production) {
139+
completeCallback(message);
140+
} else {
141+
this.logWarning(message);
142+
completeCallback();
143+
}
138144
} else {
139145
completeCallback();
140146
}

gulp-core-build/src/IExecutable.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ export interface IExecutable {
1010
/** Optional name to give the task. If no name is provided, the "Running subtask" logging will be silent. */
1111
name?: string;
1212

13-
enabled?: boolean;
14-
1513
/** Optional callback to indicate if the task is enabled or not. */
16-
isEnabled?: (config?: IBuildConfig) => boolean;
14+
isEnabled?: (buildConfig: IBuildConfig) => boolean;
1715

1816
/** Optional method to indicate directory matches to clean up when the clean task is run. */
1917
getCleanMatch?: (config: IBuildConfig, taskConfig?: any) => string[]; /* tslint:disable-line:no-any */

gulp-core-build/src/tasks/GulpTask.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export abstract class GulpTask<TASK_CONFIG> implements IExecutable {
5353
* @param buildConfig - the build configuration which should be used when determining if the task is enabled
5454
* @returns true if the build is not redundant and the enabled toggle is true
5555
*/
56-
public isEnabled(config?: IBuildConfig): boolean {
57-
return (!config || !config.isRedundantBuild) && this.enabled;
58-
};
56+
public isEnabled(buildConfig: IBuildConfig): boolean {
57+
return (!buildConfig || !buildConfig.isRedundantBuild) && this.enabled;
58+
}
5959

6060
/**
6161
* A JSON Schema object which will be used to validate this task's configuration file.

0 commit comments

Comments
 (0)