Skip to content

Duplicate resolution of promises within util #81

@matmar10

Description

@matmar10

Several areas of the lib/utils.js have duplicate resolution of promises - where an error calls BOTH reject AND resolve:

Example:

  return new Promise((resolve, reject) => {
    fs.readFile(file, 'utf8', function(err, data) {
      if (err) {
        reject(err);
      }

      resolve(data);
    });
  });

This will BOTH reject and resolve the error.

Also, the test cases are ambiguously written. It's not clear what behavior is actually expected:

    it('should handle glob error', function(done) {
      var files = new Error('custom: glob error');

      utils.readFileGlobs(files)
      .then(function() {
        done('readFileGlobs did not throw error');
      })
      .catch(function(err) {
        expect(err.message).to.equal('custom: glob error');
        done();
      });
    });

Because the done() method accepts an error. Fro the Mocha docs:

This callback accepts both an Error instance (or subclass thereof) or a falsy value; anything else is invalid usage and throws an error (usually causing a failed test).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions