Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it still useful? #93

Open
zzzgit opened this issue Jul 5, 2019 · 5 comments
Open

is it still useful? #93

zzzgit opened this issue Jul 5, 2019 · 5 comments

Comments

@zzzgit
Copy link

zzzgit commented Jul 5, 2019

const Promi = Promise
module.exports = {
    resolved: function (value) {
        return Promi.resolve(333)
    },
    rejected: function (reason) {
        return Promi.resolve(new Error("444"))
    },
    deferred: function () {
        let res, rej;
        const prom = new Promi((resolve, reject)=>{res = resolve; rej=reject})
        return {
            promise: prom,
            resolve(value){
                res(value)
            },
            reject(reason){
                rej(reason)
            }
        }
    }
};

Even node.js's built-in Promise can't pass these test cases.

image

many many errors I got....

@poelstra
Copy link

Duh, your resolved and rejected functions return custom values, instead of the values passed in by the test.

This one works as expected:

const adapter = {
	deferred: () => {
		let resolve;
		let reject;
		const promise = new Promise((res, rej) => { resolve = res; reject = rej; });
		return {
			promise,
			reject,
			resolve,
		};
	},
	rejected: (reason) => Promise.reject(reason),
	resolved: (value) => Promise.resolve(value),
};

@zzzgit
Copy link
Author

zzzgit commented Jul 24, 2019

const Pinky = Promise
module.exports = {
	resolved: function(value) {
		return Pinky.resolve(value)
	},
	rejected: function(reason) {
		return Pinky.resolve(reason)
	},
	deferred: function() {
		// eslint-disable-next-line @typescript-eslint/no-unused-vars
		let res; let rej
		const prom = new Pinky((resolve, reject) => {
			res = resolve; rej = reject
		})
		return {
			promise: prom,
			resolve: res,
			reject: rej,
		}
	},
}

OK, even though I have changed my code as you mentioned, I still got many errors.

@TotooriaHyperion
Copy link

node 14.16.0 passed all the tests.
node 16.13.0 randomly failed around 10~16 tests.

  1)  Uncaught error outside test suite:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  2)  Uncaught error outside test suite:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  3) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an asynchronously-fulfilled custom thenable for an already-rejected promise `then` calls `resolvePromise` synchronously via return from a fulfilled promise:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  4) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an asynchronously-fulfilled custom thenable for an already-rejected promise `then` calls `resolvePromise` asynchronously via return from a fulfilled promise:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  5) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` Uncaught error outside test suite:
     Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
      at processImmediate (node:internal/timers:464:21)

  6) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` synchronously via return from a fulfilled promise:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  7) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` synchronously via return from a rejected promise:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  8) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` asynchronously via return from a fulfilled promise:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  9) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` asynchronously via return from a rejected promise:
     Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
  

  10)  Uncaught error outside test suite:
     Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
      at processImmediate (node:internal/timers:464:21)

  11) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.3: If both `resolvePromise` and `rejectPromise` are called, or multiple calls to the same argument are made, the first call takes precedence, and any further calls are ignored. calling `resolvePromise` synchronously then `rejectPromise` asynchronously Uncaught error outside test suite:
     Uncaught TypeError: Cannot set properties of undefined (setting 'state')
      at onPromiseRejected (node_modules/promises-aplus-tests/lib/tests/2.3.3.js:108:13)

  12) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` Uncaught error outside test suite:
     Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
      at processImmediate (node:internal/timers:464:21)

  13) 2.3.3: Otherwise, if `x` is an object or function, Uncaught error outside test suite:
     Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
      at processImmediate (node:internal/timers:464:21)

@seandunaway
Copy link

seandunaway commented Jun 19, 2023

% node --version
v20.3.0

794 passing (11s)
14 failing

same 2.3.3 failures

@FaberVitale
Copy link

FaberVitale commented Nov 11, 2023

It seems that the test suite fails since node 15 because of the unhandledrejection changes.

globalThis.Promise passes all tests in node 20 & node 18 if an unhandledrejection listener is added in the adapter.

// adapter.js
module.exports = {
  deferred() {
    let resolve, reject;

    const promise = new Promise((res, rej) => {
      resolve = res;
      reject = rej;
    });

    return {
      promise,
      resolve,
      reject,
    };
  },
};

require('process').on('unhandledRejection', (err) => { console.debug('unhandledRejection', err) });
  872 passing (13s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants