Created
September 12, 2016 02:21
-
-
Save naoki-iwami/c5ceba0b02bee3b6bbcd1545c111ab98 to your computer and use it in GitHub Desktop.
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
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