LibSquoosh: add smoke test

This commit is contained in:
Jason Miller
2021-09-07 14:26:16 -04:00
parent 255dfa434a
commit 4e04053e4c
4 changed files with 211 additions and 2094 deletions

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,8 @@
"/build/*"
],
"scripts": {
"build": "rollup -c"
"build": "rollup -c",
"test": "uvu -r ts-node/register test"
},
"keywords": [],
"author": "Google Chrome Developers <chromium-dev@google.com>",
@ -34,7 +35,9 @@
"@types/node": "^15.6.1",
"rollup": "^2.46.0",
"rollup-plugin-terser": "^7.0.2",
"ts-node": "^10.2.1",
"typescript": "^4.1.3",
"uvu": "^0.5.1",
"which": "^2.0.2"
}
}

View File

@ -0,0 +1,43 @@
import * as path from 'path';
import { test } from 'uvu';
import * as assert from 'uvu/assert';
import { ImagePool } from '..';
let imagePool: ImagePool;
test.after.each(async () => {
if (imagePool) {
try {
await imagePool.close();
} catch (e) {}
}
imagePool = undefined;
});
test('smoke test', async () => {
imagePool = new ImagePool(1);
const imagePath = path.resolve(__dirname, '../../icon-large-maskable.png');
const image = imagePool.ingestImage(imagePath);
const { bitmap } = await image.decoded;
assert.equal(bitmap.width, 1024);
await image.preprocess({
resize: {
enabled: true,
width: 100,
},
});
await image.encode({
mozjpeg: {},
});
const { size } = await image.encodedWith.mozjpeg;
// resulting image is 1554b
assert.ok(size > 500);
assert.ok(size < 5000);
});
test.run();

View File

@ -5,5 +5,12 @@
"types": ["node"],
"allowJs": true
},
"include": ["src/**/*", "../codecs/**/*"]
"include": ["src/**/*", "../codecs/**/*"],
"ts-node": {
"transpileOnly": true,
"compilerOptions": {
"module": "commonjs"
},
"include": ["tests/**/*"]
}
}