11import  {  test ,  describe ,  expect ,  afterEach ,  beforeEach  }  from  'vitest' ; 
2- import  {  exec  }  from  "child_process" ; 
3- import  {  promisify  }  from  "util" ; 
42import  {  parse  }  from  'node-html-parser' ; 
5- import  {  SmellsBuilder  }  from  '../src/smells-builder' ; 
6- import  {  SmellsAggreagtor  }  from  '../src/reporters/SmellsAgreggator' ; 
7- import  {  AggregatedData ,  ExportOptions ,  SmellsList  }  from  '../src/reporters/types' ; 
8- import  {  Smell ,  SmellType ,  SupportedLanguages  }  from  '../src/types' ; 
9- import  {  HtmlOutput  }  from  '../src/reporters/Output' ; 
10- import  {  readFileSync ,  rmSync  }  from  'fs' ; 
3+ import  {  ExportOptions  }  from  '../src/reporters/types' ; 
4+ import  {  rmSync  }  from  'fs' ; 
5+ import  {  buildEmptyHtmlReportForTestSmells  }  from  './html-report-builder' ; 
116
127describe ( 'html report' ,  ( )  =>  { 
138  const  exportsOptions : ExportOptions  =  {  to : '.'  } ; 
@@ -22,43 +17,33 @@ describe('html report', () => {
2217  } ) ; 
2318
2419  test ( 'renders empty table when no tests are found' ,  async  ( )  =>  { 
25-     const  generatedHtml  =  await  buildHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
20+     const  generatedHtml  =  await  buildEmptyHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
2621    const  root  =  parse ( generatedHtml ) ; 
2722
2823    expect ( root . querySelectorAll ( 'table tbody tr' ) . length ) . toEqual ( 0 ) ; 
2924  } ) ; 
3025
3126  test ( 'renders report title' ,  async  ( )  =>  { 
32-     const  generatedHtml  =  await  buildHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
27+     const  generatedHtml  =  await  buildEmptyHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
3328    const  root  =  parse ( generatedHtml ) ; 
3429
3530    expect ( root . querySelector ( '[data-testid="report-title"]' ) ?. textContent ) . toEqual ( 'Test smells report' ) ; 
3631  } ) ; 
3732
3833  test ( 'renders total number of smells found' ,  async  ( )  =>  { 
39-     const  generatedHtml  =  await  buildHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
34+     const  generatedHtml  =  await  buildEmptyHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
4035    const  root  =  parse ( generatedHtml ) ; 
4136
4237    expect ( root . querySelector ( '[data-testid="total-smells-found"]' ) ?. textContent ) . toEqual ( '0' ) ; 
4338    expect ( root . querySelector ( '[data-testid="title-smells-found"]' ) ?. textContent ) . toEqual ( 'Test smells' ) ; 
4439  } ) ; 
4540
4641  test ( 'renders the number of test files' ,  async  ( )  =>  { 
47-     const  generatedHtml  =  await  buildHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
42+     const  generatedHtml  =  await  buildEmptyHtmlReportForTestSmells ( exportsOptions ,  filePath ) ; 
4843    const  root  =  parse ( generatedHtml ) ; 
4944
5045    expect ( root . querySelector ( '[data-testid="total-test-files"]' ) ?. textContent ) . toEqual ( '0' ) ; 
5146    expect ( root . querySelector ( '[data-testid="title-test-files"]' ) ?. textContent ) . toEqual ( 'Test files' ) ; 
5247  } ) ; 
5348} ) ; 
5449
55- async  function  buildHtmlReportForTestSmells ( exportsOptions : ExportOptions ,  filePath : string )  { 
56-   const  smellsFound : SmellsList [ ]  =  [ ] ; 
57-   const  aggregatedData : AggregatedData  =  {  data : smellsFound ,  totalSmells : 0 ,  averageSmellsPerTestFile : 0  } ; 
58- 
59-   const  reporter  =  new  HtmlOutput ( ) ; 
60-   await  reporter . writeTo ( aggregatedData ,  exportsOptions ) ; 
61- 
62-   const  generatedHtml  =  readFileSync ( filePath ,  {  encoding : 'utf8' ,  flag : 'r'  } ) ; 
63-   return  generatedHtml ; 
64- } 
0 commit comments