Code Monkey home page Code Monkey logo

Comments (5)

poelstra avatar poelstra commented on June 10, 2024

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),
};

from promises-tests.

zzzgit avatar zzzgit commented on June 10, 2024
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.

from promises-tests.

TotooriaHyperion avatar TotooriaHyperion commented on June 10, 2024

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)

from promises-tests.

seandunaway avatar seandunaway commented on June 10, 2024
% node --version
v20.3.0

794 passing (11s)
14 failing

same 2.3.3 failures

from promises-tests.

FaberVitale avatar FaberVitale commented on June 10, 2024

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)

from promises-tests.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.