"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
//@ts-ignore
globalThis.__DEV__ = true;
const util_1 = require("util");
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
global.TextEncoder ??= util_1.TextEncoder;
// @ts-ignore
global.TextDecoder ??= util_1.TextDecoder;
require("@testing-library/jest-dom");
require("../../testing/matchers/index.cjs");
const client_1 = require("@apollo/client");
const dev_1 = require("@apollo/client/dev");
const areCombinedGraphQLErrorsEqual_js_1 = require("./areCombinedGraphQLErrorsEqual.cjs");
const areCombinedProtocolErrorsEqual_js_1 = require("./areCombinedProtocolErrorsEqual.cjs");
const areGraphQlErrorsEqual_js_1 = require("./areGraphQlErrorsEqual.cjs");
const areMissingFieldErrorsEqual_js_1 = require("./areMissingFieldErrorsEqual.cjs");
const areServerErrorsEqual_js_1 = require("./areServerErrorsEqual.cjs");
(0, client_1.setLogVerbosity)("log");
// Turn off warnings for repeated fragment names
graphql_tag_1.default.disableFragmentWarnings();
process.on("unhandledRejection", () => { });
if (process.env.TEST_ENV === "ci") {
    // in CI, we work with the compiled code, so we need to load the error messages
    (0, dev_1.loadDevMessages)();
    (0, dev_1.loadErrorMessages)();
}
else {
    // locally, the error messages are in the source code, so we need to load the
    // error message handler
    (0, dev_1.loadErrorMessageHandler)();
}
function fail(reason = "fail was called in a test.") {
    expect(reason).toBe(undefined);
}
// @ts-ignore
globalThis.fail = fail;
if (!Symbol.dispose) {
    Object.defineProperty(Symbol, "dispose", {
        value: Symbol("dispose"),
    });
}
if (!Symbol.asyncDispose) {
    Object.defineProperty(Symbol, "asyncDispose", {
        value: Symbol("asyncDispose"),
    });
}
// @ts-ignore
expect.addEqualityTesters([
    areServerErrorsEqual_js_1.areServerErrorsEqual,
    areCombinedGraphQLErrorsEqual_js_1.areCombinedGraphQLErrorsEqual,
    areCombinedProtocolErrorsEqual_js_1.areCombinedProtocolErrorsEqual,
    areGraphQlErrorsEqual_js_1.areGraphQLErrorsEqual,
    areMissingFieldErrorsEqual_js_1.areMissingFieldErrorsEqual,
]);
// not available in JSDOM 🙄
global.structuredClone = (val) => JSON.parse(JSON.stringify(val));
global.ReadableStream ||= require("stream/web").ReadableStream;
AbortSignal.timeout = (ms) => {
    const controller = new AbortController();
    setTimeout(() => controller.abort(new DOMException("The operation timed out.", "TimeoutError")), ms);
    return controller.signal;
};
//# sourceMappingURL=setup.cjs.map
