@@ -16,42 +16,15 @@ describe('nxHandler', () => {
1616 nxProjectsFilter : '--with-target={task}' ,
1717 } ;
1818
19- describe ( 'isConfigured' , ( ) => {
20- it ( 'should detect Nx when nx.json exists and `nx report` succeeds' , async ( ) => {
21- vol . fromJSON ( { 'nx.json' : '{}' } , MEMFS_VOLUME ) ;
22- vi . spyOn ( utils , 'executeProcess' ) . mockResolvedValue ( {
23- code : 0 ,
24- stdout : 'NX Report complete - copy this into the issue template' ,
25- } as utils . ProcessResult ) ;
26-
27- await expect ( nxHandler . isConfigured ( options ) ) . resolves . toBeTrue ( ) ;
28- } ) ;
29-
30- it ( "should NOT detect Nx when nx.json doesn't exist" , async ( ) => {
31- vol . fromJSON ( { 'turbo.json' : '{}' } , MEMFS_VOLUME ) ;
32- vi . spyOn ( utils , 'executeProcess' ) . mockResolvedValue ( {
33- code : 0 ,
34- } as utils . ProcessResult ) ;
35-
36- await expect ( nxHandler . isConfigured ( options ) ) . resolves . toBeFalse ( ) ;
37- } ) ;
38-
39- it ( 'should NOT detect Nx when `nx report` fails with non-zero exit code' , async ( ) => {
40- vol . fromJSON ( { 'nx.json' : '' } , MEMFS_VOLUME ) ;
41- vi . spyOn ( utils , 'executeProcess' ) . mockResolvedValue ( {
42- code : 1 ,
43- stderr : 'Error: ValueExpected in nx.json' ,
44- } as utils . ProcessResult ) ;
45-
46- await expect ( nxHandler . isConfigured ( options ) ) . resolves . toBeFalse ( ) ;
47- } ) ;
48- } ) ;
49-
5019 describe ( 'listProjects' , ( ) => {
20+ const nxReportSuccess = { code : 0 } as utils . ProcessResult ;
21+
5122 beforeEach ( ( ) => {
52- vi . spyOn ( utils , 'executeProcess' ) . mockResolvedValue ( {
53- stdout : '["backend","frontend"]' ,
54- } as utils . ProcessResult ) ;
23+ vi . spyOn ( utils , 'executeProcess' )
24+ . mockResolvedValueOnce ( nxReportSuccess )
25+ . mockResolvedValueOnce ( {
26+ stdout : '["backend","frontend"]' ,
27+ } as utils . ProcessResult ) ;
5528 } ) ;
5629
5730 it ( 'should list projects from `nx show projects`' , async ( ) => {
@@ -95,20 +68,39 @@ describe('nxHandler', () => {
9568 } satisfies utils . ProcessConfig ) ;
9669 } ) ;
9770
71+ it ( 'should throw if `nx report` fails' , async ( ) => {
72+ vi . spyOn ( utils , 'executeProcess' )
73+ . mockReset ( )
74+ . mockResolvedValueOnce ( {
75+ code : 1 ,
76+ stderr : 'Error: ValueExpected in nx.json' ,
77+ } as utils . ProcessResult ) ;
78+
79+ await expect ( nxHandler . listProjects ( options ) ) . rejects . toThrow (
80+ "'nx report' failed with exit code 1 - Error: ValueExpected in nx.json" ,
81+ ) ;
82+ } ) ;
83+
9884 it ( 'should throw if `nx show projects` outputs invalid JSON' , async ( ) => {
99- vi . spyOn ( utils , 'executeProcess' ) . mockResolvedValue ( {
100- stdout : 'backend\nfrontend\n' ,
101- } as utils . ProcessResult ) ;
85+ vi . spyOn ( utils , 'executeProcess' )
86+ . mockReset ( )
87+ . mockResolvedValueOnce ( nxReportSuccess )
88+ . mockResolvedValueOnce ( {
89+ stdout : 'backend\nfrontend\n' ,
90+ } as utils . ProcessResult ) ;
10291
10392 await expect ( nxHandler . listProjects ( options ) ) . rejects . toThrow (
10493 "Invalid non-JSON output from 'nx show projects' - SyntaxError: Unexpected token" ,
10594 ) ;
10695 } ) ;
10796
10897 it ( "should throw if `nx show projects` JSON output isn't array of strings" , async ( ) => {
109- vi . spyOn ( utils , 'executeProcess' ) . mockResolvedValue ( {
110- stdout : '"backend"' ,
111- } as utils . ProcessResult ) ;
98+ vi . spyOn ( utils , 'executeProcess' )
99+ . mockReset ( )
100+ . mockResolvedValueOnce ( nxReportSuccess )
101+ . mockResolvedValueOnce ( {
102+ stdout : '"backend"' ,
103+ } as utils . ProcessResult ) ;
112104
113105 await expect ( nxHandler . listProjects ( options ) ) . rejects . toThrow (
114106 'Invalid JSON output from \'nx show projects\', expected array of strings, received "backend"' ,
0 commit comments