@@ -7,6 +7,29 @@ import { Smell, SmellType, SupportedLanguages } from '../src/types';
77
88vi . mock ( '../src/reporters/Output' ) ; 
99
10+ function  buildListWithSingleSmell ( smells : Smell [ ] ) : SmellsList [ ]  { 
11+   return  [ 
12+     { 
13+       smells, 
14+       language : SupportedLanguages . javascript , 
15+       fileName : 'random' , 
16+       fileContent : 'console.log("Hello world")' , 
17+     } , 
18+   ] ; 
19+ } 
20+ 
21+ function  createSingleSmell ( ) : Smell  { 
22+   return  { 
23+     type : SmellType . consoleStatement , 
24+     lineStart : 0 , 
25+     lineEnd : 1 , 
26+     startAt : 10 , 
27+     endsAt : 20 , 
28+     description : '' , 
29+     diagnostic : '' 
30+   } ; 
31+ } 
32+ 
1033describe ( 'smells aggregator' ,  ( )  =>  { 
1134  test ( 'no smells for a single file' ,  async  ( )  =>  { 
1235    const  smellsFound : SmellsList [ ]  =  [ ] ; 
@@ -22,24 +45,21 @@ describe('smells aggregator', () => {
2245    expect ( write . mock . calls [ 0 ] [ 1 ] ) . toEqual ( exportsOptions ) ; 
2346  } ) ; 
2447
25-   test ( 'match detected smells found to write in the output' ,  async  ( )  =>  { 
26-     const  smell : Smell  =  { 
27-       type : SmellType . consoleStatement , 
28-       lineStart : 0 , 
29-       lineEnd : 1 , 
30-       startAt : 10 , 
31-       endsAt : 20 , 
32-       description : '' , 
33-       diagnostic : '' 
34-     } ; 
48+   test ( 'should send file contents to the output' ,  async  ( )  =>  { 
49+     const  smellsFound : SmellsList [ ]  =  buildListWithSingleSmell ( [ createSingleSmell ( ) ] ) ; 
50+     const  exportsOptions : ExportOptions  =  {  to : '.'  } ; 
3551
36-     const  smellsFound : SmellsList [ ]  =  [ 
37-       { 
38-         smells : [ smell ] , 
39-         language : SupportedLanguages . javascript , 
40-         fileName : 'random' 
41-       } , 
42-     ] ; 
52+     const  write  =  vi . mocked ( HtmlOutput . prototype . writeTo  =  vi . fn ( ) ) ; 
53+ 
54+     const  reporter  =  new  SmellsAggreagtor ( smellsFound ,  exportsOptions ) ; 
55+ 
56+     await  reporter . build ( ) ; 
57+ 
58+     expect ( write . mock . calls [ 0 ] [ 0 ] . data [ 0 ] . fileContent ) . toEqual ( 'console.log("Hello world")' ) ; 
59+   } ) ; 
60+ 
61+   test ( 'match detected smells found to write in the output' ,  async  ( )  =>  { 
62+     const  smellsFound : SmellsList [ ]  =  buildListWithSingleSmell ( [ createSingleSmell ( ) ] ) ; 
4363    const  exportsOptions : ExportOptions  =  {  to : '.'  } ; 
4464
4565    const  write  =  vi . mocked ( HtmlOutput . prototype . writeTo  =  vi . fn ( ) ) ; 
@@ -62,13 +82,7 @@ describe('smells aggregator', () => {
6282      diagnostic : '' 
6383    } ; 
6484
65-     const  smellsFound : SmellsList [ ]  =  [ 
66-       { 
67-         smells : [ smell ] , 
68-         language : SupportedLanguages . javascript , 
69-         fileName : 'random' 
70-       } , 
71-     ] ; 
85+     const  smellsFound : SmellsList [ ]  =  buildListWithSingleSmell ( [ createSingleSmell ( ) ] ) ; 
7286    const  exportsOptions : ExportOptions  =  {  to : '.'  } ; 
7387
7488    const  write  =  vi . mocked ( HtmlOutput . prototype . writeTo  =  vi . fn ( ) ) ; 
@@ -86,12 +100,14 @@ describe('smells aggregator', () => {
86100      { 
87101        smells : [ smell ,  smell ,  smell ,  smell ,  smell ] , 
88102        language : SupportedLanguages . javascript , 
89-         fileName : 'first_test.js' 
103+         fileName : 'first_test.js' , 
104+         fileContent : 'console.log("Hello world")' , 
90105      } , 
91106      { 
92107        smells : [ smell ,  smell ,  smell ,  smell ,  smell ] , 
93108        language : SupportedLanguages . javascript , 
94-         fileName : 'second_test.js' 
109+         fileName : 'second_test.js' , 
110+         fileContent : 'var content = 0' , 
95111      } , 
96112    ] ; 
97113    const  exportsOptions : ExportOptions  =  {  to : '.'  } ; 
@@ -111,12 +127,14 @@ describe('smells aggregator', () => {
111127      { 
112128        smells : [ smell ,  smell ,  smell ,  smell ] , 
113129        language : SupportedLanguages . javascript , 
114-         fileName : 'first_test.js' 
130+         fileName : 'first_test.js' , 
131+         fileContent : 'console.log("Hello world")' , 
115132      } , 
116133      { 
117134        smells : [ ] , 
118135        language : SupportedLanguages . javascript , 
119-         fileName : 'second_test.js' 
136+         fileName : 'second_test.js' , 
137+         fileContent : 'console.log("Hello world")' , 
120138      } , 
121139    ] ; 
122140    const  exportsOptions : ExportOptions  =  {  to : '.'  } ; 
@@ -129,4 +147,4 @@ describe('smells aggregator', () => {
129147
130148    expect ( write . mock . calls [ 0 ] [ 0 ] . averageSmellsPerTestFile ) . toEqual ( 2 ) ; 
131149  } ) ; 
132- } ) ; 
150+ } ) ; 
0 commit comments