Add native image resize tests
This commit is contained in:
parent
042684fb38
commit
6a7f0d70fd
1 changed files with 20 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const nativeImage = require('electron').nativeImage
|
||||
const {nativeImage} = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
describe('nativeImage module', () => {
|
||||
|
@ -61,4 +61,23 @@ describe('nativeImage module', () => {
|
|||
assert.equal(image.getSize().width, 256)
|
||||
})
|
||||
})
|
||||
|
||||
describe('resize(options)', () => {
|
||||
it('returns a resized image', () => {
|
||||
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||
assert.deepEqual(image.resize({}).getSize(), {width: 538, height: 190})
|
||||
assert.deepEqual(image.resize({width: 400}).getSize(), {width: 400, height: 190})
|
||||
assert.deepEqual(image.resize({height: 123}).getSize(), {width: 538, height: 123})
|
||||
assert.deepEqual(image.resize({width: 80, height: 65}).getSize(), {width: 80, height: 65})
|
||||
})
|
||||
|
||||
it('supports a quality option', () => {
|
||||
const image = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
|
||||
const good = image.resize({width: 100, height: 100, quality: 'good'})
|
||||
const better = image.resize({width: 100, height: 100, quality: 'better'})
|
||||
const best = image.resize({width: 100, height: 100, quality: 'best'})
|
||||
assert(good.toPNG().length <= better.toPNG().length)
|
||||
assert(better.toPNG().length < best.toPNG().length)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue