-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from MailOnline/feat/highlight
feat: highlight error code in terminal
- Loading branch information
Showing
11 changed files
with
113 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
throw new Error('Error in test suite itself, reporter should report it properly.'); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require('fs'); | ||
const {codeFrameColumns} = require('@babel/code-frame'); | ||
|
||
const formatCodeFrame = (filePath, line, column, margin = 4) => { | ||
try { | ||
const source = fs.readFileSync(filePath, 'utf8'); | ||
const location = { | ||
start: { | ||
column, | ||
line | ||
} | ||
}; | ||
|
||
const formatted = codeFrameColumns(source, location, { | ||
highlightCode: true, | ||
linesAbove: margin, | ||
linesBelow: margin | ||
}); | ||
|
||
// This below is because for some reason `@babel/code-frame` is not honoring | ||
// `linesBelow` setting. | ||
return formatted.split('\n').slice(0, 2 * margin + 1).join('\n'); | ||
} catch (error) { | ||
return ''; | ||
} | ||
}; | ||
|
||
module.exports = formatCodeFrame; |
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,6 @@ | ||
const chalk = require('chalk'); | ||
|
||
const formatFailureMessageTraceLine = (description, relativeFilePath, row, column) => | ||
chalk`${description}({cyan ${relativeFilePath}}:{black.bold ${row}}:{black.bold ${column}})`; | ||
|
||
module.exports = formatFailureMessageTraceLine; |
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,23 @@ | ||
const chalk = require('chalk'); | ||
const progressBar = require('../progressBar'); | ||
|
||
const formatStatsBar = (percent, hasErrors) => { | ||
let percentFormatted = Math.round(100 * percent) + '%'; | ||
|
||
percentFormatted = percentFormatted.padStart(3, ' '); | ||
percentFormatted = percentFormatted.padEnd(4, ' '); | ||
|
||
const bar = progressBar(percent, hasErrors ? 'red' : 'grey.dim'); | ||
|
||
let textStyles = 'green'; | ||
|
||
if (hasErrors) { | ||
textStyles = 'red.bold'; | ||
} else if (percent < 1) { | ||
textStyles = 'yellow'; | ||
} | ||
|
||
return chalk`{${textStyles} ${percentFormatted}} ${bar}`; | ||
}; | ||
|
||
module.exports = formatStatsBar; |
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