Skip to content

Commit ca1d392

Browse files
devversionkirjs
authored andcommitted
test: add test to verify extending tsconfig works in signal input migration (#59463)
Related to #59348 PR Close #59463
1 parent 7debf0f commit ca1d392

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

packages/core/schematics/test/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jasmine_node_test(
2626
"//packages/core/schematics/ng-generate/inject-migration:static_files",
2727
"//packages/core/schematics/ng-generate/output-migration:static_files",
2828
"//packages/core/schematics/ng-generate/route-lazy-loading:static_files",
29+
"//packages/core/schematics/ng-generate/signal-input-migration:static_files",
2930
"//packages/core/schematics/ng-generate/signal-queries-migration:static_files",
3031
"//packages/core/schematics/ng-generate/signals:static_files",
3132
"//packages/core/schematics/ng-generate/standalone-migration:static_files",
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import {getSystemPath, normalize, virtualFs} from '@angular-devkit/core';
10+
import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
11+
import {HostTree} from '@angular-devkit/schematics';
12+
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
13+
import {runfiles} from '@bazel/runfiles';
14+
import shx from 'shelljs';
15+
16+
describe('signal input migration', () => {
17+
let runner: SchematicTestRunner;
18+
let host: TempScopedNodeJsSyncHost;
19+
let tree: UnitTestTree;
20+
let tmpDirPath: string;
21+
let previousWorkingDir: string;
22+
23+
function writeFile(filePath: string, contents: string) {
24+
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
25+
}
26+
27+
function runMigration(options?: {path?: string}) {
28+
return runner.runSchematic('signal-input-migration', options, tree);
29+
}
30+
31+
beforeEach(() => {
32+
runner = new SchematicTestRunner('test', runfiles.resolvePackageRelative('../collection.json'));
33+
host = new TempScopedNodeJsSyncHost();
34+
tree = new UnitTestTree(new HostTree(host));
35+
36+
writeFile('/tsconfig.json', '{}');
37+
writeFile(
38+
'/angular.json',
39+
JSON.stringify({
40+
version: 1,
41+
projects: {t: {root: '', architect: {build: {options: {tsConfig: './tsconfig.json'}}}}},
42+
}),
43+
);
44+
45+
previousWorkingDir = shx.pwd();
46+
tmpDirPath = getSystemPath(host.root);
47+
shx.cd(tmpDirPath);
48+
});
49+
50+
afterEach(() => {
51+
shx.cd(previousWorkingDir);
52+
shx.rm('-r', tmpDirPath);
53+
});
54+
55+
it('should work', async () => {
56+
writeFile(
57+
'/index.ts',
58+
`
59+
import {Input, Directive} from '@angular/core';
60+
61+
@Directive({})
62+
export class SomeDirective {
63+
@Input({required: true}) name = '';
64+
}`,
65+
);
66+
67+
await runMigration();
68+
69+
const content = tree.readContent('/index.ts').replace(/\s+/g, ' ');
70+
expect(content).toContain('readonly name = input.required<string>()');
71+
});
72+
73+
it('should work when extending tsconfig from node_modules', async () => {
74+
writeFile(`node_modules/@tsconfig/strictest/tsconfig.json`, `{}`);
75+
writeFile(
76+
`tsconfig.json`,
77+
JSON.stringify({
78+
extends: `@tsconfig/strictest/tsconfig.json`,
79+
}),
80+
);
81+
writeFile(
82+
'/index.ts',
83+
`
84+
import {Input, Directive} from '@angular/core';
85+
86+
@Directive({})
87+
export class SomeDirective {
88+
@Input({required: true}) name = '';
89+
}`,
90+
);
91+
92+
await runMigration();
93+
94+
const content = tree.readContent('/index.ts').replace(/\s+/g, ' ');
95+
expect(content).toContain('readonly name = input.required<string>()');
96+
});
97+
});

0 commit comments

Comments
 (0)