-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pify for gm doesn't seems to be working #36
Comments
Try this const image = gm(…);
pify(image.bind(image)); |
Doesn't work:
neither does Example 3. |
Oh yes off course. You have to pify pity the write function, not the others. const image = gm(…).size(100, 100);
pify(image.write.bind(image))().then(...); |
Aww, sorry, #16 seems related to your issue. About your third example:
I cannot guess what |
This one occures only when using
Edit: yeah, I was afraid that this could be related to #16 |
Maybe you want to try this: const img = gm(image.data);
const out = await pify(img.size.bind(img))(); // <-- bind to img, not to gm! If it works you may want to try // untested(!)
const autoBind = require('auto-bind');
const gm = require("gm").subClass({ imageMagick: true });
const gmP = (...args) => pify(autoBind(gm(...args)));
test("Resize JPEG with jpegoptim", async t => {
// …
const out = await gmP(destPath).size();
t.is(out.width, 200);
}); |
Unfortunately this doesn't seems to be working, I'm getting:
|
@kdybicz Above works as expected. As a #16 workaround, I suggest a small helper function: const bind = obj => {
for (const key in obj) {
const val = obj[key];
if (typeof val === 'function') {
obj[key] = val.bind(obj);
}
}
return obj;
};
const gmP = (...args) => pify(bind(gm(...args))); By the way, your tests have additional issues (see https://github.com/secretescapes/aws-lambda-image/pull/1):
|
I'm closing this, because it is a #16 duplicate. |
This is my approach to solving this issue https://github.com/ysugimoto/aws-lambda-image/pull/87/files but I will for sure take a look at your proposal. Thanks! |
Btw, const bindAll = require('bind-all');
const gmP = (...args) => pify(bindAll(gm(...args)));
test("Resize JPEG with cjpeg", async t => {
//…
const out = await gmP(destPath).size();
t.is(out.width, 200);
}); |
Thanks to your advice I did end up with code, that is working perfectly fine! https://github.com/secretescapes/aws-lambda-image/blob/improving-tests-quality-v2/test/resize-jpeg.js |
Hi,
I'm trying to fix AVA tests for some functionality and I need to Promisify
gm(...).size()
function. Unfortunately I'm not able to do that properly:So, my question is: if it's possible to
pify
gm
and if so, I would like to know how?The text was updated successfully, but these errors were encountered: