Skip to content

Commit 636874b

Browse files
committed
Merge remote-tracking branch 'origin/angular-eos-upgrades-prerelease' into angular-eos-upgrades-trunk
2 parents b276960 + ff90a9b commit 636874b

15 files changed

Lines changed: 63 additions & 69 deletions

angular.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,11 @@
274274
"test": {
275275
"builder": "@angular-devkit/build-angular:karma",
276276
"options": {
277+
"builderMode": "application",
277278
"main": "projects/request/src/test.ts",
278279
"karmaConfig": "projects/request/karma.conf.js",
279280
"tsConfig": "projects/request/tsconfig.spec.json",
281+
"include": ["projects/request/src/**/*.spec.ts"],
280282
"scripts": []
281283
}
282284
}

projects/request/karma.conf.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ module.exports = function (config) {
1414
],
1515
client: {
1616
jasmine: {
17-
// you can add configuration options for Jasmine here
18-
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19-
// for example, you can disable the random execution with `random: false`
20-
// or set a specific seed with `seed: 4321`
17+
random: false,
18+
timeoutInterval: 10000,
2119
},
2220
clearContext: false // leave Jasmine Spec Runner output visible in browser
2321
},
@@ -37,8 +35,11 @@ module.exports = function (config) {
3735
colors: true,
3836
logLevel: config.LOG_INFO,
3937
autoWatch: true,
40-
browsers: ['Chrome'],
38+
browsers: ['ChromeHeadless'],
4139
singleRun: false,
42-
restartOnFileChange: true
40+
restartOnFileChange: true,
41+
browserNoActivityTimeout: 120000,
42+
browserDisconnectTimeout: 30000,
43+
browserDisconnectTolerance: 3,
4344
});
4445
};

projects/request/ng-package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"dest": "../../dist/request",
44
"lib": {
55
"entryFile": "src/public-api.ts"
6-
},
7-
"allowedNonPeerDependencies": [
8-
"lodash"
9-
]
6+
}
107
}

projects/request/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
"name": "request",
33
"version": "0.0.1",
44
"peerDependencies": {
5-
"@angular/common": "^17.0.0 || ^18.0.0 || ^19.0.0",
6-
"@angular/core": "^17.0.0 || ^18.0.0 || ^19.0.0"
5+
"@angular/common": "^18.0.0 || ^19.0.0",
6+
"@angular/core": "^18.0.0 || ^19.0.0"
77
},
88
"dependencies": {
9-
"lodash-es": "^4.17.21",
109
"tslib": "^2.3.0"
1110
}
1211
}

projects/request/src/lib/request.module.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { TestBed } from '@angular/core/testing';
2+
import { provideHttpClient } from '@angular/common/http';
3+
import { provideHttpClientTesting } from '@angular/common/http/testing';
24
import { RequestModule } from './request.module';
35

46
describe('RequestModule', () => {
@@ -12,6 +14,10 @@ describe('RequestModule', () => {
1214
prefixUrl: 'TEST',
1315
}),
1416
],
17+
providers: [
18+
provideHttpClient(),
19+
provideHttpClientTesting(),
20+
],
1521
});
1622

1723
requestModule = TestBed.inject(RequestModule);

projects/request/src/lib/request.module.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
22
import { RequestConfig, RequestService } from './request.service';
3-
import { HttpClientModule } from '@angular/common/http';
43

54
@NgModule({
6-
imports: [
7-
HttpClientModule,
8-
],
95
providers: [
106
RequestService,
117
],
12-
exports: [
13-
HttpClientModule,
14-
],
158
})
169
export class RequestModule {
1710
constructor(@Optional() @SkipSelf() parentModule: RequestModule) {

projects/request/src/lib/request.service.spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {
66

77
import {
88
HttpTestingController,
9-
HttpClientTestingModule,
9+
provideHttpClientTesting,
1010
} from '@angular/common/http/testing';
11+
import { provideHttpClient } from '@angular/common/http';
1112

1213
import { RequestService, RequestConfig, DevModeService, QueryEncoder } from './request.service';
1314
import { Router } from '@angular/router';
@@ -68,12 +69,12 @@ describe('RequestService', () => {
6869
let mockBackend: HttpTestingController;
6970
let requestConfigSpy: RequestConfig;
7071
let devModeServiceSpy: DevModeService;
71-
let storageSpy: BrowserStorageService;
7272

7373
beforeEach(async () => {
7474
TestBed.configureTestingModule({
75-
imports: [HttpClientTestingModule],
7675
providers: [
76+
provideHttpClient(),
77+
provideHttpClientTesting(),
7778
RequestService,
7879
DevModeService,
7980
{
@@ -102,7 +103,6 @@ describe('RequestService', () => {
102103
mockBackend = TestBed.inject(HttpTestingController);
103104
requestConfigSpy = TestBed.inject(RequestConfig);
104105
devModeServiceSpy = TestBed.inject(DevModeService);
105-
storageSpy = TestBed.inject(BrowserStorageService);
106106
});
107107

108108
it('should be created', () => {
@@ -130,15 +130,16 @@ describe('RequestService', () => {
130130
mockBackend.verify();
131131
}));
132132

133-
it('should update apikey if new apikey exist', () => {
134-
let res = { body: true, apikey: 'testapikey' };
133+
it('should pass through response with custom headers', () => {
134+
let res: any;
135135
service.get(testURL, { headers: { some: 'keys' } }).subscribe(_res => {
136136
res = _res;
137137
});
138138
const req = mockBackend.expectOne({ method: 'GET' });
139-
req.flush(res);
139+
req.flush({ body: true, apikey: 'testapikey' });
140140

141-
expect(storageSpy.setUser).toHaveBeenCalledWith({ apikey: res.apikey });
141+
expect(res).toEqual({ body: true, apikey: 'testapikey' });
142+
expect(req.request.headers.get('Content-Type')).toBe('application/json');
142143
mockBackend.verify();
143144
});
144145

@@ -160,7 +161,7 @@ describe('RequestService', () => {
160161
const req = mockBackend.expectOne({ url: testURL, method: 'GET' }).flush(ERR_MESSAGE, err);
161162

162163
expect(res).toBeUndefined();
163-
expect(errRes).toEqual(ERR_MESSAGE);
164+
expect(errRes.error).toEqual(ERR_MESSAGE);
164165
mockBackend.verify();
165166

166167
}));
@@ -242,6 +243,7 @@ describe('RequestService', () => {
242243
const req = mockBackend.expectOne({ url: testURL, method: 'POST' }).flush(ERR_MESSAGE, err);
243244

244245
expect(res).toBeUndefined();
246+
expect(errRes.error).toEqual(ERR_MESSAGE);
245247
mockBackend.verify();
246248
}));
247249
});
@@ -308,7 +310,7 @@ describe('RequestService', () => {
308310
const req = mockBackend.expectOne({ url: `https://${PREFIX_URL}/${testURL}`, method: 'PUT' }).flush(ERR_MESSAGE, err);
309311

310312
expect(res).toBeUndefined();
311-
expect(errRes).toEqual(ERR_MESSAGE);
313+
expect(errRes.error).toEqual(ERR_MESSAGE);
312314
mockBackend.verify();
313315
}));
314316
});
@@ -354,7 +356,7 @@ describe('RequestService', () => {
354356

355357
expect(res).toBeUndefined();
356358
expect(console.error).not.toHaveBeenCalled();
357-
expect(errRes).toEqual(ERR_MESSAGE);
359+
expect(errRes.error).toEqual(ERR_MESSAGE);
358360
mockBackend.verify();
359361
}));
360362
});
@@ -400,7 +402,7 @@ describe('RequestService', () => {
400402
},
401403
_err => {
402404
errRes = _err;
403-
expect(errRes).toEqual(ERR_MESSAGE);
405+
expect(errRes.error).toEqual(ERR_MESSAGE);
404406
}
405407
);
406408

@@ -415,7 +417,7 @@ describe('RequestService', () => {
415417
_res => _res,
416418
_err => {
417419
errRes = _err;
418-
expect(errRes.message).toEqual(badKey);
420+
expect(errRes.error.message).toEqual(badKey);
419421
}
420422
);
421423

projects/request/src/lib/request.service.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import { Router } from '@angular/router';
1010
import { Observable, of, throwError } from 'rxjs';
1111
import { catchError, concatMap } from 'rxjs/operators';
12-
import { has, isEmpty, each } from 'lodash-es';
1312

1413
interface RequestOptions {
1514
headers?: any;
@@ -92,9 +91,9 @@ export class RequestService {
9291
*/
9392
setParams(options: {[key:string]: any}) {
9493
let params: any;
95-
if (!isEmpty(options)) {
94+
if (options && Object.keys(options).length > 0) {
9695
params = new HttpParams();
97-
each(options, (value, key) => {
96+
Object.entries(options).forEach(([key, value]) => {
9897
params = params.append(key, value);
9998
});
10099
}
@@ -122,13 +121,13 @@ export class RequestService {
122121
httpOptions = {};
123122
}
124123

125-
if (!has(httpOptions, 'headers')) {
124+
if (!('headers' in httpOptions)) {
126125
httpOptions.headers = '';
127126
}
128-
if (!has(httpOptions, 'params')) {
127+
if (!('params' in httpOptions)) {
129128
httpOptions.params = '';
130129
}
131-
if (!has(httpOptions, 'observe')) {
130+
if (!('observe' in httpOptions)) {
132131
httpOptions.observe = 'body';
133132
}
134133

@@ -149,10 +148,10 @@ export class RequestService {
149148
params.httpOptions = {};
150149
}
151150

152-
if (!has(params.httpOptions, 'headers')) {
151+
if (!('headers' in params.httpOptions)) {
153152
params.httpOptions.headers = '';
154153
}
155-
if (!has(params.httpOptions, 'params')) {
154+
if (!('params' in params.httpOptions)) {
156155
params.httpOptions.params = '';
157156
}
158157

@@ -179,10 +178,10 @@ export class RequestService {
179178
httpOptions = {};
180179
}
181180

182-
if (!has(httpOptions, 'headers')) {
181+
if (!('headers' in httpOptions)) {
183182
httpOptions.headers = '';
184183
}
185-
if (!has(httpOptions, 'params')) {
184+
if (!('params' in httpOptions)) {
186185
httpOptions.params = '';
187186
}
188187

@@ -203,10 +202,10 @@ export class RequestService {
203202
*
204203
*/
205204
delete(endPoint: string, httpOptions: RequestOptions = {}): Observable<any> {
206-
if (!has(httpOptions, 'headers')) {
205+
if (!('headers' in httpOptions)) {
207206
httpOptions.headers = '';
208207
}
209-
if (!has(httpOptions, 'params')) {
208+
if (!('params' in httpOptions)) {
210209
httpOptions.params = '';
211210
}
212211

@@ -245,11 +244,11 @@ export class RequestService {
245244
}
246245

247246
// log the user out if jwt expired
248-
if (has(error, 'error.message') && [
247+
if (error?.error?.message && [
249248
'Request must contain an apikey',
250249
'Expired apikey',
251250
'Invalid apikey'
252-
].includes(error?.error?.message) && !this.loggedOut) {
251+
].includes(error.error.message) && !this.loggedOut) {
253252
// in case lots of api returns the same apikey invalid at the same time
254253
this.loggedOut = true;
255254
setTimeout(

projects/request/src/test.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
1+
// this file is required by karma.conf.js and loads recursively all the .spec and framework files
22

3+
import '@angular/localize/init';
34
import 'zone.js';
45
import 'zone.js/testing';
56
import { getTestBed } from '@angular/core/testing';
@@ -8,20 +9,9 @@ import {
89
platformBrowserDynamicTesting
910
} from '@angular/platform-browser-dynamic/testing';
1011

11-
declare const require: {
12-
context(path: string, deep?: boolean, filter?: RegExp): {
13-
<T>(id: string): T;
14-
keys(): string[];
15-
};
16-
};
17-
18-
// First, initialize the Angular testing environment.
12+
// first, initialize the angular testing environment.
1913
getTestBed().initTestEnvironment(
2014
BrowserDynamicTestingModule,
2115
platformBrowserDynamicTesting(),
16+
{ teardown: { destroyAfterEach: true } }
2217
);
23-
24-
// Then we find all the tests.
25-
const context = require.context('./', true, /\.spec\.ts$/);
26-
// And load the modules.
27-
context.keys().map(context);

projects/request/tsconfig.lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
1+
/* To learn more about this file see: https://angular.dev/reference/configs/workspace-config#tsconfig. */
22
{
33
"extends": "../../tsconfig.json",
44
"compilerOptions": {

0 commit comments

Comments
 (0)