Repository: sindresorhus/execa (js)

Issue:
4.0.1 causes problems with Bluebird
I've gotten an error from Bluebird when using execa at version `4.0.1`:
```
TypeError: this._then is not a function
    at Promise.then (~/.config/yarn/global/node_modules/bluebird/js/release/promise.js:154:17)
    at ChildProcess.then (~/.config/yarn/global/node_modules/execa/lib/promise.js:13:25)
```

This works fine if I downgrade execa to `4.0.0`.

Pull request description:
Fix problems with third-party Promise
Fixes #426

Patch:
diff --git a/lib/promise.js b/lib/promise.js
index f85c43a..bd9d523 100644
--- a/lib/promise.js
+++ b/lib/promise.js
@@ -1,8 +1,9 @@
 'use strict';
 
+const nativePromisePrototype = (async () => {})().constructor.prototype;
 const descriptors = ['then', 'catch', 'finally'].map(property => [
 	property,
-	Reflect.getOwnPropertyDescriptor(Promise.prototype, property)
+	Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property)
 ]);
 
 // The return value is a mixin of `childProcess` and `Promise`


Test patch:
diff --git a/test/override-promise.js b/test/override-promise.js
new file mode 100644
index 0000000..30c2465
--- /dev/null
+++ b/test/override-promise.js
@@ -0,0 +1,20 @@
+import path from 'path';
+import test from 'ava';
+
+process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;
+
+// Can't use `test.before`, because `ava` needs `Promise`.
+// Can't use `import(…)` either, because `execa` is not an ES Module.
+const nativePromise = Promise;
+global.Promise = class BrokenPromise {
+	then() {
+		throw new Error('error');
+	}
+};
+const execa = require('..');
+global.Promise = nativePromise;
+
+test('should work with third-party Promise', async t => {
+	const {stdout} = await execa('noop', ['foo']);
+	t.is(stdout, 'foo');
+});