Skip to content

Commit

Permalink
fix: fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Nov 13, 2017
1 parent c8d33a7 commit 6cbddcd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/format/formatCodeFrame.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const {codeFrameColumns} = require('@babel/code-frame');

const formatCodeFrame = (filePath, line, column) => {
const formatCodeFrame = (filePath, line, column, margin = 4) => {
try {
const source = fs.readFileSync(filePath, 'utf8');
const location = {
Expand All @@ -11,11 +11,15 @@ const formatCodeFrame = (filePath, line, column) => {
}
};

return codeFrameColumns(source, location, {
const formatted = codeFrameColumns(source, location, {
highlightCode: true,
linesAbove: 4,
linesBelow: 4
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 '';
}
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/failingTestSuite.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"name":"/jest-tap-reporter/test/index.spec.js",
"startTime":1500478841634,
"status":"failed",
"summary":""
"summary":"",
"testFilePath": "/jest-tap-reporter/test/TapReporter.spec.js"
}
3 changes: 2 additions & 1 deletion test/fixtures/severalTestsSuite.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
"name":"/jest-tap-reporter/test/index.spec.js",
"startTime":1500478996144,
"status":"passed",
"summary":""
"summary":"",
"testFilePath": "/jest-tap-reporter/test/TapReporter.spec.js"
}
3 changes: 2 additions & 1 deletion test/fixtures/skippedTestSuite.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"name":"/jest-tap-reporter/test/index.spec.js",
"startTime":1500479077405,
"status":"passed",
"summary":""
"summary":"",
"testFilePath": "/jest-tap-reporter/test/TapReporter.spec.js"
}

0 comments on commit 6cbddcd

Please sign in to comment.