Created
November 1, 2018 17:15
-
-
Save tbremer/2b73a3af2b1e1e15146a76a6834b14a9 to your computer and use it in GitHub Desktop.
Jest Tap Plugin - es6 - flow.
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
"use strict"; | |
var _createClass = (function() { | |
function defineProperties(target, props) { | |
for (var i = 0; i < props.length; i++) { | |
var descriptor = props[i]; | |
descriptor.enumerable = descriptor.enumerable || false; | |
descriptor.configurable = true; | |
if ("value" in descriptor) descriptor.writable = true; | |
Object.defineProperty(target, descriptor.key, descriptor); | |
} | |
} | |
return function(Constructor, protoProps, staticProps) { | |
if (protoProps) defineProperties(Constructor.prototype, protoProps); | |
if (staticProps) defineProperties(Constructor, staticProps); | |
return Constructor; | |
}; | |
})(); | |
function _classCallCheck(instance, Constructor) { | |
if (!(instance instanceof Constructor)) { | |
throw new TypeError("Cannot call a class as a function"); | |
} | |
} | |
/* eslint-disable no-console, class-methods-use-this */ | |
var MyCustomReporter = (function() { | |
function MyCustomReporter() { | |
_classCallCheck(this, MyCustomReporter); | |
this.message = "TAP version 13\n\n"; | |
this.hasError = false; | |
} | |
_createClass(MyCustomReporter, [ | |
{ | |
key: "onTestResult", | |
value: function onTestResult(_, _ref) { | |
var _this = this; | |
var testResults = _ref.testResults, | |
testExecError = _ref.testExecError; | |
if (this.hasError) return; | |
if (testExecError) { | |
this.message += | |
"not ok\n\nBail Out! " + | |
testExecError.code + | |
" `" + | |
testExecError.message + | |
"`\n"; | |
this.hasError = true; | |
} | |
testResults.forEach(function(result, idx) { | |
if (idx === 0) _this.message += "1.." + testResults.length + "\n\n"; | |
var resultMessage = ""; | |
if (result.status === "passed") resultMessage += "ok"; | |
else resultMessage += "not ok"; | |
resultMessage += " " + (idx + 1) + " " + result.fullName; | |
if (result.status === "pending") resultMessage += " # SKIP"; | |
if (result.status === "failed") { | |
var errorMessages = result.failureMessages | |
.map(function(i) { | |
return i.replace(/\r?\n/g, "\r\n#").replace(/[\t ]{1,}/g, " "); | |
}) | |
.join("#"); | |
resultMessage += "\n# " + errorMessages; | |
} | |
resultMessage += "\n\n"; | |
_this.message += resultMessage; | |
}); | |
} | |
}, | |
{ | |
key: "onRunComplete", | |
value: function onRunComplete() { | |
console.log(this.message); | |
} | |
} | |
]); | |
return MyCustomReporter; | |
})(); | |
module.exports = MyCustomReporter; |
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
// @flow | |
type TestResult = {| | |
ancestorTitles: string[], | |
duration: number, | |
failureMessages: string[], | |
fullName: string, | |
location: void, | |
numPassingAsserts: number, | |
status: 'passed' | 'failed' | 'pending', | |
title: string, | |
|}; | |
type SecondArg = { | |
testResults: TestResult[], | |
testExecError: { | |
code: string, | |
message: string, | |
}, | |
}; | |
class MyCustomReporter { | |
message: string; | |
hasError: boolean; | |
constructor() { | |
this.message = 'TAP version 13\n\n'; | |
this.hasError = false; | |
} | |
onTestResult(_: void, { testResults, testExecError }: SecondArg) { | |
if (this.hasError) return; | |
if (testExecError) { | |
this.message += `not ok | |
Bail Out! ${testExecError.code} \`${testExecError.message}\`\n`; | |
this.hasError = true; | |
} | |
testResults.forEach((result: TestResult, idx: number) => { | |
if (idx === 0) this.message += `1..${testResults.length}\n\n`; | |
let resultMessage: string = ''; | |
if (result.status === 'passed') resultMessage += 'ok'; | |
else resultMessage += 'not ok'; | |
resultMessage += ` ${idx + 1} ${result.fullName}`; | |
if (result.status === 'pending') resultMessage += ' # SKIP'; | |
if (result.status === 'failed') { | |
const errorMessages = result.failureMessages | |
.map(i => i.replace(/\r?\n/g, '\r\n#').replace(/[\t ]{1,}/g, ' ')) | |
.join('#'); | |
resultMessage += `\n# ${errorMessages}`; | |
} | |
resultMessage += '\n\n'; | |
this.message += resultMessage; | |
}); | |
} | |
onRunComplete() { | |
console.log(this.message); | |
} | |
} | |
module.exports = MyCustomReporter; |
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
class MyCustomReporter { | |
constructor() { | |
this.message = "TAP version 13\n\n"; | |
this.hasError = false; | |
} | |
onTestResult(_, { testResults, testExecError }) { | |
if (this.hasError) return; | |
if (testExecError) { | |
this.message += `not ok | |
Bail Out! ${testExecError.code} \`${testExecError.message}\`\n`; | |
this.hasError = true; | |
} | |
testResults.forEach((result, idx) => { | |
if (idx === 0) this.message += `1..${testResults.length}\n\n`; | |
let resultMessage = ""; | |
if (result.status === "passed") resultMessage += "ok"; | |
else resultMessage += "not ok"; | |
resultMessage += ` ${idx + 1} ${result.fullName}`; | |
if (result.status === "pending") resultMessage += " # SKIP"; | |
if (result.status === "failed") { | |
const errorMessages = result.failureMessages | |
.map(i => i.replace(/\r?\n/g, "\r\n#").replace(/[\t ]{1,}/g, " ")) | |
.join("#"); | |
resultMessage += `\n# ${errorMessages}`; | |
} | |
resultMessage += "\n\n"; | |
this.message += resultMessage; | |
}); | |
} | |
onRunComplete() { | |
console.log(this.message); | |
} | |
} | |
module.exports = MyCustomReporter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment