mirror of
https://github.com/zhigang1992/viff.git
synced 2026-01-12 17:53:17 +08:00
remove report
This commit is contained in:
@@ -14,15 +14,12 @@ module.exports = function(grunt) {
|
||||
'lib/viff.js': 'src/viff.coffee',
|
||||
'lib/comparison.js': 'src/comparison.coffee',
|
||||
'lib/index.js': 'src/index.coffee',
|
||||
'lib/reporter.js': 'src/reporter.coffee',
|
||||
'lib/color.helper.js': 'src/color.helper.coffee',
|
||||
'lib/html.report.template.js': 'src/html.report.template.coffee',
|
||||
'lib/process.argv.js': 'src/process.argv.coffee',
|
||||
'lib/image.generator.js': 'src/image.generator.coffee',
|
||||
'lib/console.status.js': 'src/console.status.coffee',
|
||||
'test/build/comparison_test.js': 'test/src/comparison_test.coffee',
|
||||
'test/build/viff_test.js': 'test/src/viff_test.coffee',
|
||||
'test/build/reporter_test.js': 'test/src/reporter_test.coffee',
|
||||
'test/build/process_argv_test.js': 'test/src/process_argv_test.coffee',
|
||||
'test/build/image_generator_test.js': 'test/src/image_generator_test.coffee'
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
|
||||
template = """
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf8"/>
|
||||
<title>Viff Report</title>
|
||||
<style type="text/css">
|
||||
@import url(http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600);
|
||||
body{font: normal normal 14px/1.5 'Open Sans', sans-serif; }
|
||||
body,ul,h1,h2,h3,h4{margin:0;padding:0;font-weight:300;font-style:normal;}
|
||||
body{margin: 20px;}
|
||||
h1{font-size: 3em;}
|
||||
h2{font-size: 2.4em;}
|
||||
ul{overflow: hidden;}
|
||||
li{list-style-type: none; margin-bottom: 20px; overflow: hidden;}
|
||||
a {float: left;height: 100px;width: 100px; overflow: hidden; margin-right:1%; position: relative;}
|
||||
a:before {
|
||||
content: attr(data-env);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100px;
|
||||
font-size: 30px;
|
||||
line-height: 100px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
text-transform:lowercase;
|
||||
color: #000;
|
||||
background: #eee;
|
||||
opacity: .8;
|
||||
}
|
||||
a:nth-of-type(3):before {
|
||||
background: #C0392B;
|
||||
color: #fff;
|
||||
}
|
||||
img{max-width: 600px;}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Viff Report - ({{sameCount}} same in {{caseCount}} cases) {{totalAnalysisTime}}ms</h1>
|
||||
{{#each compares}}
|
||||
<h2>{{@key}}</h2>
|
||||
<ul>
|
||||
{{#each this}}
|
||||
<li>
|
||||
<h3>{{@key}} - {{this.misMatchPercentage}}% mismatch {{this.analysisTime}}ms</h3>
|
||||
{{#each this.images}}
|
||||
<a href="data:image/png;base64,{{this}}" data-env="{{@key}}">
|
||||
<img src="data:image/png;base64,{{this}}"/>
|
||||
</a>
|
||||
{{/each}}
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/each}}
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
module.exports = template
|
||||
@@ -2,7 +2,6 @@ _ = require 'underscore'
|
||||
require 'webdriver-helper'
|
||||
|
||||
Viff = require './viff.js'
|
||||
Reporter = require './reporter.js'
|
||||
processArgs = require './process.argv.js'
|
||||
consoleStatus = require './console.status.js'
|
||||
imgGen = require './image.generator'
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
require './color.helper.js'
|
||||
_ = require 'underscore'
|
||||
handlebars = require 'handlebars'
|
||||
template = require './html.report.template.js'
|
||||
ImageGenerator = require './image.generator.js'
|
||||
|
||||
render = handlebars.compile template
|
||||
|
||||
class Reporter
|
||||
constructor: (@compares) ->
|
||||
@cases = []
|
||||
@differences = []
|
||||
@totalAnalysisTime = 0
|
||||
|
||||
for browser, urls of @compares
|
||||
for url, diff of urls
|
||||
diffCase = {}
|
||||
diffCase[url] = diff
|
||||
|
||||
@cases.push diffCase
|
||||
@differences.push(diffCase) if diff.misMatchPercentage isnt 0
|
||||
@totalAnalysisTime += diff.analysisTime
|
||||
|
||||
@caseCount = @cases.length
|
||||
@diffCount = @differences.length
|
||||
|
||||
to: (format = 'html') ->
|
||||
reportObj =
|
||||
compares: @compares
|
||||
caseCount: @caseCount
|
||||
sameCount: @caseCount - @diffCount
|
||||
diffCount: @diffCount
|
||||
totalAnalysisTime: @totalAnalysisTime
|
||||
|
||||
return render reportObj if format is 'html'
|
||||
return JSON.stringify(reportObj) if format is 'json'
|
||||
|
||||
if format is 'file'
|
||||
ImageGenerator.generate reportObj
|
||||
return ''
|
||||
|
||||
|
||||
module.exports = Reporter
|
||||
@@ -1,90 +0,0 @@
|
||||
_ = require 'underscore'
|
||||
sinon = require 'sinon'
|
||||
Reporter = require '../../lib/reporter.js'
|
||||
ImageGenerator = require '../../lib/image.generator.js'
|
||||
|
||||
module.exports =
|
||||
setUp: (callback) ->
|
||||
@compares =
|
||||
chrome:
|
||||
'/404.html':
|
||||
isSameDimensions: true
|
||||
misMatchPercentage: 2.5
|
||||
analysisTime: 51
|
||||
images:
|
||||
build: 'aaa'
|
||||
prod: 'bbb'
|
||||
|
||||
'/strict-mode':
|
||||
isSameDimensions: false
|
||||
misMatchPercentage: 4
|
||||
analysisTime: 52
|
||||
images:
|
||||
build: 'ccc'
|
||||
prod: 'ddd'
|
||||
|
||||
firefox:
|
||||
'/404.html':
|
||||
isSameDimensions: true
|
||||
misMatchPercentage: 3
|
||||
analysisTime: 53
|
||||
images:
|
||||
build: 'eee'
|
||||
prod: 'fff'
|
||||
|
||||
'/strict-mode':
|
||||
isSameDimensions: false
|
||||
misMatchPercentage: 0
|
||||
analysisTime: 54
|
||||
images:
|
||||
build: 'ggg'
|
||||
prod: 'hhh'
|
||||
|
||||
callback()
|
||||
tearDown: (callback) ->
|
||||
callback()
|
||||
|
||||
'it should contains 4 diffs': (test) ->
|
||||
reporter = new Reporter @compares
|
||||
test.equals reporter.caseCount, 4
|
||||
test.done()
|
||||
|
||||
'it should count how mamy diff is there': (test) ->
|
||||
reporter = new Reporter @compares
|
||||
test.equals reporter.diffCount, 3
|
||||
test.done()
|
||||
|
||||
'it should return total analysisTime': (test) ->
|
||||
reporter = new Reporter @compares
|
||||
test.equals reporter.totalAnalysisTime, 210
|
||||
test.done()
|
||||
|
||||
'it should generate correct html': (test) ->
|
||||
html = new Reporter(@compares).to 'html'
|
||||
|
||||
test.ok html.indexOf('<h2>chrome</h2>') > 0
|
||||
test.ok html.indexOf('<h3>/404.html - 3% mismatch 53ms</h3>') > 0
|
||||
test.ok html.indexOf('data:image/png;base64,ggg') > 0
|
||||
test.ok html.indexOf('data-env="build"') > 0
|
||||
test.ok html.indexOf('<h1>Viff Report - (1 same in 4 cases) 210ms</h1>') > 0
|
||||
test.done()
|
||||
|
||||
'it should generate correct json': (test) ->
|
||||
jsonStr = new Reporter(@compares).to 'json'
|
||||
json = JSON.parse jsonStr
|
||||
|
||||
test.equals json.caseCount, 4
|
||||
test.equals json.diffCount, 3
|
||||
test.equals json.totalAnalysisTime, 210
|
||||
test.ok _.isEqual _.keys(json.compares), ['chrome', 'firefox']
|
||||
test.ok _.isEqual _.keys(json.compares.chrome['/404.html'].images), ['build', 'prod']
|
||||
test.ok _.isEqual _.values(json.compares.chrome['/404.html'].images), ['aaa', 'bbb']
|
||||
test.done()
|
||||
|
||||
'it should generate correct file-based json': (test) ->
|
||||
generate = sinon.stub(ImageGenerator, 'generate').returns 'undefined'
|
||||
new Reporter(@compares).to 'file'
|
||||
|
||||
test.ok generate.calledOnce
|
||||
test.equals generate.lastCall.args[0].compares, @compares
|
||||
test.done()
|
||||
Reference in New Issue
Block a user