66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9+ import { PassThrough } from 'node:stream' ;
10+ import { stripVTControlCharacters } from 'node:util' ;
911import { main } from '../bin/schematics' ;
1012
11- // We only care about the write method in these mocks of NodeJS.WriteStream.
12- class MockWriteStream {
13- lines : string [ ] = [ ] ;
14- write ( str : string ) {
15- // Strip color control characters.
16- this . lines . push ( str . replace ( / [ ^ \x20 - \x7F ] \[ \d + m / g, '' ) ) ;
17-
18- return true ;
19- }
20- }
21-
2213describe ( 'schematics-cli binary' , ( ) => {
23- let stdout : MockWriteStream , stderr : MockWriteStream ;
14+ let stdout : PassThrough , stderr : PassThrough ;
2415
2516 beforeEach ( ( ) => {
26- stdout = new MockWriteStream ( ) ;
27- stderr = new MockWriteStream ( ) ;
17+ stdout = new PassThrough ( ) ;
18+ stderr = new PassThrough ( ) ;
2819 } ) ;
2920
3021 it ( 'list-schematics works' , async ( ) => {
3122 const args = [ '--list-schematics' ] ;
3223 const res = await main ( { args, stdout, stderr } ) ;
33- expect ( stdout . lines ) . toMatch ( / b l a n k / ) ;
34- expect ( stdout . lines ) . toMatch ( / s c h e m a t i c / ) ;
24+ const output = stripVTControlCharacters ( stdout . read ( ) ?. toString ( ) || '' ) ;
25+ expect ( output ) . toMatch ( / b l a n k / ) ;
26+ expect ( output ) . toMatch ( / s c h e m a t i c / ) ;
3527 expect ( res ) . toEqual ( 0 ) ;
3628 } ) ;
3729
@@ -45,30 +37,33 @@ describe('schematics-cli binary', () => {
4537 it ( 'dry-run works' , async ( ) => {
4638 const args = [ 'blank' , 'foo' , '--dry-run' ] ;
4739 const res = await main ( { args, stdout, stderr } ) ;
48- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ R E A D M E .m d / ) ;
49- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ .g i t i g n o r e / ) ;
50- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x .t s / ) ;
51- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x _ s p e c .t s / ) ;
52- expect ( stdout . lines ) . toMatch ( / D r y r u n e n a b l e d ./ ) ;
40+ const output = stripVTControlCharacters ( stdout . read ( ) ?. toString ( ) || '' ) ;
41+ expect ( output ) . toMatch ( / C R E A T E f o o \/ R E A D M E .m d / ) ;
42+ expect ( output ) . toMatch ( / C R E A T E f o o \/ .g i t i g n o r e / ) ;
43+ expect ( output ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x .t s / ) ;
44+ expect ( output ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x _ s p e c .t s / ) ;
45+ expect ( output ) . toMatch ( / D r y r u n e n a b l e d ./ ) ;
5346 expect ( res ) . toEqual ( 0 ) ;
5447 } ) ;
5548
5649 it ( 'dry-run is default when debug mode' , async ( ) => {
5750 const args = [ 'blank' , 'foo' , '--debug' ] ;
5851 const res = await main ( { args, stdout, stderr } ) ;
59- expect ( stdout . lines ) . toMatch ( / D e b u g m o d e e n a b l e d ./ ) ;
60- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ R E A D M E .m d / ) ;
61- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ .g i t i g n o r e / ) ;
62- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x .t s / ) ;
63- expect ( stdout . lines ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x _ s p e c .t s / ) ;
64- expect ( stdout . lines ) . toMatch ( / D r y r u n e n a b l e d b y d e f a u l t i n d e b u g m o d e ./ ) ;
52+ const output = stripVTControlCharacters ( stdout . read ( ) ?. toString ( ) || '' ) ;
53+ expect ( output ) . toMatch ( / D e b u g m o d e e n a b l e d ./ ) ;
54+ expect ( output ) . toMatch ( / C R E A T E f o o \/ R E A D M E .m d / ) ;
55+ expect ( output ) . toMatch ( / C R E A T E f o o \/ .g i t i g n o r e / ) ;
56+ expect ( output ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x .t s / ) ;
57+ expect ( output ) . toMatch ( / C R E A T E f o o \/ s r c \/ f o o \/ i n d e x _ s p e c .t s / ) ;
58+ expect ( output ) . toMatch ( / D r y r u n e n a b l e d b y d e f a u l t i n d e b u g m o d e ./ ) ;
6559 expect ( res ) . toEqual ( 0 ) ;
6660 } ) ;
6761
6862 it ( 'error when no name is provided' , async ( ) => {
6963 const args = [ 'blank' ] ;
7064 const res = await main ( { args, stdout, stderr } ) ;
71- expect ( stderr . lines ) . toMatch ( / E r r o r : n a m e o p t i o n i s r e q u i r e d / ) ;
65+ const output = stripVTControlCharacters ( stderr . read ( ) ?. toString ( ) || '' ) ;
66+ expect ( output ) . toMatch ( / E r r o r : n a m e o p t i o n i s r e q u i r e d / ) ;
7267 expect ( res ) . toEqual ( 1 ) ;
7368 } ) ;
7469} ) ;
0 commit comments