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,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 fs = require('node:fs');
@@ -8,7 +9,7 @@ const sharp = require('../../lib');
const fixtures = require('../fixtures');
describe('failOn', () => {
it('handles truncated JPEG', function (done) {
it('handles truncated JPEG', function (_t, done) {
sharp(fixtures.inputJpgTruncated, { failOn: 'none' })
.resize(32, 24)
.toBuffer(function (err, data, info) {
@@ -20,7 +21,7 @@ describe('failOn', () => {
});
});
it('handles truncated PNG, emits warnings', function (done) {
it('handles truncated PNG, emits warnings', function (_t, done) {
let isWarningEmitted = false;
sharp(fixtures.inputPngTruncated, { failOn: 'none' })
.on('warning', function (warning) {
@@ -68,7 +69,7 @@ describe('failOn', () => {
);
});
it('returns errors to callback for truncated JPEG', function (done) {
it('returns errors to callback for truncated JPEG', function (_t, done) {
sharp(fixtures.inputJpgTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
assert.ok(err.message.includes('VipsJpeg: premature end of'), err);
assert.strictEqual(data, undefined);
@@ -77,7 +78,7 @@ describe('failOn', () => {
});
});
it('returns errors to callback for truncated PNG', function (done) {
it('returns errors to callback for truncated PNG', function (_t, done) {
sharp(fixtures.inputPngTruncated, { failOn: 'truncated' }).toBuffer(function (err, data, info) {
assert.ok(err.message.includes('read error'), err);
assert.strictEqual(data, undefined);
@@ -86,7 +87,7 @@ describe('failOn', () => {
});
});
it('rejects promises for truncated JPEG', function (done) {
it('rejects promises for truncated JPEG', function (_t, done) {
sharp(fixtures.inputJpgTruncated, { failOn: 'error' })
.toBuffer()
.then(() => {