Migrate from mocha to Node.js native test runner

Includes coverage reports when using Node.js 22 onwards
This commit is contained in:
Lovell Fuller
2025-09-21 11:04:55 +01:00
parent c446d743a2
commit f2978651f0
70 changed files with 583 additions and 541 deletions

View File

@@ -1,13 +1,14 @@
// 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('../../');
const fixtures = require('../fixtures');
describe('Partial image extraction', function () {
it('JPEG', function (done) {
it('JPEG', function (_t, done) {
sharp(fixtures.inputJpg)
.extract({ left: 2, top: 2, width: 20, height: 20 })
.toBuffer(function (err, data, info) {
@@ -18,7 +19,7 @@ describe('Partial image extraction', function () {
});
});
it('PNG', function (done) {
it('PNG', function (_t, done) {
sharp(fixtures.inputPng)
.extract({ left: 200, top: 300, width: 400, height: 200 })
.toBuffer(function (err, data, info) {
@@ -29,7 +30,7 @@ describe('Partial image extraction', function () {
});
});
it('WebP', function (done) {
it('WebP', function (_t, done) {
sharp(fixtures.inputWebP)
.extract({ left: 100, top: 50, width: 125, height: 200 })
.toBuffer(function (err, data, info) {
@@ -41,7 +42,7 @@ describe('Partial image extraction', function () {
});
describe('Animated WebP', function () {
it('Before resize', function (done) {
it('Before resize', function (_t, done) {
sharp(fixtures.inputWebPAnimated, { pages: -1 })
.extract({ left: 0, top: 30, width: 80, height: 20 })
.resize(320, 80)
@@ -53,7 +54,7 @@ describe('Partial image extraction', function () {
});
});
it('After resize', function (done) {
it('After resize', function (_t, done) {
sharp(fixtures.inputWebPAnimated, { pages: -1 })
.resize(320, 320)
.extract({ left: 0, top: 120, width: 320, height: 80 })
@@ -66,7 +67,7 @@ describe('Partial image extraction', function () {
});
});
it('TIFF', function (done) {
it('TIFF', function (_t, done) {
sharp(fixtures.inputTiff)
.extract({ left: 34, top: 63, width: 341, height: 529 })
.toBuffer(function (err, data, info) {
@@ -77,7 +78,7 @@ describe('Partial image extraction', function () {
});
});
it('Before resize', function (done) {
it('Before resize', function (_t, done) {
sharp(fixtures.inputJpg)
.extract({ left: 10, top: 10, width: 10, height: 500 })
.resize(100, 100)
@@ -89,7 +90,7 @@ describe('Partial image extraction', function () {
});
});
it('After resize and crop', function (done) {
it('After resize and crop', function (_t, done) {
sharp(fixtures.inputJpg)
.resize(500, 500, {
position: sharp.gravity.north
@@ -103,7 +104,7 @@ describe('Partial image extraction', function () {
});
});
it('Before and after resize and crop', function (done) {
it('Before and after resize and crop', function (_t, done) {
sharp(fixtures.inputJpg)
.extract({ left: 0, top: 0, width: 700, height: 700 })
.resize(500, 500, {
@@ -118,7 +119,7 @@ describe('Partial image extraction', function () {
});
});
it('Extract then rotate', function (done) {
it('Extract then rotate', function (_t, done) {
sharp(fixtures.inputPngWithGreyAlpha)
.extract({ left: 20, top: 10, width: 380, height: 280 })
.rotate(90)
@@ -131,7 +132,7 @@ describe('Partial image extraction', function () {
});
});
it('Rotate then extract', function (done) {
it('Rotate then extract', function (_t, done) {
sharp(fixtures.inputPngWithGreyAlpha)
.rotate(90)
.extract({ left: 20, top: 10, width: 280, height: 380 })
@@ -143,7 +144,7 @@ describe('Partial image extraction', function () {
});
});
it('Extract then rotate then extract', function (done) {
it('Extract then rotate then extract', function (_t, done) {
sharp(fixtures.inputPngWithGreyAlpha)
.extract({ left: 20, top: 10, width: 180, height: 280 })
.rotate(90)
@@ -156,7 +157,7 @@ describe('Partial image extraction', function () {
});
});
it('Extract then rotate non-90 anagle', function (done) {
it('Extract then rotate non-90 anagle', function (_t, done) {
sharp(fixtures.inputPngWithGreyAlpha)
.extract({ left: 20, top: 10, width: 380, height: 280 })
.rotate(45)
@@ -169,7 +170,7 @@ describe('Partial image extraction', function () {
});
});
it('Rotate then extract non-90 angle', function (done) {
it('Rotate then extract non-90 angle', function (_t, done) {
sharp(fixtures.inputPngWithGreyAlpha)
.rotate(45)
.extract({ left: 20, top: 10, width: 380, height: 280 })
@@ -217,7 +218,7 @@ describe('Partial image extraction', function () {
image: fixtures.inputJpgWithLandscapeExif8
}
].forEach(({ name, image }) => {
it(name, function (done) {
it(name, function (_t, done) {
sharp(image)
.rotate()
.extract({ left: 0, top: 208, width: 60, height: 40 })
@@ -286,7 +287,7 @@ describe('Partial image extraction', function () {
});
});
it('Bad image area', function (done) {
it('Bad image area', function (_t, done) {
sharp(fixtures.inputJpg)
.extract({ left: 3000, top: 10, width: 10, height: 10 })
.toBuffer(function (err) {