Skip to content

Commit

Permalink
bazel test src:test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Aug 28, 2018
1 parent 50b242f commit ed56381
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +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_suite")

ng_module(
name = "src",
Expand Down Expand Up @@ -32,3 +33,31 @@ ts_devserver(
],
deps = [":src"],
)

ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":src",
"@angular//packages/core/testing",
"@angular//packages/platform-browser-dynamic/testing",
],
)

ts_web_test_suite(
name = "test",
srcs = ["//:node_modules/tslib/tslib.js"],
# do not sort
bootstrap = [
"//:node_modules/zone.js/dist/zone-testing-bundle.js",
"//:node_modules/reflect-metadata/Reflect.js",
],
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
"@io_bazel_rules_webtesting//browsers:firefox-local",
],
deps = [
":test_lib",
],
)
10 changes: 10 additions & 0 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';

import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';

// TODO(alexeagle): this helper should be in @angular/platform-browser-dynamic/testing
try {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
} catch {
// Ignore exceptions when calling it multiple times.
}

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
Expand Down

0 comments on commit ed56381

Please sign in to comment.