question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pify for gm doesn't seems to be working

See original GitHub issue

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:

const out = await pify(gm(image.data).size());
console.log("gm output: " + out.width);
---
  gm output: undefined
const out = await pify(gm(image.data).size)();
console.log("gm output: " + out.width);
---
  1 failed

  resize-jpeg › Resize JPEG with jpegoptim
  Error: Cannot read property 'size' of undefined
    proto.(anonymous function) (node_modules/gm/lib/getters.js:47:20)
    node_modules/pify/index.js:29:7
    node_modules/pify/index.js:12:10
    ret (node_modules/pify/index.js:56:34)
    Test.<anonymous> (test/resize-jpeg.js:37:20)
    Generator.next (<anonymous>)
const out = await pify(gm(image.data).size.bind(gm))();
console.log("gm output: " + out.width);
---
  1 failed

  resize-jpeg › Resize JPEG with jpegoptim
  Error: Cannot read property 'size' of undefined
    proto.(anonymous function) (node_modules/gm/lib/getters.js:47:20)
    node_modules/pify/index.js:29:7
    node_modules/pify/index.js:12:10
    ret (node_modules/pify/index.js:56:34)
    Test.<anonymous> (test/resize-jpeg.js:37:20)
    Generator.next (<anonymous>)
const out = await pify(gm(image.data)).size();
console.log("gm output: " + out.width);
---
  1 failed

  resize-jpeg › Resize JPEG with jpegoptim
  Error: pify(...).size is not a function
    Test.<anonymous> (test/resize-jpeg.js:37:43)
    Generator.next (<anonymous>)

So, my question is: if it’s possible to pify gm and if so, I would like to know how?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
schnittstabilcommented, Jan 30, 2017

Btw, bind-all provides the same functionality as my bind helper above:

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);
});
0reactions
kdybiczcommented, Jan 30, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Diagnose Your Engine Control Unit - Symptoms of Bad ...
Our step-by-step guide will help you diagnose your ECU with symptoms of bad/faulty units, testing recommendations & an affordable ECU repair service.
Read more >
How flexible is Shopify Plus? With Loren Padelford, VP & GM ...
Shopify themselves doesn't think so. My goal with all of this content I create is to get you the truth by cutting through...
Read more >
Set up the Google channel - Shopify Help Center
Set up the Google channel to sync products to Google and for use in Google Performance Max campaigns.
Read more >
Lane Keep Assist Safety Feature | Vehicle Support | Chevy
Lane Keep Assist with Lane Departure Warning uses a brief, gentle steering wheel turn to alert † you when you may be unintentionally...
Read more >
Complete Cylinder Heads Guide for Big-Block Chevy Engines
Note that domed pistons designed for open chamber cylinder heads do not work with closed chamber heads due to insufficient clearance. While introduced...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found