Some checks failed
Test and deploy / Verify production build (push) Failing after 15m8s
27 lines
1.2 KiB
JavaScript
27 lines
1.2 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { spawnSync } from 'node:child_process';
|
|
import test from 'node:test';
|
|
|
|
test('image processing falls back to WebAssembly without native CPU support', () => {
|
|
// Isolate the native-binding simulation from the rest of the test process.
|
|
const result = spawnSync(process.execPath, ['-e', `
|
|
const Module = require('node:module');
|
|
const original = Module._load;
|
|
Module._load = function (id, ...args) {
|
|
if (id.endsWith('.node') && !id.includes('wasm32')) {
|
|
const error = new Error('Simulated unavailable native binding');
|
|
error.code = 'MODULE_NOT_FOUND';
|
|
throw error;
|
|
}
|
|
return original.call(this, id, ...args);
|
|
};
|
|
const sharp = require('sharp');
|
|
(async () => {
|
|
const image = await sharp({ create: { width: 8, height: 8, channels: 3, background: '#336699' } }).webp().toBuffer();
|
|
const metadata = await sharp(image).metadata();
|
|
if (metadata.format !== 'webp' || metadata.width !== 8 || metadata.height !== 8) throw new Error('Image round trip failed');
|
|
})().catch(error => { console.error(error); process.exitCode = 1; });
|
|
`], { encoding: 'utf8', timeout: 30000 });
|
|
assert.equal(result.status, 0, result.stderr || result.error?.message);
|
|
});
|