mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Migrate from mocha to Node.js native test runner
Includes coverage reports when using Node.js 22 onwards
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Copyright 2013 Lovell Fuller and others.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const { describe, it } = require('node:test');
|
||||
const assert = require('node:assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
@@ -15,7 +16,7 @@ describe('Rotation', function () {
|
||||
[1, 2, 3, 4, 5, 6, 7, 8].forEach(function (exifTag) {
|
||||
const input = fixtures[`inputJpgWith${orientation}Exif${exifTag}`];
|
||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}-out.jpg`);
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate`, function (done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate`, function (_t, done) {
|
||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||
|
||||
const img = sharp(input, options);
|
||||
@@ -29,7 +30,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then resize`, function (done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then resize`, function (_t, done) {
|
||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape' ? [320, 240] : [320, 427];
|
||||
|
||||
const img = sharp(input, options);
|
||||
@@ -45,7 +46,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
if (rotateMethod !== 'constructor') {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Resize then auto-rotate`, function (done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Resize then auto-rotate`, function (_t, done) {
|
||||
const [expectedWidth, expectedHeight] = orientation === 'Landscape'
|
||||
? (exifTag < 5) ? [320, 240] : [320, 240]
|
||||
: [320, 427];
|
||||
@@ -67,7 +68,7 @@ describe('Rotation', function () {
|
||||
[90, 180, 270, 45].forEach(function (angle) {
|
||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_rotate${angle}-out.jpg`);
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then rotate ${angle} ${doResize ? 'and resize' : ''}`, function (done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then rotate ${angle} ${doResize ? 'and resize' : ''}`, function (_t, done) {
|
||||
const [width, height] = (angle === 45 ? [742, 742] : [inputWidth, inputHeight]).map((x) => doResize ? Math.floor(x / 1.875) : x);
|
||||
const [expectedWidth, expectedHeight] = angle % 180 === 0 ? [width, height] : [height, width];
|
||||
|
||||
@@ -90,7 +91,7 @@ describe('Rotation', function () {
|
||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||
const flipFlopFileName = [flip && 'flip', flop && 'flop'].filter(Boolean).join('_');
|
||||
const flipFlopTestName = [flip && 'flip', flop && 'flop'].filter(Boolean).join(' & ');
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then ${flipFlopTestName} ${doResize ? 'and resize' : ''}`, function (done) {
|
||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then ${flipFlopTestName} ${doResize ? 'and resize' : ''}`, function (_t, done) {
|
||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_${flipFlopFileName}-out.jpg`);
|
||||
|
||||
const img = sharp(input, options);
|
||||
@@ -115,7 +116,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 30 degrees with semi-transparent background', function (done) {
|
||||
it('Rotate by 30 degrees with semi-transparent background', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.rotate(30, { background: { r: 255, g: 0, b: 0, alpha: 0.5 } })
|
||||
@@ -129,7 +130,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 30 degrees with solid background', function (done) {
|
||||
it('Rotate by 30 degrees with solid background', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.rotate(30, { background: { r: 255, g: 0, b: 0 } })
|
||||
@@ -142,7 +143,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 90 degrees, respecting output input size', function (done) {
|
||||
it('Rotate by 90 degrees, respecting output input size', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.resize(320, 240)
|
||||
@@ -156,7 +157,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Resize then rotate by 30 degrees, respecting output input size', function (done) {
|
||||
it('Resize then rotate by 30 degrees, respecting output input size', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.rotate(30)
|
||||
@@ -171,7 +172,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
[-3690, -450, -90, 90, 450, 3690].forEach(function (angle) {
|
||||
it(`Rotate by any 90-multiple angle (${angle}deg)`, function (done) {
|
||||
it(`Rotate by any 90-multiple angle (${angle}deg)`, function (_t, done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(240, info.width);
|
||||
@@ -182,7 +183,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
[-3750, -510, -150, 30, 390, 3630].forEach(function (angle) {
|
||||
it(`Rotate by any 30-multiple angle (${angle}deg)`, function (done) {
|
||||
it(`Rotate by any 30-multiple angle (${angle}deg)`, function (_t, done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(397, info.width);
|
||||
@@ -193,7 +194,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
|
||||
[-3780, -540, 0, 180, 540, 3780].forEach(function (angle) {
|
||||
it(`Rotate by any 180-multiple angle (${angle}deg)`, function (done) {
|
||||
it(`Rotate by any 180-multiple angle (${angle}deg)`, function (_t, done) {
|
||||
sharp(fixtures.inputJpg320x240).rotate(angle).toBuffer(function (err, _data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
@@ -203,7 +204,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', function (done) {
|
||||
it('Rotate by 270 degrees, square output ignoring aspect ratio', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(240, 240, { fit: sharp.fit.fill })
|
||||
.rotate(270)
|
||||
@@ -220,7 +221,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 315 degrees, square output ignoring aspect ratio', function (done) {
|
||||
it('Rotate by 315 degrees, square output ignoring aspect ratio', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(240, 240, { fit: sharp.fit.fill })
|
||||
.rotate(315)
|
||||
@@ -237,7 +238,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (done) {
|
||||
it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(270)
|
||||
.resize(320, 240, { fit: sharp.fit.fill })
|
||||
@@ -254,7 +255,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Auto-rotate by 270 degrees, rectangular output ignoring aspect ratio', function (done) {
|
||||
it('Auto-rotate by 270 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithLandscapeExif8)
|
||||
.resize(320, 240, { fit: sharp.fit.fill })
|
||||
.rotate()
|
||||
@@ -271,7 +272,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Rotate by 30 degrees, rectangular output ignoring aspect ratio', function (done) {
|
||||
it('Rotate by 30 degrees, rectangular output ignoring aspect ratio', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240, { fit: sharp.fit.fill })
|
||||
.rotate(30)
|
||||
@@ -288,7 +289,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag but do not rotate output', function (done) {
|
||||
it('Input image has Orientation EXIF tag but do not rotate output', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.resize(320)
|
||||
.withMetadata()
|
||||
@@ -306,7 +307,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (done) {
|
||||
it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
@@ -319,7 +320,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Override EXIF Orientation tag metadata after auto-rotate', function (done) {
|
||||
it('Override EXIF Orientation tag metadata after auto-rotate', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
@@ -337,7 +338,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (done) {
|
||||
it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithExifMirroring)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
@@ -355,7 +356,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Attempt to auto-rotate using image that has no EXIF', function (done) {
|
||||
it('Attempt to auto-rotate using image that has no EXIF', function (_t, done) {
|
||||
sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
@@ -366,7 +367,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Attempt to auto-rotate image format without EXIF support', function (done) {
|
||||
it('Attempt to auto-rotate image format without EXIF support', function (_t, done) {
|
||||
sharp(fixtures.inputPng)
|
||||
.rotate()
|
||||
.resize(320)
|
||||
@@ -440,7 +441,7 @@ describe('Rotation', function () {
|
||||
assert.strictEqual(warningMessage, 'ignoring previous rotate options');
|
||||
});
|
||||
|
||||
it('Multiple rotate: last one wins (cardinal)', function (done) {
|
||||
it('Multiple rotate: last one wins (cardinal)', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(45)
|
||||
.rotate(90)
|
||||
@@ -452,7 +453,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Multiple rotate: last one wins (non cardinal)', function (done) {
|
||||
it('Multiple rotate: last one wins (non cardinal)', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.rotate(90)
|
||||
.rotate(45)
|
||||
@@ -464,7 +465,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flip - vertical', function (done) {
|
||||
it('Flip - vertical', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip()
|
||||
@@ -482,7 +483,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flop - horizontal', function (done) {
|
||||
it('Flop - horizontal', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flop()
|
||||
@@ -500,7 +501,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Flip and flop', function (done) {
|
||||
it('Flip and flop', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip()
|
||||
@@ -514,7 +515,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Neither flip nor flop', function (done) {
|
||||
it('Neither flip nor flop', function (_t, done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320)
|
||||
.flip(false)
|
||||
@@ -528,7 +529,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Auto-rotate and flip', function (done) {
|
||||
it('Auto-rotate and flip', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.flip()
|
||||
@@ -542,7 +543,7 @@ describe('Rotation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Auto-rotate and flop', function (done) {
|
||||
it('Auto-rotate and flop', function (_t, done) {
|
||||
sharp(fixtures.inputJpgWithExif)
|
||||
.rotate()
|
||||
.flop()
|
||||
|
||||
Reference in New Issue
Block a user