1+ import { join , resolve } from 'path' ;
2+
3+ import * as mockFs from 'mock-fs' ;
4+
15import { Logger } from './logger/logger' ;
26import { inlineTemplate , replaceTemplateUrl , updateTemplate } from './template' ;
37import { getTemplateMatch , getTemplateFormat , replaceExistingJsTemplate } from './template' ;
4- import { resolve } from 'path' ;
5- import * as mockFs from 'mock-fs' ;
68
79
810describe ( 'template' , ( ) => {
@@ -12,55 +14,60 @@ describe('template', () => {
1214 it ( 'should inline multiple external html files which are the same for multiple @Components in same .ts file' , ( ) => {
1315 const sourceText = '/*someprefix*/@Component({templateUrl: "some-file.html" });/*somebetween*/@Component({templateUrl: "some-file.html" })/*somesuffix*/' ;
1416
15- const d = {
16- '/path/to/dir' : {
17- 'some-file.html' : '<div>A</div>' ,
18- 'some-file.scss' : 'body { color: red; }' ,
19- 'some-file.ts' : sourceText ,
20- } ,
17+ const baseDir = join ( process . cwd ( ) , 'path' , 'to' , 'dir' ) ;
18+
19+ const d : any = { } ;
20+
21+ d [ baseDir ] = {
22+ 'some-file.html' : '<div>A</div>' ,
23+ 'some-file.scss' : 'body { color: red; }' ,
24+ 'some-file.ts' : sourceText ,
2125 } ;
2226 mockFs ( d ) ;
2327
24- const results = inlineTemplate ( sourceText , '/path/to/dir/ some-file.ts') ;
28+ const results = inlineTemplate ( sourceText , join ( baseDir , ' some-file.ts') ) ;
2529
26- expect ( results ) . toEqual ( `/*someprefix*/@Component({template:/*ion-inline-start:"/path/to/dir/ some-file.html"*/'<div>A</div>'/*ion-inline-end:"/path/to/dir/ some-file.html"*/ });/*somebetween*/@Component({template:/*ion-inline-start:"/path/to/dir/ some-file.html"*/'<div>A</div>'/*ion-inline-end:"/path/to/dir/ some-file.html"*/ })/*somesuffix*/` ) ;
30+ expect ( results ) . toEqual ( `/*someprefix*/@Component({template:/*ion-inline-start:"${ join ( baseDir , ' some-file.html' ) } "*/'<div>A</div>'/*ion-inline-end:"${ join ( baseDir , ' some-file.html' ) } "*/ });/*somebetween*/@Component({template:/*ion-inline-start:"${ join ( baseDir , ' some-file.html' ) } "*/'<div>A</div>'/*ion-inline-end:"${ join ( baseDir , ' some-file.html' ) } "*/ })/*somesuffix*/` ) ;
2731 mockFs . restore ( ) ;
2832 } ) ;
2933
3034 it ( 'should inline multiple external html files with multiple @Components in same .ts file' , ( ) => {
3135 const sourceText = '/*someprefix*/@Component({templateUrl: "some-file1.html" });/*somebetween*/@Component({templateUrl: "some-file2.html" })/*somesuffix*/' ;
3236
33- const d = {
34- '/path/to/dir' : {
35- 'some-file1.html' : '<div>A</div>' ,
36- 'some-file2.html' : '<div>B</div>' ,
37- 'some-file.scss' : 'body { color: red; }' ,
38- 'some-file.ts' : sourceText ,
39- } ,
40- } ;
37+ const baseDir = join ( process . cwd ( ) , 'path' , 'to' , 'dir' ) ;
38+ const d : any = { } ;
39+
40+ d [ baseDir ] = {
41+ 'some-file1.html' : '<div>A</div>' ,
42+ 'some-file2.html' : '<div>B</div>' ,
43+ 'some-file.scss' : 'body { color: red; }' ,
44+ 'some-file.ts' : sourceText ,
45+ }
4146 mockFs ( d ) ;
4247
43- const results = inlineTemplate ( sourceText , '/path/to/dir/ some-file.ts') ;
48+ const results = inlineTemplate ( sourceText , join ( baseDir , ' some-file.ts') ) ;
4449
45- expect ( results ) . toEqual ( `/*someprefix*/@Component({template:/*ion-inline-start:"/path/to/dir/ some-file1.html"*/'<div>A</div>'/*ion-inline-end:"/path/to/dir/ some-file1.html"*/ });/*somebetween*/@Component({template:/*ion-inline-start:"/path/to/dir/ some-file2.html"*/'<div>B</div>'/*ion-inline-end:"/path/to/dir/ some-file2.html"*/ })/*somesuffix*/` ) ;
50+ expect ( results ) . toEqual ( `/*someprefix*/@Component({template:/*ion-inline-start:"${ join ( baseDir , ' some-file1.html' ) } "*/'<div>A</div>'/*ion-inline-end:"${ join ( baseDir , ' some-file1.html' ) } "*/ });/*somebetween*/@Component({template:/*ion-inline-start:"${ join ( baseDir , ' some-file2.html' ) } "*/'<div>B</div>'/*ion-inline-end:"${ join ( baseDir , ' some-file2.html' ) } "*/ })/*somesuffix*/` ) ;
4651 mockFs . restore ( ) ;
4752 } ) ;
4853
4954 it ( 'should inline the external html file content' , ( ) => {
5055 const sourceText = '@Component({templateUrl: "some-file.html" })' ;
5156
52- const d = {
53- '/path/to/dir' : {
54- 'some-file.html' : '<div>hello</div>' ,
55- 'some-file.scss' : 'body { color: red; }' ,
56- 'some-file.ts' : sourceText ,
57- } ,
57+ const baseDir = join ( process . cwd ( ) , 'path' , 'to' , 'dir' ) ;
58+
59+ const d : any = { } ;
60+
61+ d [ baseDir ] = {
62+ 'some-file.html' : '<div>hello</div>' ,
63+ 'some-file.scss' : 'body { color: red; }' ,
64+ 'some-file.ts' : sourceText ,
5865 } ;
5966 mockFs ( d ) ;
6067
61- const results = inlineTemplate ( sourceText , '/path/to/dir/ some-file.ts') ;
68+ const results = inlineTemplate ( sourceText , join ( baseDir , ' some-file.ts') ) ;
6269
63- expect ( results ) . toEqual ( `@Component({template:/*ion-inline-start:"/path/to/dir/ some-file.html"*/'<div>hello</div>'/*ion-inline-end:"/path/to/dir/ some-file.html"*/ })` ) ;
70+ expect ( results ) . toEqual ( `@Component({template:/*ion-inline-start:"${ join ( baseDir , ' some-file.html' ) } "*/'<div>hello</div>'/*ion-inline-end:"${ join ( baseDir , ' some-file.html' ) } "*/ })` ) ;
6471 mockFs . restore ( ) ;
6572 } ) ;
6673
@@ -138,11 +145,11 @@ describe('template', () => {
138145 this is "multiline" 'content'
139146 </div>\r
140147 ` ;
141- const htmlFilePath = '/ full/ path/to/ somepage.html';
148+ const htmlFilePath = join ( process . cwd ( ) , ' full' , ' path' , 'to' , ' somepage.html') ;
142149 const match = getTemplateMatch ( str ) ;
143150 const result = replaceTemplateUrl ( match , htmlFilePath , templateContent ) ;
144151
145- const expected = `Component({template:/*ion-inline-start:"/ full/ path/to/ somepage.html"*/'\\n <div>\t\\n this is "multiline" \\'content\\'\\n </div>\\n\\n '/*ion-inline-end:"/ full/ path/to/ somepage.html"*/})` ;
152+ const expected = `Component({template:/*ion-inline-start:"${ join ( process . cwd ( ) , ' full' , ' path' , 'to' , ' somepage.html' ) } "*/'\\n <div>\t\\n this is "multiline" \\'content\\'\\n </div>\\n\\n '/*ion-inline-end:"${ join ( process . cwd ( ) , ' full' , ' path' , 'to' , ' somepage.html' ) } "*/})` ;
146153
147154 expect ( result ) . toEqual ( expected ) ;
148155 } ) ;
0 commit comments