From f2ba0e8091daedc20e4d196138fbf9f841f8eb3f Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 3 Aug 2016 17:21:58 -0400 Subject: [PATCH] Avoid requiring jQuery for sending the coverage report back. --- lib/templates/test-body-footer.html | 56 ++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/templates/test-body-footer.html b/lib/templates/test-body-footer.html index 580bbe8b..573a1ac6 100644 --- a/lib/templates/test-body-footer.html +++ b/lib/templates/test-body-footer.html @@ -3,37 +3,37 @@ var coverageData = window.__coverage__; var data = JSON.stringify(coverageData || {}); - $.ajax({ - type: 'POST', - async: false, - url: '/write-coverage', - datatype: 'json', - contentType:'application/json; charset=utf-8', - data: data, - error: function(jqXHR, textStatus, errorThrown ) { - throw errorThrown; - }, - success: function(data) { - if (!data || !data.total) { - return; - } + var request = new XMLHttpRequest(); + request.open('POST', '/write-coverage', true); + request.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); + request.send(data); + request.responseType = 'json'; - var results = ['Lines', 'Branches', 'Functions', 'Statements'] - .filter(function (name) { - return data.total[name.toLowerCase()] - }) - .map(function (name) { - return name + ' ' + data.total[name.toLowerCase()].pct + '%' - }) + request.onload = function() { + var data = this.response; - $('body').append('
' + results.join(' | ') + '
'); - }, - complete: function() { - if (callback) { - callback(); - } + if (!data || !data.total) { + return; } - }); + + var results = ['Lines', 'Branches', 'Functions', 'Statements'] + .filter(function (name) { + return data.total[name.toLowerCase()] + }) + .map(function (name) { + return name + ' ' + data.total[name.toLowerCase()].pct + '%' + }); + + var resultsText = document.createTextNode(results.join(' | ')); + var element = document.createElement('div'); + element.style = 'background-color: white; color: black; border: 2px solid black; padding: 1em;position: fixed; left: 15px; bottom: 15px'; + element.appendChild(resultsText); + document.body.appendChild(element); + + if (callback) { + callback(); + } + }; } if (typeof Testem !== "undefined" && Testem.afterTests) {