test(common): run common/http tests with Bazel (#24738)

@angular/common/http had tests which were not executed in Bazel. This
commit adds a BUILD.bazel file and ensures the tests pass.

PR Close #24738
This commit is contained in:
Alex Rickabaugh 2018-06-29 11:55:55 -07:00 committed by Matias Niemelä
parent ee50ee493d
commit d05d28629d
2 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,35 @@
load("//tools:defaults.bzl", "ts_library", "ts_web_test_suite")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(
["**/*.ts"],
exclude = ["**/*_node_only_spec.ts"],
),
deps = [
"//packages/common/http",
"//packages/common/http/testing",
"//packages/core",
"//packages/core/testing",
"@rxjs",
"@rxjs//operators",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular/tools/testing/init_node_spec.js"],
deps = [
":test_lib",
"//tools/testing:node",
],
)
ts_web_test_suite(
name = "test_web",
deps = [
":test_lib",
],
)

View File

@ -76,13 +76,17 @@ class SampleTokenExtractor {
it('does not re-parse if document.cookie has not changed', () => { it('does not re-parse if document.cookie has not changed', () => {
expect(extractor.getToken()).toEqual('test'); expect(extractor.getToken()).toEqual('test');
expect(extractor.getToken()).toEqual('test'); expect(extractor.getToken()).toEqual('test');
expect(extractor.parseCount).toEqual(1); expect(getParseCount(extractor)).toEqual(1);
}); });
it('re-parses if document.cookie changes', () => { it('re-parses if document.cookie changes', () => {
expect(extractor.getToken()).toEqual('test'); expect(extractor.getToken()).toEqual('test');
document['cookie'] = 'XSRF-TOKEN=blah'; document['cookie'] = 'XSRF-TOKEN=blah';
expect(extractor.getToken()).toEqual('blah'); expect(extractor.getToken()).toEqual('blah');
expect(extractor.parseCount).toEqual(2); expect(getParseCount(extractor)).toEqual(2);
}); });
}); });
} }
function getParseCount(extractor: HttpXsrfCookieExtractor): number {
return (extractor as any).parseCount;
}