const itIsDefined = typeof it === "object";

function wrap<TResult>(
  original: ((...args: any[]) => TResult) | false,
) {
  return (
    message: string,
    callback: (
      resolve: (result?: any) => void,
      reject: (reason?: any) => void,
    ) => any,
    timeout?: number,
  ) => original && original(message, function () {
    return new Promise(
      (resolve, reject) => callback.call(this, resolve, reject),
    );
  }, timeout);
}

const wrappedIt = wrap(itIsDefined && it);
export function itAsync(...args: Parameters<typeof wrappedIt>) {
  return wrappedIt.apply(this, args);
}

export namespace itAsync {
  export const only = wrap(itIsDefined && it.only);
  export const skip = wrap(itIsDefined && it.skip);
  export const todo = wrap(itIsDefined && it.todo);
}

function wrap<TResult>(
  original: (...args: any[]) => TResult,
) {
  return (
    message: string,
    callback: (
      resolve: (result?: any) => void,
      reject: (reason?: any) => void,
    ) => any,
    timeout?: number,
  ) => original(message, function () {
    return new Promise(
      (resolve, reject) => callback.call(this, resolve, reject),
    );
  }, timeout);
}

const wrappedIt = wrap(it);
export function itAsync(...args: Parameters<typeof wrappedIt>) {
  return wrappedIt.apply(this, args);
}

export namespace itAsync {
  export const only = wrap(it.only);
  export const skip = wrap(it.skip);
  export const todo = wrap(it.todo);
}

Revert "Allow importing @apollo/client/testing when global.it undefined."
Revert "Allow importing @apollo/client/testing when global.it undefined."

This reverts commit 458960673148b70051315a4c0e73f9f22d749e2d, because it
was pushed without a PR, and broke a number of tests.
