@@ -15,12 +15,37 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
1515 let addonDir : string ;
1616 let addonName = 'my-addon' ;
1717
18+ async function commandSucceeds ( command : string ) {
19+ let result = await execa ( {
20+ cwd : addonDir ,
21+ shell : true ,
22+ preferLocal : true ,
23+ // Allows us to not fail yet when the command fails
24+ // but we'd still fail appropriately with the exitCode check below.
25+ // When we fail, we want to check for git diffs for debugging purposes.
26+ reject : false ,
27+ } ) ( command ) ;
28+
29+ if ( result . exitCode !== 0 ) {
30+ console . log ( result ) ;
31+ console . log ( `\n\n${ command } exited with code ${ result . exitCode } \n\n` ) ;
32+ console . log ( result . stdout ) ;
33+ console . log ( result . stderr ) ;
34+ console . log ( `\n\n git diff \n\n` ) ;
35+ await execa ( { cwd : addonDir , stdio : 'inherit' } ) `git diff` ;
36+ }
37+
38+ expect ( result . exitCode , `\`${ command } \` succeeds` ) . toEqual ( 0 ) ;
39+
40+ return result ;
41+ }
42+
1843 beforeAll ( async ( ) => {
1944 tmpDir = ( await tmp . dir ( ) ) . path ;
2045 addonDir = join ( tmpDir , addonName ) ;
2146 await execa ( {
2247 cwd : tmpDir ,
23- } ) `${ localEmberCli } addon ${ addonName } -b ${ blueprintPath } --skip-npm --skip-git -- prefer-local true --${ packageManager } --typescript` ;
48+ } ) `${ localEmberCli } addon ${ addonName } -b ${ blueprintPath } --skip-npm --prefer-local true --${ packageManager } --typescript` ;
2449 await execa ( { cwd : addonDir } ) `${ packageManager } install` ;
2550 } ) ;
2651
@@ -35,9 +60,7 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
3560 // Tests are additive, so when running them in order, we want to check linting
3661 // before we add files from fixtures
3762 it ( 'lints pass' , async ( ) => {
38- let { exitCode } = await execa ( { cwd : addonDir } ) `pnpm lint` ;
39-
40- expect ( exitCode ) . toEqual ( 0 ) ;
63+ await commandSucceeds ( `${ packageManager } run lint` ) ;
4164 } ) ;
4265
4366 describe ( 'with fixture' , ( ) => {
@@ -54,19 +77,15 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
5477 } ) ;
5578
5679 it ( 'lint:fix' , async ( ) => {
57- let { exitCode } = await execa ( { cwd : addonDir } ) `${ packageManager } run lint:fix` ;
58-
59- expect ( exitCode ) . toEqual ( 0 ) ;
80+ await commandSucceeds ( `${ packageManager } run lint:fix` ) ;
6081 } ) ;
6182
6283 it ( 'build' , async ( ) => {
63- let buildResult = await execa ( { cwd : addonDir } ) `${ packageManager } run build` ;
64-
65- expect ( buildResult . exitCode ) . toEqual ( 0 ) ;
84+ await commandSucceeds ( `${ packageManager } run build` ) ;
6685
6786 let src = await dirContents ( join ( addonDir , 'src' ) ) ;
6887 let dist = await dirContents ( join ( addonDir , 'dist' ) ) ;
69- let declarations = await dirContents ( join ( addonDir , 'dist ' ) ) ;
88+ let declarations = await dirContents ( join ( addonDir , 'declarations ' ) ) ;
7089
7190 expect ( { src } , 'ensure we dont litter the src dir with declarations' ) . to . deep . equal ( {
7291 src : [ 'components' , 'index.ts' , 'template-registry.ts' ] ,
@@ -85,21 +104,18 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
85104 'components' ,
86105 'index.d.ts' ,
87106 'index.d.ts.map' ,
88- 'services' ,
89107 'template-registry.d.ts' ,
90108 'template-registry.d.ts.map' ,
91109 ] ,
92110 } ) ;
93111 } ) ;
94112
95113 it ( 'test' , async ( ) => {
96- let testResult = await execa ( { cwd : addonDir } ) `${ packageManager } run test` ;
97-
98- expect ( testResult . exitCode ) . toEqual ( 0 ) ;
114+ let testResult = await commandSucceeds ( `${ packageManager } run test` ) ;
99115
100- expect ( testResult . exitCode ) . toEqual ( 0 ) ;
101- expect ( testResult . stdout ) . to . include ( '# tests 5 ' ) ;
102- expect ( testResult . stdout ) . to . include ( '# pass 5 ' ) ;
116+ console . log ( testResult . stdout ) ;
117+ expect ( testResult . stdout ) . to . include ( '# tests 2 ' ) ;
118+ expect ( testResult . stdout ) . to . include ( '# pass 2 ' ) ;
103119 expect ( testResult . stdout ) . to . include ( '# fail 0' ) ;
104120 } ) ;
105121 } ) ;
0 commit comments