title: how to replace imported modules as stub
body: <p>I would like to replace imported modules as stub so as to focus on unit testing only the main module. I've tried using sinon.stub but it seems it's not doing what I expect it to do as I keep on getting an error when running the test.</p>
  
  <pre>
      { Error: Command failed: identify: unable to open image `test.exe': No such file or directory @ error/blob.c/OpenBlob/2724.
      identify: no decode delegate for this image format `EXE' @ error/constitute.c/ReadImage/504.
  
          at ChildProcess. (/node_modules/imagemagick/imagemagick.js:88:15)
          at ChildProcess.emit (events.js:159:13)
          at maybeClose (internal/child_process.js:943:16)
          at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5) timedOut: false, killed: false, code: 1, signal: null }
  
  </pre>
  
  <p>Here is my main module.</p>
  
  <pre>
  
      // src/services/identifyService.js
      import imagemagick from 'imagemagick';
  
      class IdentifyService {
          async identify(filePath) {
              imagemagick.identify(['-format', '%w_%h', filePath], function(err, output) {
                  if (err) reject(err);
  
                  return resolve(output);
              });
          }
      }
  
  </pre>
  
  <p>And this is my test.</p>
  
  <pre>
  
      // test/identifyService.test.js
      import imagemagick from 'imagemagick';
      import IdentifyService from '../src/services/identifyService';
  
      describe('Verify image processing', () => {
          before(() => {
              const fileInfo = [{page: 1, width:100, height: 100, colorspace: 'RGB'}];
              sinon.stub(imagemagick, 'identify').returns(fileInfo);
          });
  
          it('returns metadata', (done) => {
              const metadata = IdentifyService.identify('test.exe');
              expect(metadata).to.have.lengthOf(0);
          });
      });
  
  </pre>
  
  <p>Am I doing something wrong here? Any help would be greatly appreciated.</p>