-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(image-shrink): add fallback test (#525)
* chore(image-shrink): add fallback test * chore: add missing exports found by typedoc * chore: fix typedoc build --------- Co-authored-by: nd0ut <[email protected]>
- Loading branch information
Showing
6 changed files
with
61 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/// <reference types="vite/client" /> | ||
import { describe, expect, it } from 'vitest' | ||
import { fallback } from './fallback' | ||
import { loadImageAsBlob } from '../../test/helpers/loadImageAsBlob' | ||
import { imageLoader } from '../../utils/image/imageLoader' | ||
|
||
describe('fallback', () => { | ||
it('should work', async () => { | ||
const originalFile = await loadImageAsBlob( | ||
() => import('../../test/samples/2000x2000.jpeg') | ||
) | ||
const image = await imageLoader(URL.createObjectURL(originalFile)) | ||
URL.revokeObjectURL(image.src) | ||
|
||
const canvas = await fallback({ | ||
img: image, | ||
sourceW: image.width, | ||
targetW: 100, | ||
targetH: 100, | ||
step: 0.71 | ||
}) | ||
|
||
expect(canvas.width).toBe(100) | ||
}) | ||
|
||
it('should throw if not supported', async () => { | ||
const originalFile = await loadImageAsBlob( | ||
() => import('../../test/samples/2000x2000.jpeg') | ||
) | ||
const image = await imageLoader(URL.createObjectURL(originalFile)) | ||
URL.revokeObjectURL(image.src) | ||
|
||
const promise = fallback({ | ||
img: image, | ||
sourceW: image.width, | ||
targetW: 65535 + 1, | ||
targetH: 65535 + 1, | ||
step: 0.71 | ||
}) | ||
expect(promise).rejects.toThrow('Not supported') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters