Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8ad0f9

Browse files
clydinalan-agius4
authored andcommitted
refactor(@schematics/angular): remove unneeded getFileContent unit-test helper
Some schematic unit-tests were using the `getFileContent` helper utility that was no longer needed due to a `Tree` now containing a `readText` method. All usages of the helper and the helper itself have now been removed.
1 parent aace49e commit f8ad0f9

File tree

5 files changed

+14
-36
lines changed

5 files changed

+14
-36
lines changed

‎packages/schematics/angular/library/index_spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88

99
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
1010
import { parse as parseJson } from 'jsonc-parser';
11-
import { getFileContent } from '../../angular/utility/test';
1211
import { Schema as ComponentOptions } from '../component/schema';
1312
import { latestVersions } from '../utility/latest-versions';
1413
import { Schema as WorkspaceOptions } from '../workspace/schema';
1514
import { Schema as GenerateLibrarySchema } from './schema';
1615

1716
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1817
function getJsonFileContent(tree: UnitTestTree, path: string): any {
19-
return parseJson(tree.readContent(path).toString());
18+
return tree.readJson(path);
2019
}
2120

2221
describe('Library Schematic', () => {
@@ -119,7 +118,7 @@ describe('Library Schematic', () => {
119118
it('should create a package.json named "foo"', async () => {
120119
const tree = await schematicRunner.runSchematic('library', defaultOptions, workspaceTree);
121120

122-
const fileContent = getFileContent(tree,'/projects/foo/package.json');
121+
const fileContent = tree.readText('/projects/foo/package.json');
123122
expect(fileContent).toMatch(/"name":"foo"/);
124123
});
125124

@@ -134,14 +133,14 @@ describe('Library Schematic', () => {
134133
it('should add sideEffects: false flag to package.json named "foo"', async () => {
135134
const tree = await schematicRunner.runSchematic('library', defaultOptions, workspaceTree);
136135

137-
const fileContent = getFileContent(tree,'/projects/foo/package.json');
136+
const fileContent = tree.readText('/projects/foo/package.json');
138137
expect(fileContent).toMatch(/"sideEffects":false/);
139138
});
140139

141140
it('should create a README.md named "foo"', async () => {
142141
const tree = await schematicRunner.runSchematic('library', defaultOptions, workspaceTree);
143142

144-
const fileContent = getFileContent(tree,'/projects/foo/README.md');
143+
const fileContent = tree.readText('/projects/foo/README.md');
145144
expect(fileContent).toMatch(/#Foo/);
146145
});
147146

@@ -425,7 +424,7 @@ describe('Library Schematic', () => {
425424
workspaceTree,
426425
);
427426

428-
const fileContent = getFileContent(tree,'/projects/foo/src/lib/foo-module.ts');
427+
const fileContent = tree.readText('/projects/foo/src/lib/foo-module.ts');
429428
expect(fileContent).toMatch(/exports:\[\n(\s*){2}Foo\n1円\]/);
430429
});
431430

‎packages/schematics/angular/pipe/index_spec.ts

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

99
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
1010
import { Schema as ApplicationOptions } from '../application/schema';
11-
import { createAppModule,getFileContent } from '../utility/test';
11+
import { createAppModule } from '../utility/test';
1212
import { Schema as WorkspaceOptions } from '../workspace/schema';
1313
import { Schema as PipeOptions } from './schema';
1414

@@ -58,7 +58,7 @@ describe('Pipe Schematic', () => {
5858
const files = tree.files;
5959
expect(files).toContain('/projects/bar/src/app/foo-pipe.spec.ts');
6060
expect(files).toContain('/projects/bar/src/app/foo-pipe.ts');
61-
const moduleContent = getFileContent(tree,'/projects/bar/src/app/app-module.ts');
61+
const moduleContent = tree.readText('/projects/bar/src/app/app-module.ts');
6262
expect(moduleContent).toMatch(/import.*Foo.*from'.\/foo-pipe'/);
6363
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m);
6464
const fileContent = tree.readContent('/projects/bar/src/app/foo-pipe.ts');
@@ -77,7 +77,7 @@ describe('Pipe Schematic', () => {
7777
const files = tree.files;
7878
expect(files).toContain('/projects/bar/src/app/foo.pipe.spec.ts');
7979
expect(files).toContain('/projects/bar/src/app/foo.pipe.ts');
80-
const moduleContent = getFileContent(tree,'/projects/bar/src/app/app-module.ts');
80+
const moduleContent = tree.readText('/projects/bar/src/app/app-module.ts');
8181
expect(moduleContent).toMatch(/import.*Foo.*from'.\/foo.pipe'/);
8282
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m);
8383
const fileContent = tree.readContent('/projects/bar/src/app/foo.pipe.ts');
@@ -96,7 +96,7 @@ describe('Pipe Schematic', () => {
9696
const files = tree.files;
9797
expect(files).toContain('/projects/bar/src/app/foo-pipe.spec.ts');
9898
expect(files).toContain('/projects/bar/src/app/foo-pipe.ts');
99-
const moduleContent = getFileContent(tree,'/projects/bar/src/app/app-module.ts');
99+
const moduleContent = tree.readText('/projects/bar/src/app/app-module.ts');
100100
expect(moduleContent).toMatch(/import.*Foo.*from'.\/foo-pipe'/);
101101
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m);
102102
const fileContent = tree.readContent('/projects/bar/src/app/foo-pipe.ts');
@@ -107,7 +107,7 @@ describe('Pipe Schematic', () => {
107107
const options = { ...defaultNonStandaloneOptions, module: 'app-module.ts' };
108108

109109
const tree = await schematicRunner.runSchematic('pipe', options, appTree);
110-
const appModule = getFileContent(tree,'/projects/bar/src/app/app-module.ts');
110+
const appModule = tree.readText('/projects/bar/src/app/app-module.ts');
111111

112112
expect(appModule).toMatch(/import{FooPipe}from'.\/foo-pipe'/);
113113
});
@@ -139,7 +139,7 @@ describe('Pipe Schematic', () => {
139139
const options = { ...defaultNonStandaloneOptions, export: true };
140140

141141
const tree = await schematicRunner.runSchematic('pipe', options, appTree);
142-
const appModuleContent = getFileContent(tree,'/projects/bar/src/app/app-module.ts');
142+
const appModuleContent = tree.readText('/projects/bar/src/app/app-module.ts');
143143
expect(appModuleContent).toMatch(/exports:\[\n(\s*){2}FooPipe\n1円\]/);
144144
});
145145

@@ -150,7 +150,7 @@ describe('Pipe Schematic', () => {
150150
const files = tree.files;
151151
expect(files).toContain('/projects/bar/src/app/foo/foo-pipe.spec.ts');
152152
expect(files).toContain('/projects/bar/src/app/foo/foo-pipe.ts');
153-
const moduleContent = getFileContent(tree,'/projects/bar/src/app/app-module.ts');
153+
const moduleContent = tree.readText('/projects/bar/src/app/app-module.ts');
154154
expect(moduleContent).toMatch(/import.*Foo.*from'.\/foo\/foo-pipe'/);
155155
expect(moduleContent).toMatch(/declarations:\s*\[[^\]]+?,\r?\n\s+FooPipe\r?\n/m);
156156
});
@@ -161,7 +161,7 @@ describe('Pipe Schematic', () => {
161161
const newTree = createAppModule(appTree, routingModulePath);
162162
const options = { ...defaultNonStandaloneOptions, module: routingFileName };
163163
const tree = await schematicRunner.runSchematic('pipe', options, newTree);
164-
const content = getFileContent(tree,routingModulePath);
164+
const content = tree.readText(routingModulePath);
165165
expect(content).toMatch(/import{FooPipe}from'.\/foo-pipe/);
166166
});
167167

‎packages/schematics/angular/utility/ast-utils_spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { tags } from '@angular-devkit/core';
1010
import { HostTree } from '@angular-devkit/schematics';
1111
import * as ts from '../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1212
import { Change, InsertChange } from '../utility/change';
13-
import { getFileContent } from '../utility/test';
1413
import {
1514
addDeclarationToModule,
1615
addExportToModule,
@@ -38,7 +37,7 @@ function applyChanges(path: string, content: string, changes: Change[]): string
3837
}
3938
tree.commitUpdate(exportRecorder);
4039

41-
return getFileContent(tree,path);
40+
return tree.readText(path);
4241
}
4342

4443
describe('ast utils', () => {

‎packages/schematics/angular/utility/test/get-file-content.ts

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

‎packages/schematics/angular/utility/test/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
*/
88

99
export * from './create-app-module';
10-
export * from './get-file-content';

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /