Giter Club home page Giter Club logo

middleware-browser-coverage-demo's Introduction

Test application

A simple express application to demonstrate how the library works.

$ node index.js # start the app without coverage

$ node index.js --coverage # start the app with coverage

$ open http://localhost:8888/coverage # shows coverage info

$ curl -o coverage.zip http://localhost:8888/coverage/download # gives you the zip file with reports

================

Difference with original version: Add coverage data collector for clients.

Steps to add this function:

  • Add sending coverage data fucntion in public/js/client.js:
--- a/public/js/client.js
+++ b/public/js/client.js
@@ -5,4 +5,18 @@ $(function () {
         link.attr('href', '/authors/' + $(this).attr('id'));
         return link;
     });
-});
\ No newline at end of file
+});
+
+// post window.__coverage__ to server every 2 seconds
+setInterval(function() {
+    $.ajax({
+        url: "/coverage/client",
+        type: "POST",
+        data: JSON.stringify(window.__coverage__),
+        contentType: "application/json; charset=utf-8",
+        dataType:"json",
+        success: function(data) {
+            console.log("success!");
+        }
+    });
+}, 2000);
  • Instrument js files
$ mv public public_without_coverage  # move client side js to another folder

$ nyc instrument public_without_coverage public  # instrument
  • Update js files path in server/index.js
@@ -3,7 +3,7 @@ var path = require('path'),
     express = require('express'),
     url = require('url'),
     data = require('./data'),
-    publicDir = path.resolve(__dirname, '..', 'public'),
+    publicDir = path.resolve(__dirname, '..', 'public_without_coverage'),
     coverage = require('istanbul-middleware'),
     bodyParser = require('body-parser');
  • Get coverage data

$ open http://localhost:8888 # Run the website

$ open http://localhost:8888/coverage # shows coverage info. public_without_coverage folder should exist in report after 2 seconds.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.