@@ -6,39 +6,34 @@ import { Exec } from '@e-square/utils/exec';
66import { logger } from '@e-square/utils/logger' ;
77import { assertNxInstalled , nxCommand , nxRunMany } from './nx' ;
88
9- jest . mock ( '@e-square/utils/logger' ) ;
109jest . mock ( 'child_process' ) ;
1110jest . mock ( 'fs' ) ;
11+ jest . mock ( '@e-square/utils/logger' ) ;
1212
1313describe ( 'nx' , ( ) => {
14+ let exec : Exec ;
15+
16+ beforeEach ( ( ) => {
17+ exec = new Exec ( jest . fn ( ) ) ;
18+ jest . spyOn ( exec , 'build' ) . mockReturnValue ( ( ) => Promise . resolve ( '' ) ) ;
19+ jest . spyOn ( exec , 'withCommand' ) ;
20+ jest . spyOn ( exec , 'withArgs' ) ;
21+ jest . spyOn ( exec , 'withOptions' ) ;
22+ } ) ;
23+
1424 describe ( 'assertNxInstalled' , ( ) => {
1525 it ( 'should fail to assert and throw error' , async ( ) => {
16- const exec = new Exec ( jest . fn ( ) . mockResolvedValueOnce ( 0 ) ) ;
1726 await expect ( assertNxInstalled ( exec ) ) . rejects . toThrow ( "Couldn't find Nx binary, Have you run npm/yarn install?" ) ;
1827 } ) ;
1928
2029 it ( 'should success assertion' , async ( ) => {
21- const exec = new Exec (
22- jest . fn ( ) . mockImplementation ( async ( _ , __ , opts ) => {
23- opts . listeners . stdout ( 'test' ) ;
24- return Promise . resolve ( 0 ) ;
25- } )
26- ) ;
30+ jest . spyOn ( exec , 'build' ) . mockReturnValue ( ( ) => Promise . resolve ( 'test' ) ) ;
31+
2732 await expect ( assertNxInstalled ( exec ) ) . resolves . toBeUndefined ( ) ;
2833 } ) ;
2934 } ) ;
3035
3136 describe ( 'exec nx' , ( ) => {
32- let exec : Exec ;
33-
34- beforeEach ( ( ) => {
35- exec = new Exec ( jest . fn ( ) ) ;
36- jest . spyOn ( exec , 'build' ) . mockReturnValue ( ( ) => Promise . resolve ( '' ) ) ;
37- jest . spyOn ( exec , 'withCommand' ) ;
38- jest . spyOn ( exec , 'withArgs' ) ;
39- jest . spyOn ( exec , 'withOptions' ) ;
40- } ) ;
41-
4237 const cases : [ pm . PackageManager , string , string ] [ ] = [
4338 [ 'npm' , '6.8.0' , 'npx -p @nrwl/cli' ] ,
4439 [ 'npm' , '7.0.0' , 'npx --no -p @nrwl/cli' ] ,
@@ -67,6 +62,23 @@ describe('nx', () => {
6762 expect ( exec . withArgs ) . toHaveBeenCalledWith ( '--target=build' ) ;
6863 } ) ;
6964
65+ it ( 'should not parse withDeps when nx version is >= 14' , async ( ) => {
66+ jest . spyOn ( exec , 'build' ) . mockReturnValueOnce ( ( ) => Promise . resolve ( '14.0.0' ) ) ;
67+
68+ await expect (
69+ nxCommand (
70+ 'test' ,
71+ {
72+ target : 'build' ,
73+ withDeps : true ,
74+ 'with-deps' : true ,
75+ } ,
76+ exec
77+ )
78+ ) . resolves . toBe ( '' ) ;
79+ expect ( exec . withArgs ) . toHaveBeenCalledWith ( '--target=build' ) ;
80+ } ) ;
81+
7082 it ( 'should call nxRunMany' , async ( ) => {
7183 await expect (
7284 nxRunMany (
0 commit comments