@@ -5,18 +5,29 @@ import { MEMFS_VOLUME } from '@code-pushup/test-utils';
55import { normalizedCreateNodesV2Context } from './utils.js' ;
66
77describe ( 'normalizedCreateNodesV2Context' , ( ) => {
8- it ( 'should provide workspaceRoot' , async ( ) => {
8+ const projectJsonPath = ( projectRoot = '' ) =>
9+ `${ MEMFS_VOLUME } /${ projectRoot } ${ projectRoot ? '/' : '' } project.json` ;
10+
11+ const setupProjectJson = ( options ?: {
12+ config ?: Record < string , unknown > ;
13+ root ?: string ;
14+ } ) => {
15+ const { config = { name : 'my-project' } , root = '' } = options ?? { } ;
916 vol . fromJSON (
1017 {
11- ' project.json' : JSON . stringify ( { name : 'my-project' } ) ,
18+ [ ` ${ root } ${ root ? '/' : '' } project.json` ] : JSON . stringify ( config ) ,
1219 } ,
1320 MEMFS_VOLUME ,
1421 ) ;
22+ } ;
23+
24+ it ( 'should provide workspaceRoot' , async ( ) => {
25+ setupProjectJson ( ) ;
1526
1627 await expect (
1728 normalizedCreateNodesV2Context (
1829 createNodesV2Context ( { workspaceRoot : MEMFS_VOLUME } ) ,
19- 'project.json' ,
30+ projectJsonPath ( ) ,
2031 ) ,
2132 ) . resolves . toStrictEqual (
2233 expect . objectContaining ( {
@@ -26,47 +37,35 @@ describe('normalizedCreateNodesV2Context', () => {
2637 } ) ;
2738
2839 it ( 'should provide projectRoot' , async ( ) => {
29- vol . fromJSON (
30- {
31- 'packages/utils/project.json' : JSON . stringify ( {
32- name : 'my-project' ,
33- } ) ,
34- } ,
35- MEMFS_VOLUME ,
36- ) ;
40+ const root = 'packages/utils' ;
41+ setupProjectJson ( { root } ) ;
3742
3843 await expect (
3944 normalizedCreateNodesV2Context (
40- createNodesV2Context ( ) ,
41- 'packages/utils/project.json' ,
45+ createNodesV2Context ( { workspaceRoot : MEMFS_VOLUME } ) ,
46+ projectJsonPath ( root ) ,
4247 ) ,
4348 ) . resolves . toStrictEqual (
4449 expect . objectContaining ( {
45- projectRoot : 'packages/utils' ,
50+ projectRoot : ` ${ MEMFS_VOLUME } / ${ root } ` ,
4651 } ) ,
4752 ) ;
4853 } ) ;
4954
5055 it ( 'should provide nxJsonConfiguration' , async ( ) => {
51- vol . fromJSON (
52- {
53- 'project.json' : JSON . stringify ( {
54- name : 'my-project' ,
55- } ) ,
56- } ,
57- MEMFS_VOLUME ,
58- ) ;
56+ setupProjectJson ( ) ;
5957
6058 await expect (
6159 normalizedCreateNodesV2Context (
6260 createNodesV2Context ( {
61+ workspaceRoot : MEMFS_VOLUME ,
6362 nxJsonConfiguration : {
6463 workspaceLayout : {
6564 libsDir : 'libs' ,
6665 } ,
6766 } ,
6867 } ) ,
69- 'project.json' ,
68+ projectJsonPath ( ) ,
7069 ) ,
7170 ) . resolves . toStrictEqual (
7271 expect . objectContaining ( {
@@ -80,17 +79,13 @@ describe('normalizedCreateNodesV2Context', () => {
8079 } ) ;
8180
8281 it ( 'should provide projectJson' , async ( ) => {
83- vol . fromJSON (
84- {
85- 'project.json' : JSON . stringify ( {
86- name : 'my-project' ,
87- } ) ,
88- } ,
89- MEMFS_VOLUME ,
90- ) ;
82+ setupProjectJson ( { config : { name : 'my-project' } } ) ;
9183
9284 await expect (
93- normalizedCreateNodesV2Context ( createNodesV2Context ( ) , 'project.json' ) ,
85+ normalizedCreateNodesV2Context (
86+ createNodesV2Context ( { workspaceRoot : MEMFS_VOLUME } ) ,
87+ projectJsonPath ( ) ,
88+ ) ,
9489 ) . resolves . toStrictEqual (
9590 expect . objectContaining ( {
9691 projectJson : {
@@ -109,22 +104,21 @@ describe('normalizedCreateNodesV2Context', () => {
109104 ) ;
110105
111106 await expect (
112- normalizedCreateNodesV2Context ( createNodesV2Context ( ) , 'project.json' ) ,
113- ) . rejects . toThrow ( 'Error parsing project.json file project.json.' ) ;
107+ normalizedCreateNodesV2Context (
108+ createNodesV2Context ( { workspaceRoot : MEMFS_VOLUME } ) ,
109+ projectJsonPath ( ) ,
110+ ) ,
111+ ) . rejects . toThrow ( `Error parsing project.json file ${ projectJsonPath ( ) } .` ) ;
114112 } ) ;
115113
116114 it ( 'should provide default targetName in createOptions' , async ( ) => {
117- vol . fromJSON (
118- {
119- 'project.json' : JSON . stringify ( {
120- name : 'my-project' ,
121- } ) ,
122- } ,
123- MEMFS_VOLUME ,
124- ) ;
115+ setupProjectJson ( ) ;
125116
126117 await expect (
127- normalizedCreateNodesV2Context ( createNodesV2Context ( ) , 'project.json' ) ,
118+ normalizedCreateNodesV2Context (
119+ createNodesV2Context ( { workspaceRoot : MEMFS_VOLUME } ) ,
120+ projectJsonPath ( ) ,
121+ ) ,
128122 ) . resolves . toStrictEqual (
129123 expect . objectContaining ( {
130124 createOptions : {
@@ -135,19 +129,16 @@ describe('normalizedCreateNodesV2Context', () => {
135129 } ) ;
136130
137131 it ( 'should provide createOptions' , async ( ) => {
138- vol . fromJSON (
139- {
140- 'project.json' : JSON . stringify ( {
141- name : 'my-project' ,
142- } ) ,
143- } ,
144- MEMFS_VOLUME ,
145- ) ;
132+ setupProjectJson ( ) ;
146133
147134 await expect (
148- normalizedCreateNodesV2Context ( createNodesV2Context ( ) , 'project.json' , {
149- projectPrefix : 'cli' ,
150- } ) ,
135+ normalizedCreateNodesV2Context (
136+ createNodesV2Context ( { workspaceRoot : MEMFS_VOLUME } ) ,
137+ projectJsonPath ( ) ,
138+ {
139+ projectPrefix : 'cli' ,
140+ } ,
141+ ) ,
151142 ) . resolves . toStrictEqual (
152143 expect . objectContaining ( {
153144 createOptions : {
0 commit comments