Skip to content

Commit d3ad095

Browse files
alan-agius4filipesilva
authored andcommitted
refactor(@angular-devkit/architect): remove deprecated TestLogger
BREAKING CHANGE: Deprecated `TestLogger` has been removed. Use `logging` API from `'@angular-devkit/core'` instead. **Note:** this change doesn't effect application developers.
1 parent ab9968d commit d3ad095

File tree

10 files changed

+105
-113
lines changed

10 files changed

+105
-113
lines changed

etc/api/angular_devkit/architect/testing/index.d.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ export declare class TestingArchitectHost implements ArchitectHost {
1414
resolveBuilder(builderName: string): Promise<BuilderInfo | null>;
1515
}
1616

17-
export declare class TestLogger extends logging.Logger {
18-
constructor(name: string, parent?: logging.Logger | null);
19-
clear(): void;
20-
includes(message: string): boolean;
21-
test(re: RegExp): boolean;
22-
}
23-
2417
export declare class TestProjectHost extends NodeJsSyncHost {
2518
protected _templateRoot: Path;
2619
constructor(_templateRoot: Path);

packages/angular_devkit/architect/testing/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
*/
88
export * from './testing-architect-host';
99
export * from './test-project-host';
10-
export * from './test-logger';

packages/angular_devkit/architect/testing/test-logger.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/browser/specs/lazy-module_spec.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*/
88

99
import { Architect } from '@angular-devkit/architect';
10-
import { TestLogger, TestProjectHost } from '@angular-devkit/architect/testing';
10+
import { TestProjectHost } from '@angular-devkit/architect/testing';
11+
import { logging } from '@angular-devkit/core';
1112
import { take, tap, timeout } from 'rxjs/operators';
1213
import {
1314
browserBuild,
@@ -45,12 +46,12 @@ describe('Browser Builder lazy modules', () => {
4546
);
4647
}
4748

48-
function hasMissingModuleError(logger: TestLogger) {
49+
function hasMissingModuleError(logs: string): boolean {
4950
// TS type error when using import().
50-
return logger.includes('Cannot find module') ||
51+
return logs.includes('Cannot find module') ||
5152
// Webpack error when using import() on a rebuild.
5253
// There is no TS error because the type checker is forked on rebuilds.
53-
logger.includes('Module not found');
54+
logs.includes('Module not found');
5455
}
5556

5657
const cases: [string, Record<string, string>][] = [
@@ -96,21 +97,24 @@ describe('Browser Builder lazy modules', () => {
9697
host.writeMultipleFiles(lazyModuleFnImport);
9798
host.replaceInFile('src/app/app.module.ts', 'lazy.module', 'invalid.module');
9899

99-
const logger = new TestLogger('build-lazy-errors');
100+
const logger = new logging.Logger('');
101+
const logs: string[] = [];
102+
logger.subscribe(e => logs.push(e.message));
103+
100104
const run = await architect.scheduleTarget(target, {}, { logger });
101105
const output = await run.result;
102106
expect(output.success).toBe(false);
103-
expect(hasMissingModuleError(logger)).toBe(true, 'Should show missing module error');
107+
expect(hasMissingModuleError(logs.join())).toBe(true, 'Should show missing module error');
104108
});
105109

106110
it('should show error when lazy route is invalid on watch mode AOT', async () => {
107111
host.writeMultipleFiles(lazyModuleFiles);
108112
host.writeMultipleFiles(lazyModuleFnImport);
109113

110114
let buildNumber = 0;
111-
const logger = new TestLogger('rebuild-lazy-errors');
115+
112116
const overrides = { watch: true, aot: true };
113-
const run = await architect.scheduleTarget(target, overrides, { logger });
117+
const run = await architect.scheduleTarget(target, overrides);
114118
await run.output
115119
.pipe(
116120
timeout(15000),
@@ -120,7 +124,6 @@ describe('Browser Builder lazy modules', () => {
120124
case 1:
121125
expect(buildEvent.success).toBe(true);
122126
host.replaceInFile('src/app/app.module.ts', 'lazy.module', 'invalid.module');
123-
logger.clear();
124127
break;
125128
case 2:
126129
expect(buildEvent.success).toBe(false);

packages/angular_devkit/build_angular/src/browser/specs/no-entry-module_spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { Architect } from '@angular-devkit/architect';
10-
import { TestLogger } from '@angular-devkit/architect/testing';
10+
import { logging } from '@angular-devkit/core';
1111
import { browserBuild, createArchitect, host, veEnabled } from '../../test-utils';
1212

1313
describe('Browser Builder no entry module', () => {
@@ -38,8 +38,11 @@ describe('Browser Builder no entry module', () => {
3838
host.replaceInFile('src/main.ts', /./g, '');
3939
host.appendToFile('src/main.ts', `import './app/app.module';`);
4040

41-
const logger = new TestLogger('no-bootstrap');
41+
const logger = new logging.Logger('');
42+
const logs: string[] = [];
43+
logger.subscribe(e => logs.push(e.message));
44+
4245
await browserBuild(architect, host, target, { baseHref: '/myUrl' }, { logger });
43-
expect(logger.includes('Lazy routes discovery is not enabled')).toBe(true);
46+
expect(logs.join().includes('Lazy routes discovery is not enabled')).toBe(true);
4447
});
4548
});

packages/angular_devkit/build_angular/src/browser/specs/rebuild_spec.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
*/
88
// tslint:disable:no-big-function
99
import { Architect } from '@angular-devkit/architect';
10-
import { TestLogger } from '@angular-devkit/architect/testing';
11-
import { join, normalize, virtualFs } from '@angular-devkit/core';
10+
import { join, logging, normalize, virtualFs } from '@angular-devkit/core';
1211
import { debounceTime, take, takeWhile, tap } from 'rxjs/operators';
1312
import {
1413
createArchitect,
@@ -154,7 +153,10 @@ describe('Browser Builder rebuilds', () => {
154153
);
155154

156155
const overrides = { watch: true, forkTypeChecker: false };
157-
const logger = new TestLogger('rebuild-type-errors');
156+
const logger = new logging.Logger('');
157+
let logs: string[] = [];
158+
logger.subscribe(e => logs.push(e.message));
159+
158160
const typeError = `is not assignable to parameter of type 'number'`;
159161
let buildNumber = 0;
160162

@@ -177,8 +179,8 @@ describe('Browser Builder rebuilds', () => {
177179
case 2:
178180
// The second build should error out with a type error on the type of an argument.
179181
expect(buildEvent.success).toBe(false);
180-
expect(logger.includes(typeError)).toBe(true);
181-
logger.clear();
182+
expect(logs.join().includes(typeError)).toBe(true);
183+
logs = [];
182184
// Change an UNRELATED file and the error should still happen.
183185
// Should trigger a rebuild, this time an error is also expected.
184186
host.appendToFile('src/app/app.module.ts', `console.log(1);`);
@@ -187,8 +189,8 @@ describe('Browser Builder rebuilds', () => {
187189
case 3:
188190
// The third build should have the same error as the first.
189191
expect(buildEvent.success).toBe(false);
190-
expect(logger.includes(typeError)).toBe(true);
191-
logger.clear();
192+
expect(logs.join().includes(typeError)).toBe(true);
193+
logs = [];
192194
// Fix the error.
193195
host.writeMultipleFiles({
194196
'src/funky2.ts': `export const funky2 = (value: string) => value + 'hello';`,
@@ -350,7 +352,9 @@ describe('Browser Builder rebuilds', () => {
350352
// show up in getNgSemanticDiagnostics. Since getNgSemanticDiagnostics is only called on the
351353
// type checker, we must disable it to get a failing fourth build with Ivy.
352354
const overrides = { watch: true, aot: true, forkTypeChecker: veEnabled };
353-
const logger = new TestLogger('rebuild-aot-errors');
355+
const logger = new logging.Logger('');
356+
let logs: string[] = [];
357+
logger.subscribe(e => logs.push(e.message));
354358
const staticAnalysisError = !veEnabled
355359
? 'selector must be a string'
356360
: 'Function expressions are not supported in decorators';
@@ -367,30 +371,30 @@ describe('Browser Builder rebuilds', () => {
367371
case 1:
368372
// The first build should error out with a static analysis error.
369373
expect(buildEvent.success).toBe(false, 'First build should not succeed.');
370-
expect(logger.includes(staticAnalysisError)).toBe(true,
374+
expect(logs.join().includes(staticAnalysisError)).toBe(true,
371375
'First build should have static analysis error.');
372-
logger.clear();
376+
logs = [];
373377
// Fix the static analysis error.
374378
host.writeMultipleFiles({ 'src/app/app.component.ts': origContent });
375379
break;
376380

377381
case 2:
378382
expect(buildEvent.success).toBe(true, 'Second build should succeed.');
379-
expect(logger.includes(staticAnalysisError)).toBe(false,
383+
expect(logs.join().includes(staticAnalysisError)).toBe(false,
380384
'Second build should not have static analysis error.');
381-
logger.clear();
385+
logs = [];
382386
// Add an syntax error to a non-main file.
383387
host.appendToFile('src/app/app.component.ts', `]]]`);
384388
break;
385389

386390
case 3:
387391
// The third build should have TS syntax error.
388392
expect(buildEvent.success).toBe(false, 'Third build should not succeed.');
389-
expect(logger.includes(syntaxError)).toBe(true,
393+
expect(logs.join().includes(syntaxError)).toBe(true,
390394
'Third build should have syntax analysis error.');
391-
expect(logger.includes(staticAnalysisError)).toBe(false,
395+
expect(logs.join().includes(staticAnalysisError)).toBe(false,
392396
'Third build should not have static analysis error.');
393-
logger.clear();
397+
logs = [];
394398
// Fix the syntax error, but add the static analysis error again.
395399
host.writeMultipleFiles({
396400
'src/app/app.component.ts': origContent.replace(
@@ -402,21 +406,21 @@ describe('Browser Builder rebuilds', () => {
402406

403407
case 4:
404408
expect(buildEvent.success).toBe(false, 'Fourth build should not succeed.');
405-
expect(logger.includes(syntaxError)).toBe(false,
409+
expect(logs.join().includes(syntaxError)).toBe(false,
406410
'Fourth build should not have syntax analysis error.');
407-
expect(logger.includes(staticAnalysisError)).toBe(true,
411+
expect(logs.join().includes(staticAnalysisError)).toBe(true,
408412
'Fourth build should have static analysis error.');
409-
logger.clear();
413+
logs = [];
410414
// Restore the file to a error-less state.
411415
host.writeMultipleFiles({ 'src/app/app.component.ts': origContent });
412416
break;
413417

414418
case 5:
415419
// The fifth build should have everything fixed..
416420
expect(buildEvent.success).toBe(true, 'Fifth build should succeed.');
417-
expect(logger.includes(syntaxError)).toBe(false,
421+
expect(logs.join().includes(syntaxError)).toBe(false,
418422
'Fifth build should not have syntax analysis error.');
419-
expect(logger.includes(staticAnalysisError)).toBe(false,
423+
expect(logs.join().includes(staticAnalysisError)).toBe(false,
420424
'Fifth build should not have static analysis error.');
421425
break;
422426
}

packages/angular_devkit/build_angular/src/browser/specs/replacements_spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
*/
88

99
import { Architect } from '@angular-devkit/architect';
10-
import { TestLogger } from '@angular-devkit/architect/testing';
11-
import { normalize, virtualFs } from '@angular-devkit/core';
10+
import { logging, normalize, virtualFs } from '@angular-devkit/core';
1211
import { of, race } from 'rxjs';
1312
import { delay, filter, map, take, takeUntil, takeWhile, tap, timeout } from 'rxjs/operators';
1413
import { browserBuild, createArchitect, host } from '../../test-utils';
@@ -179,7 +178,8 @@ describe('Browser Builder file replacements', () => {
179178

180179
const unexpectedError = `Property 'two' does not exist on type '{ one: number; }'`;
181180
const expectedError = `Property 'prop' does not exist on type '{}'`;
182-
const logger = new TestLogger('rebuild-type-errors');
181+
182+
const logger = new logging.Logger('');
183183

184184
// Race between a timeout and the expected log entry.
185185
const stop$ = race<null | string>(

0 commit comments

Comments
 (0)