Skip to content

Commit

Permalink
fix: Adapt sources after upgrading npm dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Sep 24, 2019
1 parent 6859972 commit 457f7db
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 70 deletions.
132 changes: 66 additions & 66 deletions tasks/grunt-reg-viz.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,77 @@ const os = require('os')

module.exports = function (grunt) {
grunt.registerMultiTask('reg-viz',
'Compares pictures and shows their differences for visual regression test automation.',
function () {
const done = this.async()
const options = this.options({
thresholdRate: null,
thresholdPixel: null,
concurrency: null,
enableAntialiasing: false,
additionalDetection: 'none',
force: false
})
const data = Object.assign({}, {
expected: 'expected',
actual: 'actual',
different: 'different',
report: 'report.html'
}, this.data)
const report = data.report
const force = options.force
const warn = force ? grunt.log.warn : grunt.fail.warn
let compared = 0
const observer = compare({
actualDir: data.actual,
expectedDir: data.expected,
diffDir: data.different,
report: report,
json: report.replace(/\.html$/, '.json'),
update: false,
urlPrefix: './',
thresholdRate: Number(options.thresholdRate),
thresholdPixel: Number(options.thresholdPixel),
concurrency: Number(options.concurrency) || os.cpus().length,
enableAntialias: !!options.enableAntialiasing,
enableClientAdditionalDetection: options.additionalDetection === 'client'
})
'Compares pictures and shows their differences for visual regression test automation.',
function () {
const done = this.async()
const options = this.options({
thresholdRate: null,
thresholdPixel: null,
concurrency: null,
enableAntialiasing: false,
additionalDetection: 'none',
force: false
})
const data = Object.assign({}, {
expected: 'expected',
actual: 'actual',
different: 'different',
report: 'report.html'
}, this.data)
const report = data.report
const force = options.force
const warn = force ? grunt.log.warn : grunt.fail.warn
let compared = 0
const observer = compare({
actualDir: data.actual,
expectedDir: data.expected,
diffDir: data.different,
report: report,
json: report.replace(/\.html$/, '.json'),
update: false,
urlPrefix: './',
thresholdRate: Number(options.thresholdRate),
thresholdPixel: Number(options.thresholdPixel),
concurrency: Number(options.concurrency) || os.cpus().length,
enableAntialias: !!options.enableAntialiasing,
enableClientAdditionalDetection: options.additionalDetection === 'client'
})

observer.once('start', function () {
grunt.verbose.writeln('Comparison started.')
})
observer.once('start', function () {
grunt.verbose.writeln('Comparison started.')
})

observer.on('compare', function (result) {
const path = options.actual + result.path
++compared
switch (result.type) {
case 'pass': return grunt.verbose.writeln(path + ' matched.')
case 'fail': return grunt.verbose.writeln(path + ' differed.')
case 'delete': return grunt.verbose.writeln(path + ' removed.')
case 'new': return grunt.verbose.writeln(path + ' added.')
}
})
observer.on('compare', function (result) {
const path = options.actual + result.path
++compared
switch (result.type) {
case 'pass': return grunt.verbose.writeln(path + ' matched.')
case 'fail': return grunt.verbose.writeln(path + ' differed.')
case 'delete': return grunt.verbose.writeln(path + ' removed.')
case 'new': return grunt.verbose.writeln(path + ' added.')
}
})

observer.once('complete', function (result) {
const matched = result.passedItems.length
const differed = result.failedItems.length
const removed = result.deletedItems.length
const added = result.newItems.length
const ok = differed ? force ? grunt.log.warn : grunt.fail.warn
: grunt.log.ok
grunt.verbose.writeln('Comparison finished.')
ok(compared + ' ' + grunt.util.pluralize(compared,
'image/images') + ' compared, ' + matched + ' matched, ' +
observer.once('complete', function (result) {
const matched = result.passedItems.length
const differed = result.failedItems.length
const removed = result.deletedItems.length
const added = result.newItems.length
const ok = differed ? force ? grunt.log.warn : grunt.fail.warn
: grunt.log.ok
grunt.verbose.writeln('Comparison finished.')
ok(compared + ' ' + grunt.util.pluralize(compared,
'image/images') + ' compared, ' + matched + ' matched, ' +
differed + ' differed, ' + removed + ' removed, ' + added +
' added.')
done()
})
done()
})

observer.once('error', function (error) {
grunt.verbose.error(error.stack)
grunt.log.error(error)
warn('Comparing images failed.')
done()
})
observer.once('error', function (error) {
grunt.verbose.error(error.stack)
grunt.log.error(error)
warn('Comparing images failed.')
done()
})
})
}
8 changes: 4 additions & 4 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ exports['htmllint-html-report-converter'] = {
matching: function (test) {
test.expect(2)
const different = fs.existsSync(path.join(__dirname,
'matching/different/todos-1.png'))
'matching/different/todos-1.png'))
const report = fs.existsSync(path.join(__dirname,
'matching/report.html'))
'matching/report.html'))
test.ok(!different)
test.ok(report)
test.done()
Expand All @@ -18,9 +18,9 @@ exports['htmllint-html-report-converter'] = {
differing: function (test) {
test.expect(2)
const different = fs.existsSync(path.join(__dirname,
'differing/different/todos-2.png'))
'differing/different/todos-2.png'))
const report = fs.existsSync(path.join(__dirname,
'differing/report.html'))
'differing/report.html'))
test.ok(different)
test.ok(report)
test.done()
Expand Down

0 comments on commit 457f7db

Please sign in to comment.