Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(compiler-cli): tests for standalone components/directives/pipes (#…
…45672) This commit bundles tests for standalone components that are possible after previous implementation commits. Most new tests are compliance tests, but a test is also included to validate that the template type-checking system can work with standalone components as well. PR Close #45672
- Loading branch information
Showing
13 changed files
with
545 additions
and
1 deletion.
There are no files selected for viewing
288 changes: 288 additions & 0 deletions
288
.../test_cases/r3_compiler_compliance/components_and_directives/standalone/GOLDEN_PARTIAL.js
Large diffs are not rendered by default.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
...ce/test_cases/r3_compiler_compliance/components_and_directives/standalone/TEST_CASES.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"$schema": "../../../test_case_schema.json", | ||
"cases": [ | ||
{ | ||
"description": "should properly compile a standalone component", | ||
"inputFiles": [ | ||
"component.ts" | ||
], | ||
"expectations": [ | ||
{ | ||
"failureMessage": "Invalid component definition", | ||
"files": [ | ||
"component.js" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "should properly compile a standalone directive", | ||
"inputFiles": [ | ||
"directive.ts" | ||
], | ||
"expectations": [ | ||
{ | ||
"failureMessage": "Invalid directive definition", | ||
"files": [ | ||
"directive.js" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "should properly compile a standalone pipe", | ||
"inputFiles": [ | ||
"pipe.ts" | ||
], | ||
"expectations": [ | ||
{ | ||
"failureMessage": "Invalid pipe definition", | ||
"files": [ | ||
"pipe.js" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "should generate dependencies array from imports", | ||
"inputFiles": [ | ||
"imports.ts" | ||
], | ||
"expectations": [ | ||
{ | ||
"failureMessage": "Invalid standalone component dependencies", | ||
"files": [ | ||
"imports.js" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "should support recursivity in templates", | ||
"inputFiles": [ | ||
"recursive.ts" | ||
], | ||
"expectations": [ | ||
{ | ||
"failureMessage": "Recursive usage not accounted for", | ||
"files": [ | ||
"recursive.js" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
15 changes: 15 additions & 0 deletions
15
...iance/test_cases/r3_compiler_compliance/components_and_directives/standalone/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
StandaloneCmp.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ | ||
type: StandaloneCmp, | ||
selectors: [["ng-component"]], | ||
standalone: true, | ||
features: [i0.ɵɵStandaloneFeature], | ||
decls: 1, | ||
vars: 0, | ||
template: function StandaloneCmp_Template(rf, ctx) { | ||
if (rf & 1) { | ||
i0.ɵɵelement(0, "other-cmp"); | ||
} | ||
}, | ||
dependencies: [OtherCmp], | ||
encapsulation: 2 | ||
}); |
17 changes: 17 additions & 0 deletions
17
...iance/test_cases/r3_compiler_compliance/components_and_directives/standalone/component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'other-cmp', | ||
template: '', | ||
}) | ||
export class OtherCmp { | ||
} | ||
|
||
@Component({ | ||
standalone: true, | ||
template: '<other-cmp></other-cmp>', | ||
imports: [OtherCmp], | ||
}) | ||
export class StandaloneCmp { | ||
} |
4 changes: 4 additions & 0 deletions
4
...iance/test_cases/r3_compiler_compliance/components_and_directives/standalone/directive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
StandaloneDir.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ | ||
type: StandaloneDir, | ||
standalone: true | ||
}); |
7 changes: 7 additions & 0 deletions
7
...iance/test_cases/r3_compiler_compliance/components_and_directives/standalone/directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Directive} from '@angular/core'; | ||
|
||
@Directive({ | ||
standalone: true, | ||
}) | ||
export class StandaloneDir { | ||
} |
1 change: 1 addition & 0 deletions
1
...pliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/imports.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
...pliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/imports.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {Component, Directive, NgModule, Pipe} from '@angular/core'; | ||
|
||
@Directive({selector: '[not-standalone]'}) | ||
export class NotStandaloneDir { | ||
} | ||
|
||
@Pipe({name: 'nspipe'}) | ||
export class NotStandalonePipe { | ||
transform(value: any): any {} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [NotStandaloneDir, NotStandalonePipe], | ||
exports: [NotStandaloneDir, NotStandalonePipe], | ||
}) | ||
export class NotStandaloneStuffModule { | ||
} | ||
|
||
@Directive({ | ||
standalone: true, | ||
selector: '[indirect]', | ||
}) | ||
export class IndirectDir { | ||
} | ||
|
||
@Pipe({ | ||
standalone: true, | ||
name: 'indirectpipe', | ||
}) | ||
export class IndirectPipe { | ||
transform(value: any): any {} | ||
} | ||
|
||
@NgModule({ | ||
imports: [IndirectDir, IndirectPipe], | ||
exports: [NotStandaloneStuffModule, IndirectDir, IndirectPipe], | ||
}) | ||
export class SomeModule { | ||
} | ||
|
||
|
||
@Directive({ | ||
standalone: true, | ||
selector: '[direct]', | ||
}) | ||
export class DirectDir { | ||
} | ||
|
||
@Pipe({ | ||
standalone: true, | ||
name: 'directpipe', | ||
}) | ||
export class DirectPipe { | ||
transform(value: any): any {} | ||
} | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'test-cmp', | ||
template: ` | ||
<p>Reference some non-standalone things:<span not-standalone>{{data | nspipe}}</span></p> | ||
<p>Reference some indirect standalone things:<span indirect>{{data | indirectpipe}}</span></p> | ||
<p>Reference some standalone things directly:<span direct>{{data | directpipe}}</span></p> | ||
`, | ||
imports: [SomeModule, DirectDir, DirectPipe], | ||
}) | ||
export class TestCmp { | ||
data = true; | ||
} |
6 changes: 6 additions & 0 deletions
6
...compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/pipe.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
StandalonePipe.ɵpipe = /*@__PURE__*/ i0.ɵɵdefinePipe({ | ||
name: "stpipe", | ||
type: StandalonePipe, | ||
pure: true, | ||
standalone: true | ||
}); |
9 changes: 9 additions & 0 deletions
9
...compliance/test_cases/r3_compiler_compliance/components_and_directives/standalone/pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {Pipe} from '@angular/core'; | ||
|
||
@Pipe({ | ||
standalone: true, | ||
name: 'stpipe', | ||
}) | ||
export class StandalonePipe { | ||
transform(value: any): any {} | ||
} |
1 change: 1 addition & 0 deletions
1
...iance/test_cases/r3_compiler_compliance/components_and_directives/standalone/recursive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dependencies: [RecursiveComponent], |
10 changes: 10 additions & 0 deletions
10
...iance/test_cases/r3_compiler_compliance/components_and_directives/standalone/recursive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: 'recursive-cmp', | ||
// Simple recursion. Note: no `imports`. | ||
template: '<recursive-cmp></recursive-cmp>', | ||
}) | ||
export class RecursiveComponent { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters