build: add bazel test rules for remainder of packages (#21053)
PR Close #21053
This commit is contained in:
39
packages/http/test/BUILD.bazel
Normal file
39
packages/http/test/BUILD.bazel
Normal file
@ -0,0 +1,39 @@
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test")
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")
|
||||
|
||||
ts_library(
|
||||
name = "test_lib",
|
||||
testonly = 1,
|
||||
srcs = glob(["**/*.ts"]),
|
||||
tsconfig = "//packages:tsconfig",
|
||||
deps = [
|
||||
"//packages/core",
|
||||
"//packages/core/testing",
|
||||
"//packages/http",
|
||||
"//packages/http/testing",
|
||||
"//packages/platform-browser",
|
||||
"//packages/platform-browser/testing",
|
||||
"@rxjs",
|
||||
],
|
||||
)
|
||||
|
||||
jasmine_node_test(
|
||||
name = "test",
|
||||
bootstrap = ["angular_src/packages/_testing_init/init_node_spec.js"],
|
||||
deps = [
|
||||
":test_lib",
|
||||
"//packages/_testing_init:node",
|
||||
],
|
||||
)
|
||||
|
||||
ts_web_test(
|
||||
name = "test_web",
|
||||
bootstrap = [
|
||||
"//:angular_bootstrap_scripts",
|
||||
],
|
||||
# do not sort
|
||||
deps = [
|
||||
"//packages/_testing_init:browser",
|
||||
":test_lib",
|
||||
],
|
||||
)
|
@ -8,13 +8,14 @@
|
||||
|
||||
import {Injector} from '@angular/core';
|
||||
import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {BrowserJsonp} from '@angular/http/src/backends/browser_jsonp';
|
||||
import {JSONPBackend, JSONPConnection} from '@angular/http/src/backends/jsonp_backend';
|
||||
import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options';
|
||||
import {ReadyState, RequestMethod, ResponseType} from '@angular/http/src/enums';
|
||||
import {Request} from '@angular/http/src/static_request';
|
||||
import {Response} from '@angular/http/src/static_response';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
import {BrowserJsonp} from '../../src/backends/browser_jsonp';
|
||||
import {JSONPBackend, JSONPConnection} from '../../src/backends/jsonp_backend';
|
||||
import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options';
|
||||
import {ReadyState, RequestMethod, ResponseType} from '../../src/enums';
|
||||
import {Request} from '../../src/static_request';
|
||||
|
||||
let existingScripts: MockBrowserJsonp[] = [];
|
||||
|
||||
@ -75,10 +76,10 @@ class MockBrowserJsonp extends BrowserJsonp {
|
||||
describe('JSONPConnection', () => {
|
||||
it('should use the injected BaseResponseOptions to create the response',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const connection = new JSONPConnection(
|
||||
const connection = new (JSONPConnection as any)(
|
||||
sampleRequest, new MockBrowserJsonp(),
|
||||
new ResponseOptions({type: ResponseType.Error}));
|
||||
connection.response.subscribe(res => {
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.type).toBe(ResponseType.Error);
|
||||
async.done();
|
||||
});
|
||||
@ -88,7 +89,7 @@ class MockBrowserJsonp extends BrowserJsonp {
|
||||
|
||||
it('should ignore load/callback when disposed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp());
|
||||
const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
|
||||
const spy = new SpyObject();
|
||||
const loadSpy = spy.spy('load');
|
||||
const errorSpy = spy.spy('error');
|
||||
@ -111,13 +112,13 @@ class MockBrowserJsonp extends BrowserJsonp {
|
||||
|
||||
it('should report error if loaded without invoking callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp());
|
||||
const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
(res: Response) => {
|
||||
expect('response listener called').toBe(false);
|
||||
async.done();
|
||||
},
|
||||
err => {
|
||||
(err: Response) => {
|
||||
expect(err.text()).toEqual('JSONP injected script did not invoke callback.');
|
||||
async.done();
|
||||
});
|
||||
@ -127,14 +128,14 @@ class MockBrowserJsonp extends BrowserJsonp {
|
||||
|
||||
it('should report error if script contains error',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp());
|
||||
const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
|
||||
|
||||
connection.response.subscribe(
|
||||
res => {
|
||||
(res: Response) => {
|
||||
expect('response listener called').toBe(false);
|
||||
async.done();
|
||||
},
|
||||
err => {
|
||||
(err: Response) => {
|
||||
expect(err.text()).toBe('Oops!');
|
||||
async.done();
|
||||
});
|
||||
@ -149,16 +150,18 @@ class MockBrowserJsonp extends BrowserJsonp {
|
||||
const base = new BaseRequestOptions();
|
||||
const req = new Request(base.merge(
|
||||
new RequestOptions({url: 'https://google.com', method: method})) as any);
|
||||
expect(() => new JSONPConnection(req, new MockBrowserJsonp()).response.subscribe())
|
||||
expect(
|
||||
() => new (JSONPConnection as any)(req, new MockBrowserJsonp())
|
||||
.response.subscribe())
|
||||
.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
it('should respond with data passed to callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp());
|
||||
const connection = new (JSONPConnection as any)(sampleRequest, new MockBrowserJsonp());
|
||||
|
||||
connection.response.subscribe(res => {
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.json()).toEqual(({fake_payload: true, blob_id: 12345}));
|
||||
async.done();
|
||||
});
|
||||
|
@ -8,15 +8,14 @@
|
||||
|
||||
import {Injector} from '@angular/core';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it, xit} from '@angular/core/testing/src/testing_internal';
|
||||
import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options';
|
||||
import {Request} from '@angular/http/src/static_request';
|
||||
import {Response} from '@angular/http/src/static_response';
|
||||
import {MockBackend, MockConnection} from '@angular/http/testing/src/mock_backend';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
import {ReplaySubject} from 'rxjs/ReplaySubject';
|
||||
|
||||
import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options';
|
||||
import {Request} from '../../src/static_request';
|
||||
import {Response} from '../../src/static_response';
|
||||
import {MockBackend, MockConnection} from '../../testing/src/mock_backend';
|
||||
|
||||
{
|
||||
describe('MockBackend', () => {
|
||||
|
||||
|
@ -8,17 +8,17 @@
|
||||
|
||||
import {Injectable} from '@angular/core';
|
||||
import {AsyncTestCompleter, SpyObject, afterEach, beforeEach, beforeEachProviders, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {BrowserXhr} from '@angular/http/src/backends/browser_xhr';
|
||||
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '@angular/http/src/backends/xhr_backend';
|
||||
import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from '@angular/http/src/base_response_options';
|
||||
import {ResponseContentType, ResponseType} from '@angular/http/src/enums';
|
||||
import {Headers} from '@angular/http/src/headers';
|
||||
import {XSRFStrategy} from '@angular/http/src/interfaces';
|
||||
import {Request} from '@angular/http/src/static_request';
|
||||
import {Response} from '@angular/http/src/static_response';
|
||||
import {URLSearchParams} from '@angular/http/src/url_search_params';
|
||||
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
import {BrowserXhr} from '../../src/backends/browser_xhr';
|
||||
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from '../../src/backends/xhr_backend';
|
||||
import {BaseRequestOptions, RequestOptions} from '../../src/base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from '../../src/base_response_options';
|
||||
import {ResponseContentType, ResponseType} from '../../src/enums';
|
||||
import {Headers} from '../../src/headers';
|
||||
import {XSRFStrategy} from '../../src/interfaces';
|
||||
import {Request} from '../../src/static_request';
|
||||
import {Response} from '../../src/static_response';
|
||||
import {URLSearchParams} from '../../src/url_search_params';
|
||||
|
||||
let abortSpy: any;
|
||||
let sendSpy: any;
|
||||
@ -422,7 +422,7 @@ class MockBrowserXHR extends BrowserXhr {
|
||||
(res: Response) => {
|
||||
|
||||
},
|
||||
errRes => {
|
||||
(errRes: Response) => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
async.done();
|
||||
});
|
||||
@ -444,7 +444,7 @@ class MockBrowserXHR extends BrowserXhr {
|
||||
nextCalled = true;
|
||||
expect(res.status).toBe(statusCode);
|
||||
},
|
||||
errRes => { errorCalled = true; },
|
||||
(errRes: Response) => { errorCalled = true; },
|
||||
() => {
|
||||
expect(nextCalled).toBe(true);
|
||||
expect(errorCalled).toBe(false);
|
||||
@ -461,7 +461,7 @@ class MockBrowserXHR extends BrowserXhr {
|
||||
const connection = new XHRConnection(
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(res => {
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.ok).toBe(true);
|
||||
async.done();
|
||||
});
|
||||
@ -477,8 +477,8 @@ class MockBrowserXHR extends BrowserXhr {
|
||||
sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode}));
|
||||
|
||||
connection.response.subscribe(
|
||||
res => { throw 'should not be called'; },
|
||||
errRes => {
|
||||
(res: Response) => { throw 'should not be called'; },
|
||||
(errRes: Response) => {
|
||||
expect(errRes.ok).toBe(false);
|
||||
async.done();
|
||||
});
|
||||
@ -497,7 +497,7 @@ class MockBrowserXHR extends BrowserXhr {
|
||||
|
||||
connection.response.subscribe(
|
||||
(res: Response) => { nextCalled = true; },
|
||||
errRes => {
|
||||
(errRes: Response) => {
|
||||
expect(errRes.status).toBe(statusCode);
|
||||
expect(nextCalled).toBe(false);
|
||||
async.done();
|
||||
@ -553,8 +553,8 @@ class MockBrowserXHR extends BrowserXhr {
|
||||
connection1.response.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe(responseBody);
|
||||
|
||||
connection2.response.subscribe(ress => {
|
||||
expect(ress.text()).toBe(responseBody);
|
||||
connection2.response.subscribe((res: Response) => {
|
||||
expect(res.text()).toBe(responseBody);
|
||||
async.done();
|
||||
});
|
||||
existingXHRs[1].setStatusCode(200);
|
||||
|
@ -7,9 +7,9 @@
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {BaseRequestOptions, RequestOptions} from '../src/base_request_options';
|
||||
import {RequestMethod} from '../src/enums';
|
||||
import {Headers} from '../src/headers';
|
||||
import {BaseRequestOptions, RequestOptions} from '@angular/http/src/base_request_options';
|
||||
import {RequestMethod} from '@angular/http/src/enums';
|
||||
import {Headers} from '@angular/http/src/headers';
|
||||
|
||||
{
|
||||
describe('BaseRequestOptions', () => {
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Headers} from '../src/headers';
|
||||
import {Headers} from '@angular/http/src/headers';
|
||||
|
||||
{
|
||||
describe('Headers', () => {
|
||||
|
@ -9,12 +9,12 @@
|
||||
import {Injector} from '@angular/core';
|
||||
import {TestBed, getTestBed} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, afterEach, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {stringToArrayBuffer} from '@angular/http/src/http_utils';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {zip} from 'rxjs/observable/zip';
|
||||
|
||||
import {BaseRequestOptions, ConnectionBackend, Http, HttpModule, JSONPBackend, Jsonp, JsonpModule, Request, RequestMethod, RequestOptions, Response, ResponseContentType, ResponseOptions, URLSearchParams, XHRBackend} from '../index';
|
||||
import {stringToArrayBuffer} from '../src/http_utils';
|
||||
import {MockBackend, MockConnection} from '../testing/src/mock_backend';
|
||||
|
||||
{
|
||||
|
@ -7,14 +7,13 @@
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {RequestOptions} from '@angular/http/src/base_request_options';
|
||||
import {ContentType} from '@angular/http/src/enums';
|
||||
import {Headers} from '@angular/http/src/headers';
|
||||
import {stringToArrayBuffer, stringToArrayBuffer8} from '@angular/http/src/http_utils';
|
||||
import {ArrayBuffer, Request} from '@angular/http/src/static_request';
|
||||
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
|
||||
import {RequestOptions} from '../src/base_request_options';
|
||||
import {ContentType} from '../src/enums';
|
||||
import {Headers} from '../src/headers';
|
||||
import {stringToArrayBuffer, stringToArrayBuffer8} from '../src/http_utils';
|
||||
import {ArrayBuffer, Request} from '../src/static_request';
|
||||
|
||||
{
|
||||
describe('Request', () => {
|
||||
describe('detectContentType', () => {
|
||||
|
@ -8,8 +8,8 @@
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {ResponseOptions} from '../src/base_response_options';
|
||||
import {Response} from '../src/static_response';
|
||||
import {ResponseOptions} from '@angular/http/src/base_response_options';
|
||||
import {Response} from '@angular/http/src/static_response';
|
||||
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {URLSearchParams} from '../src/url_search_params';
|
||||
import {URLSearchParams} from '@angular/http/src/url_search_params';
|
||||
|
||||
{
|
||||
describe('URLSearchParams', () => {
|
||||
|
Reference in New Issue
Block a user