-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move builder testing infrastructure to separate bazel target mo…
…dule The builder testing infrastructure and harness has been moved out of the `@angular-devkit/build-angular` package and into a separate bazel only module. This allows the testing code to be shared with other packages within the repository. It also removes test only code from within the package that is not specific any of the included builders.
- Loading branch information
1 parent
63dab46
commit 6313036
Showing
49 changed files
with
270 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test") | ||
load("//tools:defaults.bzl", "ts_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ts_library( | ||
name = "builder", | ||
testonly = True, | ||
srcs = glob( | ||
include = [ | ||
"src/**/*.ts", | ||
], | ||
exclude = [ | ||
"src/**/*_spec.ts", | ||
], | ||
), | ||
data = glob(["projects/**/*"]), | ||
deps = [ | ||
"//packages/angular_devkit/architect", | ||
"//packages/angular_devkit/architect/node", | ||
"//packages/angular_devkit/architect/testing", | ||
"//packages/angular_devkit/core", | ||
"//packages/angular_devkit/core/node", | ||
"@npm//rxjs", | ||
], | ||
) | ||
|
||
ts_library( | ||
name = "unit_test_lib", | ||
testonly = True, | ||
srcs = glob( | ||
include = [ | ||
"src/**/*_spec.ts", | ||
], | ||
), | ||
deps = [ | ||
":builder", | ||
"//packages/angular_devkit/architect/testing", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "unit_test", | ||
srcs = [":unit_test_lib"], | ||
) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export { | ||
BuilderHarness, | ||
BuilderHarnessExecutionOptions, | ||
BuilderHarnessExecutionResult, | ||
} from './builder-harness'; | ||
export { HarnessFileMatchers, JasmineBuilderHarness, describeBuilder } from './jasmine-helpers'; | ||
export * from './test-utils'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/* eslint-disable import/no-extraneous-dependencies */ | ||
|
||
import { Architect, BuilderOutput, ScheduleOptions, Target } from '@angular-devkit/architect'; | ||
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node'; | ||
import { TestProjectHost, TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
import { | ||
Path, | ||
getSystemPath, | ||
join, | ||
json, | ||
normalize, | ||
schema, | ||
virtualFs, | ||
workspaces, | ||
} from '@angular-devkit/core'; | ||
import { firstValueFrom } from 'rxjs'; | ||
|
||
// Default timeout for large specs is 2.5 minutes. | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000; | ||
|
||
export const workspaceRoot = join(normalize(__dirname), `../projects/hello-world-app/`); | ||
export const host = new TestProjectHost(workspaceRoot); | ||
export const outputPath: Path = normalize('dist'); | ||
|
||
export const browserTargetSpec = { project: 'app', target: 'build' }; | ||
export const devServerTargetSpec = { project: 'app', target: 'serve' }; | ||
export const extractI18nTargetSpec = { project: 'app', target: 'extract-i18n' }; | ||
export const karmaTargetSpec = { project: 'app', target: 'test' }; | ||
export const tslintTargetSpec = { project: 'app', target: 'lint' }; | ||
export const protractorTargetSpec = { project: 'app-e2e', target: 'e2e' }; | ||
|
||
export async function createArchitect(workspaceRoot: Path) { | ||
const registry = new schema.CoreSchemaRegistry(); | ||
registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
const workspaceSysPath = getSystemPath(workspaceRoot); | ||
|
||
const { workspace } = await workspaces.readWorkspace( | ||
workspaceSysPath, | ||
workspaces.createWorkspaceHost(host), | ||
); | ||
const architectHost = new TestingArchitectHost( | ||
workspaceSysPath, | ||
workspaceSysPath, | ||
new WorkspaceNodeModulesArchitectHost(workspace, workspaceSysPath), | ||
); | ||
const architect = new Architect(architectHost, registry); | ||
|
||
return { | ||
workspace, | ||
architectHost, | ||
architect, | ||
}; | ||
} | ||
|
||
export interface BrowserBuildOutput { | ||
output: BuilderOutput; | ||
files: { [file: string]: Promise<string> }; | ||
} | ||
|
||
export async function browserBuild( | ||
architect: Architect, | ||
host: virtualFs.Host, | ||
target: Target, | ||
overrides?: json.JsonObject, | ||
scheduleOptions?: ScheduleOptions, | ||
): Promise<BrowserBuildOutput> { | ||
const run = await architect.scheduleTarget(target, overrides, scheduleOptions); | ||
const output = (await run.result) as BuilderOutput & { outputs: { path: string }[] }; | ||
expect(output.success).toBe(true); | ||
|
||
if (!output.success) { | ||
await run.stop(); | ||
|
||
return { | ||
output, | ||
files: {}, | ||
}; | ||
} | ||
|
||
const [{ path }] = output.outputs; | ||
expect(path).toBeTruthy(); | ||
const outputPath = normalize(path); | ||
|
||
const fileNames = await firstValueFrom(host.list(outputPath)); | ||
const files = fileNames.reduce((acc: { [name: string]: Promise<string> }, path) => { | ||
let cache: Promise<string> | null = null; | ||
Object.defineProperty(acc, path, { | ||
enumerable: true, | ||
get() { | ||
if (cache) { | ||
return cache; | ||
} | ||
if (!fileNames.includes(path)) { | ||
return Promise.reject('No file named ' + path); | ||
} | ||
cache = firstValueFrom(host.read(join(outputPath, path))).then((content) => | ||
virtualFs.fileBufferToString(content), | ||
); | ||
|
||
return cache; | ||
}, | ||
}); | ||
|
||
return acc; | ||
}, {}); | ||
|
||
await run.stop(); | ||
|
||
return { | ||
output, | ||
files, | ||
}; | ||
} | ||
|
||
export const lazyModuleFiles: { [path: string]: string } = { | ||
'src/app/lazy/lazy-routing.module.ts': ` | ||
import { NgModule } from '@angular/core'; | ||
import { Routes, RouterModule } from '@angular/router'; | ||
const routes: Routes = []; | ||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule] | ||
}) | ||
export class LazyRoutingModule { } | ||
`, | ||
'src/app/lazy/lazy.module.ts': ` | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { LazyRoutingModule } from './lazy-routing.module'; | ||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
LazyRoutingModule | ||
], | ||
declarations: [] | ||
}) | ||
export class LazyModule { } | ||
`, | ||
}; | ||
|
||
export const lazyModuleFnImport: { [path: string]: string } = { | ||
'src/app/app.module.ts': ` | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
import { AppComponent } from './app.component'; | ||
import { RouterModule } from '@angular/router'; | ||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule, | ||
RouterModule.forRoot([ | ||
{ path: 'lazy', loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule) } | ||
]) | ||
], | ||
providers: [], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.