mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose control of the number of open files in libvips' cache.
Breaks API of existing cache method. Disable libvips cache for I/O tests.
This commit is contained in:
@@ -4,8 +4,6 @@ var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
var sharp = require('../../index');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Alpha transparency', function() {
|
||||
|
||||
it('Flatten to black', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Blur', function() {
|
||||
|
||||
it('specific radius 1', function(done) {
|
||||
|
||||
@@ -6,9 +6,15 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Clone', function() {
|
||||
|
||||
before(function() {
|
||||
sharp.cache(false);
|
||||
});
|
||||
after(function() {
|
||||
sharp.cache(true);
|
||||
});
|
||||
|
||||
it('Read from Stream and write to multiple Streams', function(done) {
|
||||
var finishEventsExpected = 2;
|
||||
// Output stream 1
|
||||
@@ -55,4 +61,5 @@ describe('Clone', function() {
|
||||
// Go
|
||||
fs.createReadStream(fixtures.inputJpg).pipe(rotator);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Colour space conversion', function() {
|
||||
|
||||
it('To greyscale', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Crop gravities', function() {
|
||||
|
||||
var testSettings = [
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Embed', function() {
|
||||
|
||||
it('JPEG within PNG, no alpha channel', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Partial image extraction', function() {
|
||||
describe('using the legacy extract(top,left,width,height) syntax', function () {
|
||||
it('JPEG', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Gamma correction', function() {
|
||||
|
||||
it('value of 0.0 (disabled)', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Interpolation', function() {
|
||||
|
||||
it('nearest neighbour', function(done) {
|
||||
|
||||
@@ -6,10 +6,15 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Input/output', function() {
|
||||
|
||||
before(function() {
|
||||
sharp.cache(false);
|
||||
});
|
||||
after(function() {
|
||||
sharp.cache(true);
|
||||
});
|
||||
|
||||
it('Read from File and write to Stream', function(done) {
|
||||
var writable = fs.createWriteStream(fixtures.outputJpg);
|
||||
writable.on('finish', function() {
|
||||
|
||||
@@ -8,8 +8,6 @@ var icc = require('icc');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Image metadata', function() {
|
||||
|
||||
it('JPEG', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Negate', function() {
|
||||
it('negate (jpeg)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Normalization', function () {
|
||||
|
||||
it('uses the same prototype for both spellings', function () {
|
||||
|
||||
@@ -4,8 +4,6 @@ var assert = require('assert');
|
||||
var fixtures = require('../fixtures');
|
||||
var sharp = require('../../index');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
// Helpers
|
||||
var getPaths = function(baseName, extension) {
|
||||
if (typeof extension === 'undefined') {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Resize dimensions', function() {
|
||||
|
||||
it('Exact crop', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Rotation', function() {
|
||||
|
||||
['Landscape', 'Portrait'].forEach(function(orientation) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Sharpen', function() {
|
||||
|
||||
it('specific radius 10', function(done) {
|
||||
|
||||
@@ -5,8 +5,6 @@ var assert = require('assert');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
describe('Threshold', function() {
|
||||
it('threshold 1 jpeg', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
|
||||
@@ -10,8 +10,6 @@ var rimraf = require('rimraf');
|
||||
var sharp = require('../../index');
|
||||
var fixtures = require('../fixtures');
|
||||
|
||||
sharp.cache(0);
|
||||
|
||||
// Verifies all tiles in a given dz output directory are <= size
|
||||
var assertDeepZoomTiles = function(directory, expectedSize, expectedLevels, done) {
|
||||
// Get levels
|
||||
|
||||
@@ -10,20 +10,48 @@ describe('Utilities', function() {
|
||||
|
||||
describe('Cache', function() {
|
||||
it('Can be disabled', function() {
|
||||
var cache = sharp.cache(0, 0);
|
||||
assert.strictEqual(0, cache.memory);
|
||||
assert.strictEqual(0, cache.items);
|
||||
sharp.cache(false);
|
||||
var cache = sharp.cache(false);
|
||||
assert.strictEqual(cache.memory.current, 0);
|
||||
assert.strictEqual(cache.memory.max, 0);
|
||||
assert.strictEqual(typeof cache.memory.high, 'number');
|
||||
assert.strictEqual(cache.files.current, 0);
|
||||
assert.strictEqual(cache.files.max, 0);
|
||||
assert.strictEqual(cache.items.current, 0);
|
||||
assert.strictEqual(cache.items.max, 0);
|
||||
});
|
||||
it('Can be set to a maximum of 50MB and 500 items', function() {
|
||||
var cache = sharp.cache(50, 500);
|
||||
assert.strictEqual(50, cache.memory);
|
||||
assert.strictEqual(500, cache.items);
|
||||
it('Can be enabled with defaults', function() {
|
||||
var cache = sharp.cache(true);
|
||||
assert.strictEqual(cache.memory.max, 50);
|
||||
assert.strictEqual(cache.files.max, 20);
|
||||
assert.strictEqual(cache.items.max, 100);
|
||||
});
|
||||
it('Can be set to zero', function() {
|
||||
var cache = sharp.cache({
|
||||
memory: 0,
|
||||
files: 0,
|
||||
items: 0
|
||||
});
|
||||
assert.strictEqual(cache.memory.max, 0);
|
||||
assert.strictEqual(cache.files.max, 0);
|
||||
assert.strictEqual(cache.items.max, 0);
|
||||
});
|
||||
it('Can be set to a maximum of 10MB, 100 files and 1000 items', function() {
|
||||
var cache = sharp.cache({
|
||||
memory: 10,
|
||||
files: 100,
|
||||
items: 1000
|
||||
});
|
||||
assert.strictEqual(cache.memory.max, 10);
|
||||
assert.strictEqual(cache.files.max, 100);
|
||||
assert.strictEqual(cache.items.max, 1000);
|
||||
});
|
||||
it('Ignores invalid values', function() {
|
||||
sharp.cache(50, 500);
|
||||
sharp.cache(true);
|
||||
var cache = sharp.cache('spoons');
|
||||
assert.strictEqual(50, cache.memory);
|
||||
assert.strictEqual(500, cache.items);
|
||||
assert.strictEqual(cache.memory.max, 50);
|
||||
assert.strictEqual(cache.files.max, 20);
|
||||
assert.strictEqual(cache.items.max, 100);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user