import { loadImage, loadImageData } from './load-image'; const canvas = require('canvas'); describe('utils/loadImage', () => { describe('loadImage', () => { it('加载 oss 上的图片', async () => { const url = 'https://st-gdx.dancf.com/gaodingx/211/configs/filters_config/20190807-101523-fa07.jpg'; const image = await loadImage(url); expect(image.width).toBe(2000); expect(image.height).toBe(2000); }); it('加载图片失败丢出异常', async () => { const url = 'file://invalid_image_src'; try { await loadImage(url); throw new Error('不能执行到这里'); } catch(error) { expect(error.message).toMatch(/load image failed/); } }); }); describe('loadImageData', () => { it('加载图片并输出 imageData', async() => { const url = 'https://st-gdx.dancf.com/gaodingx/211/configs/filters_config/20190807-101523-fa07.jpg'; const image = await canvas.loadImage(url); const imageData = loadImageData(image); expect(imageData.data.length).toBe(image.width * image.height * 4); }); }); });