Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(@angular-devkit/build-angular): disable Webpack caching during harness-based unit tests #21897

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,27 @@ export interface BuilderHarnessExecutionOptions {
useNativeFileWatching: boolean;
}

/**
* The default set of fields provided to all builders executed via the BuilderHarness.
* `root` and `sourceRoot` are required for most Angular builders to function.
* `cli.cache.enabled` set to false provides improved test isolation guarantees by disabling
* the Webpack caching.
*/
const DEFAULT_PROJECT_METADATA = {
root: '.',
sourceRoot: 'src',
cli: {
cache: {
enabled: false,
},
},
};

export class BuilderHarness<T> {
private readonly builderInfo: BuilderInfo;
private schemaRegistry = new json.schema.CoreSchemaRegistry();
private projectName = 'test';
private projectMetadata: Record<string, unknown> = { root: '.', sourceRoot: 'src' };
private projectMetadata: Record<string, unknown> = DEFAULT_PROJECT_METADATA;
private targetName?: string;
private options = new Map<string | null, T>();
private builderTargets = new Map<
Expand Down Expand Up @@ -365,7 +381,7 @@ class HarnessBuilderContext implements BuilderContext {

get analytics(): analytics.Analytics {
// Can be undefined even though interface does not allow it
return (undefined as unknown) as analytics.Analytics;
return undefined as unknown as analytics.Analytics;
}

addTeardown(teardown: () => Promise<void> | void): void {
Expand Down Expand Up @@ -447,7 +463,7 @@ class HarnessBuilderContext implements BuilderContext {
options: json.JsonObject,
builderName: string,
): Promise<T> {
return (this.contextHost.validate(options, builderName) as unknown) as T;
return this.contextHost.validate(options, builderName) as unknown as T;
}

// Unused report methods
Expand Down