chore: add bazel test rules for the cdk (#9726)

This adds bazel test rules for everything under cdk/ and sets CircleCI Overlay tests don't work because there's not yet a way to pass through flags to the browser. These issues will be addressed in a follow-up PR.
This commit is contained in:
Jeremy Elbourn
2018-02-12 16:01:00 -08:00
committed by GitHub
parent f2c28b1805
commit 21a83bae8d
22 changed files with 6833 additions and 2632 deletions
+1
View File
@@ -36,6 +36,7 @@ jobs:
# This may be unnecessary once rules_nodejs uses nodejs 8
- run: bazel run @nodejs//:npm run postinstall
- run: bazel build src/...
- run: bazel test src/...
- save_cache:
key: material2-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
+54 -9
View File
@@ -14,22 +14,67 @@ filegroup(
# TODO(alexeagle): figure out what to do
srcs = glob(["/".join(["node_modules", pkg, "**", ext]) for pkg in [
"@angular",
"jasmine",
"typescript",
"tslib",
"zone.js",
"@types",
"tsickle",
"hammerjs",
"protobufjs",
"bytebuffer",
"reflect-metadata",
"hammerjs",
"jasmine",
"minimist",
"moment",
"protobufjs",
"protractor",
"reflect-metadata",
"tsickle",
"tslib",
"tsutils",
"typescript",
"zone.js",
] for ext in [
"*.js",
"*.json",
"*.d.ts",
]]),
]] + [
"node_modules/http-server/**",
]),
)
# Glob pattern that matches all Angular testing bundles.
ANGULAR_TESTING = [
"node_modules/@angular/*/bundles/*-testing.umd.js",
# The compiler and the dynamic platform-browser should be visible only in tests
"node_modules/@angular/compiler/bundles/*.umd.js",
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
]
filegroup(
name = "angular_bundles",
srcs = glob(["node_modules/@angular/*/bundles/*.umd.js"], exclude = ANGULAR_TESTING),
)
filegroup(
name = "angular_test_bundles",
testonly = 1,
srcs = glob(ANGULAR_TESTING),
)
filegroup(
name = "tslib_bundle",
testonly = 1,
srcs = glob(["node_modules/tslib/tslib.js"]),
)
# Files necessary for unit tests that use zonejs
filegroup(
name = "web_test_bootstrap_scripts",
# The order of these deps is important.
# Do not sort.
srcs = [
"//:node_modules/reflect-metadata/Reflect.js",
"//:node_modules/zone.js/dist/zone.js",
"//:node_modules/zone.js/dist/async-test.js",
"//:node_modules/zone.js/dist/sync-test.js",
"//:node_modules/zone.js/dist/fake-async-test.js",
"//:node_modules/zone.js/dist/proxy.js",
"//:node_modules/zone.js/dist/jasmine-patch.js",
],
)
+6397 -2618
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -47,7 +47,7 @@
"@angular/platform-server": "^5.2.3",
"@angular/router": "^5.2.3",
"@angular/upgrade": "^5.0.1",
"@bazel/ibazel": "^0.1.1",
"@bazel/ibazel": "0.3.1",
"@google-cloud/storage": "^1.1.1",
"@types/chalk": "^0.4.31",
"@types/fs-extra": "^4.0.3",
+8 -1
View File
@@ -1,6 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_config")
exports_files(["tsconfig-build.json"])
ts_library(
name = "cdk",
@@ -9,3 +10,9 @@ ts_library(
deps = [],
tsconfig = ":tsconfig-build.json",
)
ts_config(
name ="tsconfig_tests",
src = "tsconfig-tests.json",
deps = ["tsconfig-build.json"],
)
+32
View File
@@ -1,12 +1,14 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
sass_library(
name = "a11y_scss_lib",
srcs = glob(["**/_*.scss"]),
)
ng_module(
name = "a11y",
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
@@ -19,3 +21,33 @@ ng_module(
],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "a11y_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":a11y",
"//src/cdk/keycodes",
"//src/cdk/platform",
"//src/cdk/testing",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":a11y_test_sources",
],
)
+27
View File
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "accordion",
@@ -11,3 +13,28 @@ ng_module(
],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "accordion_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":accordion",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":accordion_test_sources",
],
)
+14
View File
@@ -1,5 +1,6 @@
package(default_visibility=["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
# Note: this will need to ng_module if any Angular-specific stuff is added to coercion.
ts_library(
@@ -9,3 +10,16 @@ ts_library(
deps = [],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "coercion_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [":coercion"],
)
ts_web_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
deps = [":coercion_test_sources"],
)
@@ -45,5 +45,4 @@ describe('coerceBooleanProperty', () => {
it('should coerce an array to true', () => {
expect(coerceBooleanProperty([])).toBe(true);
});
});
+27
View File
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "collections",
@@ -8,3 +10,28 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "collections_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":collections",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":collections_test_sources",
],
)
+28
View File
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "layout",
@@ -12,3 +14,29 @@ ng_module(
],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "layout_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":layout",
"//src/cdk/platform",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":layout_test_sources",
],
)
+27
View File
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "observers",
@@ -8,3 +10,28 @@ ng_module(
deps = ["@rxjs", "//src/cdk/coercion"],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "observers_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":observers",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":observers_test_sources",
],
)
+37
View File
@@ -1,5 +1,6 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "overlay",
@@ -16,3 +17,39 @@ ng_module(
],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "overlay_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":overlay",
"//src/cdk/bidi",
"//src/cdk/keycodes",
"//src/cdk/platform",
"//src/cdk/portal",
"//src/cdk/scrolling",
"//src/cdk/testing",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
# TODO(jelbourn): re-enable this when we can specify browser flags
# in order to fix the window size.
tags = ["manual"],
bootstrap = [
"//:web_test_bootstrap_scripts",
],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":overlay_test_sources",
],
)
+4 -1
View File
@@ -330,7 +330,10 @@ describe('Overlay directives', () => {
originX: 'end',
originY: 'bottom',
overlayX: 'start',
overlayY: 'top'
overlayY: 'top',
// TODO(jelbourn) figure out why, when compiling with bazel, these offsets are required.
offsetX: 0,
offsetY: 0,
}];
fixture.componentInstance.isOpen = true;
+26
View File
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "portal",
@@ -8,3 +10,27 @@ ng_module(
deps = ["@rxjs"],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "portal_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":portal",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":portal_test_sources",
],
)
+30
View File
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "scrolling",
@@ -11,3 +13,31 @@ ng_module(
],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "scrolling_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":scrolling",
"//src/cdk/testing",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = [
"//:web_test_bootstrap_scripts",
],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":scrolling_test_sources",
],
)
+27
View File
@@ -1,5 +1,7 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
ng_module(
name = "table",
@@ -11,3 +13,28 @@ ng_module(
],
tsconfig = ":tsconfig-build.json",
)
ts_library(
name = "table_test_sources",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":table",
"//src/cdk/collections",
"@rxjs",
],
tsconfig = ":tsconfig-build.json",
)
ts_web_test(
name = "unit_tests",
bootstrap = ["//:web_test_bootstrap_scripts"],
# Do not sort
deps = [
"//:tslib_bundle",
"//:angular_bundles",
"//:angular_test_bundles",
"//test:angular_test_init",
":table_test_sources",
],
)
+10
View File
@@ -0,0 +1,10 @@
package(default_visibility=["//visibility:public"])
load("@angular//:index.bzl", "ng_module")
ng_module(
name = "testing",
srcs = glob(["**/*.ts"], exclude=["**/*.spec.ts"]),
module_name = "@angular/cdk/testing",
tsconfig = ":tsconfig-test.json",
deps = ["@rxjs"],
)
+15
View File
@@ -0,0 +1,15 @@
// This file exists to be consumed by bazel
{
"extends": "../tsconfig-build",
"files": [
"public-api.ts",
"../typings.d.ts"
],
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"flatModuleOutFile": "index.js",
"flatModuleId": "@angular/cdk/testing",
"skipTemplateCodegen": true
}
}
+1 -1
View File
@@ -22,7 +22,7 @@
"target": "es2015",
"lib": ["es2015", "dom"],
"skipLibCheck": true,
"types": [],
"types": ["jasmine", "tslib"],
"paths": {
"@angular/cdk/*": ["../../dist/packages/cdk/*"]
}
+11
View File
@@ -0,0 +1,11 @@
package(default_visibility=["//visibility:public"])
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
# Common set-up for all Angular Material and CDK tests.
ts_library(
name = "angular_test_init",
testonly = 1,
# This file *must* end with "spec" in order for ts_web_test to load it.
srcs = ["angular-test-init-spec.ts"],
)
+56
View File
@@ -0,0 +1,56 @@
import {TestBed} from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
/* Common setup / initialization for all unit tests in Angular Material and CDK. */
const testBed = TestBed.initTestEnvironment(
[BrowserDynamicTestingModule], platformBrowserDynamicTesting());
patchTestBedToDestroyFixturesAfterEveryTest(testBed);
(window as any).module = {};
(window as any).isNode = false;
(window as any).isBrowser = true;
(window as any).global = window;
/**
* Monkey-patches TestBed.resetTestingModule such that any errors that occur during component
* destruction are thrown instead of silently logged. Also runs TestBed.resetTestingModule after
* each unit test.
*
* Without this patch, the combination of two behaviors is problematic for Angular Material:
* - TestBed.resetTestingModule catches errors thrown on fixture destruction and logs them without
* the errors ever being thrown. This means that any component errors that occur in ngOnDestroy
* can encounter errors silently and still pass unit tests.
* - TestBed.resetTestingModule is only called *before* a test is run, meaning that even *if* the
* aforementioned errors were thrown, they would be reported for the wrong test (the test that's
* about to start, not the test that just finished).
*/
function patchTestBedToDestroyFixturesAfterEveryTest(testBed) {
// Original resetTestingModule function of the TestBed.
const _resetTestingModule = testBed.resetTestingModule;
// Monkey-patch the resetTestingModule to destroy fixtures outside of a try/catch block.
// With https://github.com/angular/angular/commit/2c5a67134198a090a24f6671dcdb7b102fea6eba
// errors when destroying components are no longer causing Jasmine to fail.
testBed.resetTestingModule = function() {
try {
this._activeFixtures.forEach(fixture => fixture.destroy());
} finally {
this._activeFixtures = [];
// Regardless of errors or not, run the original reset testing module function.
_resetTestingModule.call(this);
}
};
// Angular's testing package resets the testing module before each test. This doesn't work well
// for us because it doesn't allow developers to see what test actually failed.
// Fixing this by resetting the testing module after each test.
// https://github.com/angular/angular/blob/master/packages/core/testing/src/before_each.ts#L25
afterEach(() => testBed.resetTestingModule());
}