1
+ import { filesToAffect , standaloneEffects } from "../../../morph" ;
2
+ import { EditFileEffect } from "../../../morph/interfaces/morph.interface" ;
3
+ import { NextjsTypeNames } from "../../types/nextjs-types" ;
4
+ import { returnRootTsConfig } from "./nextjs-library" ;
5
+
6
+ describe ( 'Nextjs Library' , ( ) => {
7
+ describe ( 'returnRootTsConfig' , ( ) => {
8
+ it ( 'should choose closest index file' , ( ) => {
9
+ const mockFilePath = 'path/to/another/src/hello.service.ts' ;
10
+ const mockParameter = {
11
+ optionalTypes : { } ,
12
+ type : NextjsTypeNames . Library
13
+ } as any ;
14
+
15
+ const fileTree = [
16
+ "path/to/another/src" ,
17
+ "path/to/another/src/hello.component.ts" ,
18
+ "path/to/another/index.ts" ,
19
+ "path/to/another"
20
+ ] ;
21
+ const fileToModify = filesToAffect ( mockFilePath , fileTree , mockParameter , 'angular' ) ;
22
+ expect ( fileToModify ) . toEqual ( [ 'tsconfig.base.json' ] ) ;
23
+ } ) ;
24
+ } ) ;
25
+
26
+ describe ( 'libraryEffects' , ( ) => {
27
+ it ( 'should modify the base tsconfig with the appropriate params' , ( ) => {
28
+ const programmingLanguage = 'nextjs' ;
29
+ const mockParameter = {
30
+ type : NextjsTypeNames . Library
31
+ } as any ;
32
+ const mockParameters = {
33
+ name : 'home' ,
34
+ nameFilePath : 'libs/ui/home' ,
35
+ projectName : 'test-codegen-eleven'
36
+ }
37
+
38
+ const mockTsConfigBase = {
39
+ "compileOnSave" : false ,
40
+ "compilerOptions" : {
41
+ "paths" : {
42
+ "@test-codegen-eleven/common/common-ui" : [ "libs/common/common-ui/src/index.ts" ] ,
43
+ }
44
+ }
45
+ } ;
46
+ const expectedMockTsConfigBase = {
47
+ "compileOnSave" : false ,
48
+ "compilerOptions" : {
49
+ "paths" : {
50
+ "@test-codegen-eleven/common/common-ui" : [ "libs/common/common-ui/src/index.ts" ] ,
51
+ "@test-codegen-eleven/ui/home" : [ "libs/ui/home/src/index.ts" ] ,
52
+ }
53
+ }
54
+ } ;
55
+ const mockTsConfigBaseStringfied = JSON . stringify ( mockTsConfigBase ) ;
56
+ const mockExpectedMockTsConfigBaseStringified = JSON . stringify ( expectedMockTsConfigBase , null , 2 ) ;
57
+ const mockFileEffects : EditFileEffect [ ] = [
58
+ {
59
+ filePath : 'tsconfig.base.json' ,
60
+ originFilePath : 'path/to/another/src/hello.component.ts' ,
61
+ content : mockTsConfigBaseStringfied
62
+ }
63
+ ] ;
64
+ const result = standaloneEffects ( programmingLanguage , mockParameter , mockFileEffects , mockParameters ) ;
65
+ const expected = [
66
+ {
67
+ filePath : 'tsconfig.base.json' ,
68
+ originFilePath : 'path/to/another/src/hello.component.ts' ,
69
+ content : mockExpectedMockTsConfigBaseStringified
70
+ }
71
+ ] ;
72
+ expect ( result ) . toEqual ( expected ) ;
73
+ } ) ;
74
+ } ) ;
75
+ } ) ;
0 commit comments