Skip to content

Commit

Permalink
Return a true promise (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Aug 20, 2024
1 parent e56bf06 commit 102d1c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 2 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,9 @@ export default function nanoSpawn(command, arguments_ = [], {signal, timeout, na
const stdoutLines = lineIterator(subprocess.stdout);
const stderrLines = lineIterator(subprocess.stderr);

return {
return Object.assign(promise, {
[Symbol.asyncIterator]: () => combineAsyncIterables(stdoutLines, stderrLines),
stdout: stdoutLines,
stderr: stderrLines,
/* eslint-disable promise/prefer-await-to-then */
then(onFulfilled, onRejected) { // eslint-disable-line unicorn/no-thenable
return promise.then(onFulfilled, onRejected);
},
catch(onRejected) {
return promise.catch(onRejected);
},
finally(onFinally) {
return promise.finally(onFinally);
},
/* eslint-enable promise/prefer-await-to-then */
};
});
}
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ test('rejects on error', async t => {
nanoSpawn('non-existent-command'),
);
});

test('returns a promise', async t => {
const result = nanoSpawn('echo');
t.false(Object.prototype.propertyIsEnumerable.call(result, 'then'));
t.false(Object.hasOwn(result, 'then'));
t.true(result instanceof Promise);
await result;
});

0 comments on commit 102d1c1

Please sign in to comment.