Skip to content

Instantly share code, notes, and snippets.

@naoki-iwami
Created September 12, 2016 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naoki-iwami/c5ceba0b02bee3b6bbcd1545c111ab98 to your computer and use it in GitHub Desktop.
Save naoki-iwami/c5ceba0b02bee3b6bbcd1545c111ab98 to your computer and use it in GitHub Desktop.
task appendCaptureToReport() << {
def File basedir = project.projectDir
def root = new File(basedir, 'build/reports/tests/capture')
def buffs = [:]
root.eachFileRecurse(FileType.FILES) {
def path = root.toPath().relativize(it.toPath()).toString()
def dir = path.substring(0, path.lastIndexOf('/'))
if (dir =~ /Spec$/) {
def picName = path.substring(path.lastIndexOf('/') + 1)
println dir + " : " + picName
if (!buffs[dir]) {
buffs[dir] = []
}
buffs[dir] << picName
}
}
buffs.each { k, v ->
println k // Spec名
def htmlFile = new File(basedir, 'build/reports/tests/classes/' + k.replace('/', '.') + '.html')
if (!(k =~ /^jp/)) {
htmlFile = new File(basedir, 'build/reports/tests/classes/' + k.replaceAll(/^[^\/]+\//, "").replace('/', '.') + '.html')
}
println htmlFile.absolutePath
if (htmlFile.exists()) {
def html = '<br /><br /><br /><ul>'
v.each {
html += '<li>' + it + '<br /><br />' + '<img src="../capture/' + k + '/' + it + '">'
html += '</li>'
}
html += '</ul>'
def orgHtml = htmlFile.text
def pos = orgHtml.lastIndexOf('<div id="tab1" class="tab">')
if (pos >= 0) {
htmlFile.text = orgHtml.substring(0, pos) + html + orgHtml.substring(pos)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment