-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: switch to promises/async and refactor imports
- Loading branch information
Showing
7 changed files
with
95 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
'use strict'; | ||
import * as fs from 'node:fs'; | ||
|
||
export function getTotalLines(filePath: string): number { | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
import { readFile } from 'node:fs/promises'; | ||
|
||
export async function getTotalLines(filePath: string): Promise<number> { | ||
const fileContent = await readFile(filePath, 'utf8'); | ||
return fileContent.split(/\r\n|\r|\n/).length; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
import { getTotalLines } from './getTotalLines.js'; | ||
|
||
export async function setCoveredLines( | ||
coveredLines: number[], | ||
uncoveredLines: number[], | ||
filePath: string | ||
): Promise<string> { | ||
let formattedCoveredLines: string = ''; | ||
const randomLines: number[] = []; | ||
const totalLines = await getTotalLines(filePath); | ||
for (const coveredLine of coveredLines) { | ||
if (coveredLine > totalLines) { | ||
for (let randomLineNumber = 1; randomLineNumber <= totalLines; randomLineNumber++) { | ||
if ( | ||
!uncoveredLines.includes(randomLineNumber) && | ||
!coveredLines.includes(randomLineNumber) && | ||
!randomLines.includes(randomLineNumber) | ||
) { | ||
formattedCoveredLines += `\t\t<lineToCover lineNumber="${randomLineNumber}" covered="true"/>\n`; | ||
randomLines.push(randomLineNumber); | ||
break; | ||
} | ||
} | ||
} else { | ||
formattedCoveredLines += `\t\t<lineToCover lineNumber="${coveredLine}" covered="true"/>\n`; | ||
} | ||
} | ||
return formattedCoveredLines; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters