smartjimp/test/test.ts

28 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2023-11-24 19:08:48 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
2023-01-09 17:17:33 +00:00
import * as smartjimp from '../ts/index.js';
2023-11-24 19:08:48 +00:00
import * as smartfile from '@push.rocks/smartfile';
2020-02-02 20:10:42 +00:00
let testSmartJimp: smartjimp.SmartJimp;
2020-02-01 17:24:41 +00:00
tap.test('first test', async () => {
2023-12-03 22:09:48 +00:00
testSmartJimp = new smartjimp.SmartJimp({ mode: 'sharp'});
2023-01-09 17:17:33 +00:00
expect(testSmartJimp).toBeInstanceOf(smartjimp.SmartJimp);
});
tap.test('should be able to create a master', async () => {
2023-11-24 19:08:48 +00:00
const smartfileInstance = await smartfile.SmartFile.fromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80')
const convertedAsset = await testSmartJimp.getFromSmartfile(smartfileInstance, {width: 500});
(await smartfile.SmartFile.fromBuffer('.nogit/result.avif', convertedAsset)).write();
2020-02-02 20:10:42 +00:00
});
2020-02-01 17:24:41 +00:00
2023-12-03 22:09:48 +00:00
tap.test('should be able to use jimp', async () => {
const testSmartJimp = new smartjimp.SmartJimp({ mode: 'jimp'});
const smartfileInstance = await smartfile.SmartFile.fromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80')
const convertedAsset = await testSmartJimp.computeAssetVariation(smartfileInstance.contents, {
format: 'png',
});
(await smartfile.SmartFile.fromBuffer('.nogit/result2.png', convertedAsset)).write();
})
2020-02-02 20:10:42 +00:00
tap.start();