@@ -10,15 +10,45 @@ governing permissions and limitations under the License.
1010*/
1111
1212const execa = require ( 'execa' )
13+ const path = require ( 'path' )
1314const fs = jest . requireActual ( 'fs' )
1415const util = require ( 'util' )
1516const fse = {
1617 mkdir : util . promisify ( fs . mkdir ) ,
1718 rm : util . promisify ( fs . rm )
1819}
1920
21+ const BIN_RUN = path . resolve ( __dirname , '../bin/run' )
22+
2023jest . setTimeout ( 120000 )
2124
25+ test ( 'errors render through oclif, not Node\'s uncaught-exception printer' , async ( ) => {
26+ // Spawns the real bin/run with an argv guaranteed to trigger a flag
27+ // parse error from `@oclif/core`. When the bin's `.catch` handler is
28+ // wired correctly, oclif's renderer produces a clean single-line
29+ // `Error: …` message. When the handler is dropped (regression
30+ // tracked in adobe/aio-cli#829 / ACNA-4659), the rejection escapes
31+ // to Node and the output instead contains a source frame, a caret,
32+ // a stack trace, and a `Node.js vXX` footer. Asserting on the
33+ // absence of those Node-specific markers detects the regression
34+ // without coupling to oclif's exact prefix.
35+ const result = await execa ( 'node' , [ BIN_RUN , 'app' , 'use' , '--no-such-flag' ] ,
36+ { reject : false } )
37+
38+ // Non-zero exit on a parse error is part of the contract.
39+ expect ( result . exitCode ) . not . toBe ( 0 )
40+
41+ // The user-facing message must be present so the customer knows what
42+ // went wrong; the framework renders it on stderr.
43+ expect ( result . stderr ) . toMatch ( / N o n e x i s t e n t f l a g .* - - n o - s u c h - f l a g / )
44+
45+ // None of these substrings should appear: each is a fingerprint of
46+ // Node's default unhandled-rejection / uncaught-exception output.
47+ expect ( result . stderr ) . not . toMatch ( / a t p r o c e s s T i c k s A n d R e j e c t i o n s / )
48+ expect ( result . stderr ) . not . toMatch ( / ^ N o d e \. j s v \d + / m)
49+ expect ( result . stderr ) . not . toMatch ( / ^ \s + \^ \s * $ / m)
50+ } )
51+
2252test ( 'cli init test' , async ( ) => {
2353 const testFolder = 'e2e_test_run'
2454
0 commit comments