Skip to content

Commit

Permalink
chore: coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Feb 17, 2024
1 parent f7652cd commit 36b7d8e
Show file tree
Hide file tree
Showing 9 changed files with 522 additions and 291 deletions.
783 changes: 495 additions & 288 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/image-shrink/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
LICENSE
src/test/snapshots
coverage
3 changes: 2 additions & 1 deletion packages/image-shrink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"scripts": {
"prepack": "cp ../../LICENSE ./LICENSE",
"clean": "rimraf dist",
"test": "npx playwright install-deps chromium && vitest --run",
"test": "npx playwright install-deps chromium && vitest --run --coverage",
"test:watch": "npx playwright install-deps chromium && vitest",
"prebuild": "npm run clean",
"build": "npm run build:types && npm run build:compile",
Expand Down Expand Up @@ -47,6 +47,7 @@
"@imagemagick/magick-wasm": "^0.0.28",
"@types/content-type": "^1.1.8",
"@vitest/browser": "^1.2.2",
"@vitest/coverage-istanbul": "^1.3.0",
"playwright": "^1.41.2",
"raw-body": "^2.5.2",
"ts-node": "^10.8.1",
Expand Down
Binary file not shown.
Binary file added packages/image-shrink/src/test/samples/line.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/image-shrink/src/utils/image/imageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const processImage = (
resolve(image)
})
image.addEventListener('error', () => {
reject(image)
reject(new Error('Failed to load image. Probably not an image.'))
})
}
})
Expand Down
20 changes: 19 additions & 1 deletion packages/image-shrink/src/utils/shrinkFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,25 @@ describe('shrinkFile', () => {
expect(height).toBe(500)
})

it("should skip shrink if it's not required", async () => {
it('should throw a error if the passed file is not an image', async () => {
const originalFile = new Blob(['Hello world'], { type: 'text/plain' })
const promise = shrinkFile(originalFile, {
size: 100 * 100
})
expect(promise).rejects.toThrowError('not an image')
})

it('should throw a error if unable to convert canvas to blob', async () => {
const originalFile = await loadImageAsBlob(
() => import('../test/samples/line.jpg')
)
const promise = shrinkFile(originalFile, {
size: 100 * 100
})
expect(promise).rejects.toThrowError('Failed to convert canvas to blob')
})

it("should skip shrink if it's not required and throw a error", async () => {
const originalFile = await loadImageAsBlob(
() => import('../test/samples/2000x2000.jpeg')
)
Expand Down
1 change: 1 addition & 0 deletions packages/image-shrink/src/utils/shrinkImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const shrinkImage = (
const supportNative = 'imageSmoothingQuality' in ctx

// native scaling on ios gives blurry results
// TODO: check if it's still true
const useNativeScaling = supportNative && !isIOS() && !isIpadOS

return useNativeScaling
Expand Down
3 changes: 3 additions & 0 deletions packages/image-shrink/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default defineConfig({
plugins: [uploadPlugin()],
test: {
testTimeout: 100000,
coverage: {
provider: 'istanbul'
},
browser: {
enabled: true,
name: 'chromium',
Expand Down

0 comments on commit 36b7d8e

Please sign in to comment.