new changes

This commit is contained in:
Niranjan
2026-04-07 05:05:28 +05:30
parent 7c070224bd
commit a18bba15f2
29975 changed files with 3247495 additions and 2761 deletions

View File

@@ -0,0 +1,13 @@
import { describe, test, expect, jest } from '@jest/globals';
import { readFile } from 'node:fs/promises';
describe('Testing CLI', () => {
test('should work', async () => {
jest.setTimeout(5000);
expect(
(await import('child_process')).execSync('node ./bin/ttf2woff2.js', {
input: await readFile('fixtures/iconsfont.ttf'),
}),
).toEqual(await readFile('fixtures/iconsfont.woff2'));
});
});

View File

@@ -0,0 +1,32 @@
import { YError, printStackTrace } from 'yerror';
import debug from 'debug';
import { env } from 'node:process';
import bindings from 'bindings'
import ttf2woff2Loader from '../jssrc/index.js';
const doDebug = debug('ttf2woff2');
const ttf2woff2 = getExecutable();
function getExecutable() {
if (!env.TTF2WOFF2_VERSION || env.TTF2WOFF2_VERSION?.toLowerCase() === 'native') {
try {
doDebug('✅ Using native version.');
return bindings.default('addon.node').convert;
} catch (err) {
doDebug('❌ Could not load the native version.', printStackTrace(err as Error));
}
}
if (!env.TTF2WOFF2_VERSION || env.TTF2WOFF2_VERSION?.toLowerCase() === 'wasm') {
try {
doDebug('✅ Using WASM version.');
return ttf2woff2Loader;
} catch (err) {
doDebug('❌ Could not load the WASM version.', printStackTrace(err as Error));
}
}
throw new YError('E_UNABLE_TO_LOAD_TTF2WOFF2', env.TTF2WOFF2_VERSION);
}
export default ttf2woff2 as NonNullable<typeof ttf2woff2>;

View File

@@ -0,0 +1,65 @@
import { describe, test, expect, jest } from '@jest/globals';
import { readFile } from 'node:fs/promises';
import { YError } from 'yerror';
describe('ttf2woff2', () => {
test('should work from the main endpoint', async () => {
jest.setTimeout(5000);
const ttf2woff2 = (await import('./index.js')).default;
const inputContent = await readFile('fixtures/iconsfont.ttf');
const outputContent = ttf2woff2(inputContent);
expect(outputContent.length).toEqual(1072);
expect(outputContent[1071]).toEqual(0);
expect(outputContent).toEqual(await readFile('fixtures/iconsfont.woff2'));
});
test('should work from the native build', async () => {
const ttf2woff2 = (await import('bindings')).default('addon.node').convert;
const inputContent = await readFile('fixtures/iconsfont.ttf');
const outputContent = ttf2woff2(inputContent);
expect(outputContent.length).toEqual(1072);
expect(outputContent[1071]).toEqual(0);
expect(outputContent).toEqual(await readFile('fixtures/iconsfont.woff2'));
});
test('should well fail from the native build', async () => {
const ttf2woff2 = (await import('bindings')).default('addon.node').convert;
const inputContent = Buffer.alloc(2 ** 32, 0xff);
try {
ttf2woff2(inputContent);
throw new YError('E_UNEXPECTED_SUCCESS');
} catch (err) {
expect(err).toMatchInlineSnapshot(`[Error: E_CONVERT_ERROR]`);
}
});
test('should work from the Emscripten endpoint', async () => {
jest.setTimeout(5000);
const ttf2woff2 = (await import('../jssrc/index.js')).default;
const inputContent = await readFile('fixtures/iconsfont.ttf');
const outputContent = ttf2woff2(inputContent);
expect(outputContent.length).toEqual(1072);
expect(outputContent[1071]).toEqual(0);
expect(outputContent).toEqual(await readFile('fixtures/iconsfont.woff2'));
});
test('should well fail from the Emscripten build', async () => {
jest.setTimeout(5000);
const ttf2woff2 = (await import('../jssrc/index.js')).default;
const inputContent = Buffer.alloc(512, 0xff);
try {
ttf2woff2(inputContent);
throw new YError('E_UNEXPECTED_SUCCESS');
} catch (err) {
expect(err).toMatchInlineSnapshot(`[YError: E_CONVERT_ERROR (): E_CONVERT_ERROR]`);
}
});
});