55 addProjectConfiguration ,
66 joinPathFragments ,
77 names ,
8+ offsetFromRoot ,
9+ ProjectConfiguration ,
810} from '@nrwl/devkit' ;
911import { uniq } from '@nrwl/nx-plugin/testing' ;
1012
@@ -29,8 +31,8 @@ describe('move generator', () => {
2931 expect ( tree . exists ( `apps/${ destination } /readme.md` ) ) . toBeTruthy ( ) ;
3032 } ) ;
3133
32- it ( 'should move simple projects down a directory' , async ( ) => {
33- const { project } = makeSimpleProject ( tree , 'app' , 'apps/libs/ test' ) ;
34+ it ( 'should move simple projects up a directory' , async ( ) => {
35+ const { project } = makeSimpleProject ( tree , 'app' , 'test' ) ;
3436 const destination = uniq ( 'app' ) ;
3537 await generator ( tree , { projectName : project , destination } ) ;
3638 const config = readProjectConfiguration ( tree , destination ) ;
@@ -39,8 +41,8 @@ describe('move generator', () => {
3941 expect ( tree . exists ( `apps/libs/test/readme.md` ) ) . toBeFalsy ( ) ;
4042 } ) ;
4143
42- it ( 'should move simple projects up a directory' , async ( ) => {
43- const { project } = makeSimpleProject ( tree , 'app' , 'apps/ test' ) ;
44+ it ( 'should move simple projects down a directory' , async ( ) => {
45+ const { project } = makeSimpleProject ( tree , 'app' , 'test' ) ;
4446 const destination = joinPathFragments ( 'test' , 'nested' , uniq ( 'app' ) ) ;
4547 await generator ( tree , { projectName : project , destination } ) ;
4648 const config = readProjectConfiguration (
@@ -53,15 +55,17 @@ describe('move generator', () => {
5355 } ) ;
5456
5557 it ( 'should update references in .csproj files' , async ( ) => {
56- const { project, root } = makeSimpleProject ( tree , 'app' , 'apps/ test' ) ;
58+ const { project, root } = makeSimpleProject ( tree , 'app' , 'test' ) ;
5759 const csProjPath = 'apps/other/Other.csproj' ;
5860 tree . write (
5961 csProjPath ,
6062 `<Project Sdk="Microsoft.NET.Sdk">
6163 <ItemGroup>
62- <ProjectReference Include="../test/${ names ( project ) . className } .csproj" />
64+ <ProjectReference Include="../test/${ project } /${
65+ names ( project ) . className
66+ } .csproj" />
6367 </ItemGroup>
64-
68+
6569 <PropertyGroup>
6670 <TargetFramework>net6.0</TargetFramework>
6771 <RootNamespace>test_lib2</RootNamespace>
@@ -86,15 +90,38 @@ describe('move generator', () => {
8690 expect ( updatedCsProj ) . not . toContain ( project ) ;
8791 expect ( updatedCsProj ) . toContain ( basename ( destination ) ) ;
8892 } ) ;
93+
94+ it ( 'should update paths in project configuration' , async ( ) => {
95+ const { project, root : source } = makeSimpleProject ( tree , 'app' , 'a/b' ) ;
96+ const destination = joinPathFragments ( 'a' , 'b' , 'c' , uniq ( 'app' ) ) ;
97+ await generator ( tree , { projectName : project , destination } ) ;
98+ const config : ProjectConfiguration & { $schema ?: string } =
99+ readProjectConfiguration ( tree , destination . replace ( / [ \\ | / ] / g, '-' ) ) ;
100+ expect ( config ) . toBeDefined ( ) ;
101+ expect ( JSON . stringify ( config ) ) . not . toContain ( source ) ;
102+ expect ( JSON . stringify ( config ) ) . toContain ( destination ) ;
103+ expect ( config . root . endsWith ( destination ) ) . toBeTruthy ( ) ;
104+ expect ( config . sourceRoot ?. startsWith ( config . root ) ) . toBeTruthy ( ) ;
105+ const relativeToRoot = offsetFromRoot ( config . root ) ;
106+ expect ( config . $schema ) . toMatch (
107+ new RegExp ( `^${ joinPathFragments ( relativeToRoot , 'node_modules' ) } .*` ) ,
108+ ) ;
109+ } ) ;
89110} ) ;
90111
91112function makeSimpleProject ( tree : Tree , type : 'app' | 'lib' , path ?: string ) {
92113 const project = uniq ( type ) ;
93- const root = path ? path . replaceAll ( '{n} ', project ) : ` ${ type } s/ ${ project } ` ;
114+ const root = joinPathFragments ( ` ${ type } s` , path ?? ' ', project ) ;
94115 addProjectConfiguration ( tree , project , {
95- root : root ,
116+ root,
117+ sourceRoot : joinPathFragments ( root , 'src' ) ,
96118 projectType : type === 'app' ? 'application' : 'library' ,
97- targets : { 'my-target' : { executor : 'nx:noop' } } ,
119+ targets : {
120+ 'my-target' : {
121+ executor : 'nx:noop' ,
122+ outputs : [ `{workspaceRoot}/dist/${ root } ` ] ,
123+ } ,
124+ } ,
98125 } ) ;
99126 tree . write ( joinPathFragments ( root , 'readme.md' ) , 'contents' ) ;
100127 return { project, root } ;
0 commit comments