inital upload
This commit is contained in:
370
node_modules/@apollo/client/testing/core/core.cjs
generated
vendored
Normal file
370
node_modules/@apollo/client/testing/core/core.cjs
generated
vendored
Normal file
@@ -0,0 +1,370 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var tslib = require('tslib');
|
||||
var globals = require('../../utilities/globals');
|
||||
var equality = require('@wry/equality');
|
||||
var core = require('../../link/core');
|
||||
var utilities = require('../../utilities');
|
||||
var core$1 = require('../../core');
|
||||
var cache = require('../../cache');
|
||||
|
||||
function requestToKey(request, addTypename) {
|
||||
var queryString = request.query &&
|
||||
utilities.print(addTypename ? utilities.addTypenameToDocument(request.query) : request.query);
|
||||
var requestKey = { query: queryString };
|
||||
return JSON.stringify(requestKey);
|
||||
}
|
||||
var MockLink = (function (_super) {
|
||||
tslib.__extends(MockLink, _super);
|
||||
function MockLink(mockedResponses, addTypename, options) {
|
||||
if (addTypename === void 0) { addTypename = true; }
|
||||
if (options === void 0) { options = Object.create(null); }
|
||||
var _a;
|
||||
var _this = _super.call(this) || this;
|
||||
_this.addTypename = true;
|
||||
_this.showWarnings = true;
|
||||
_this.mockedResponsesByKey = {};
|
||||
_this.addTypename = addTypename;
|
||||
_this.showWarnings = (_a = options.showWarnings) !== null && _a !== void 0 ? _a : true;
|
||||
if (mockedResponses) {
|
||||
mockedResponses.forEach(function (mockedResponse) {
|
||||
_this.addMockedResponse(mockedResponse);
|
||||
});
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
MockLink.prototype.addMockedResponse = function (mockedResponse) {
|
||||
var normalizedMockedResponse = this.normalizeMockedResponse(mockedResponse);
|
||||
var key = requestToKey(normalizedMockedResponse.request, this.addTypename);
|
||||
var mockedResponses = this.mockedResponsesByKey[key];
|
||||
if (!mockedResponses) {
|
||||
mockedResponses = [];
|
||||
this.mockedResponsesByKey[key] = mockedResponses;
|
||||
}
|
||||
mockedResponses.push(normalizedMockedResponse);
|
||||
};
|
||||
MockLink.prototype.request = function (operation) {
|
||||
var _this = this;
|
||||
var _a;
|
||||
this.operation = operation;
|
||||
var key = requestToKey(operation, this.addTypename);
|
||||
var unmatchedVars = [];
|
||||
var requestVariables = operation.variables || {};
|
||||
var mockedResponses = this.mockedResponsesByKey[key];
|
||||
var responseIndex = mockedResponses ?
|
||||
mockedResponses.findIndex(function (res, index) {
|
||||
var mockedResponseVars = res.request.variables || {};
|
||||
if (equality.equal(requestVariables, mockedResponseVars)) {
|
||||
return true;
|
||||
}
|
||||
if (res.variableMatcher && res.variableMatcher(operation.variables)) {
|
||||
return true;
|
||||
}
|
||||
unmatchedVars.push(mockedResponseVars);
|
||||
return false;
|
||||
})
|
||||
: -1;
|
||||
var response = responseIndex >= 0 ? mockedResponses[responseIndex] : void 0;
|
||||
var delay = (response === null || response === void 0 ? void 0 : response.delay) === Infinity ? 0 : (_a = response === null || response === void 0 ? void 0 : response.delay) !== null && _a !== void 0 ? _a : 0;
|
||||
var configError;
|
||||
if (!response) {
|
||||
configError = new Error("No more mocked responses for the query: ".concat(utilities.print(operation.query), "\nExpected variables: ").concat(stringifyForDebugging(operation.variables), "\n").concat(unmatchedVars.length > 0 ?
|
||||
"\nFailed to match ".concat(unmatchedVars.length, " mock").concat(unmatchedVars.length === 1 ? "" : "s", " for this query. The mocked response had the following variables:\n").concat(unmatchedVars.map(function (d) { return " ".concat(stringifyForDebugging(d)); }).join("\n"), "\n")
|
||||
: ""));
|
||||
if (this.showWarnings) {
|
||||
console.warn(configError.message +
|
||||
"\nThis typically indicates a configuration error in your mocks " +
|
||||
"setup, usually due to a typo or mismatched variable.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (response.maxUsageCount && response.maxUsageCount > 1) {
|
||||
response.maxUsageCount--;
|
||||
}
|
||||
else {
|
||||
mockedResponses.splice(responseIndex, 1);
|
||||
}
|
||||
var newData = response.newData;
|
||||
if (newData) {
|
||||
response.result = newData(operation.variables);
|
||||
mockedResponses.push(response);
|
||||
}
|
||||
if (!response.result && !response.error && response.delay !== Infinity) {
|
||||
configError = new Error("Mocked response should contain either `result`, `error` or a `delay` of `Infinity`: ".concat(key));
|
||||
}
|
||||
}
|
||||
return new utilities.Observable(function (observer) {
|
||||
var timer = setTimeout(function () {
|
||||
if (configError) {
|
||||
try {
|
||||
if (_this.onError(configError, observer) !== false) {
|
||||
throw configError;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
observer.error(error);
|
||||
}
|
||||
}
|
||||
else if (response && response.delay !== Infinity) {
|
||||
if (response.error) {
|
||||
observer.error(response.error);
|
||||
}
|
||||
else {
|
||||
if (response.result) {
|
||||
observer.next(typeof response.result === "function" ?
|
||||
response.result(operation.variables)
|
||||
: response.result);
|
||||
}
|
||||
observer.complete();
|
||||
}
|
||||
}
|
||||
}, delay);
|
||||
return function () {
|
||||
clearTimeout(timer);
|
||||
};
|
||||
});
|
||||
};
|
||||
MockLink.prototype.normalizeMockedResponse = function (mockedResponse) {
|
||||
var _a;
|
||||
var newMockedResponse = utilities.cloneDeep(mockedResponse);
|
||||
var queryWithoutClientOnlyDirectives = utilities.removeDirectivesFromDocument([{ name: "connection" }, { name: "nonreactive" }, { name: "unmask" }], utilities.checkDocument(newMockedResponse.request.query));
|
||||
globals.invariant(queryWithoutClientOnlyDirectives, 75);
|
||||
newMockedResponse.request.query = queryWithoutClientOnlyDirectives;
|
||||
var query = utilities.removeClientSetsFromDocument(newMockedResponse.request.query);
|
||||
if (query) {
|
||||
newMockedResponse.request.query = query;
|
||||
}
|
||||
mockedResponse.maxUsageCount = (_a = mockedResponse.maxUsageCount) !== null && _a !== void 0 ? _a : 1;
|
||||
globals.invariant(mockedResponse.maxUsageCount > 0, 76, mockedResponse.maxUsageCount);
|
||||
this.normalizeVariableMatching(newMockedResponse);
|
||||
return newMockedResponse;
|
||||
};
|
||||
MockLink.prototype.normalizeVariableMatching = function (mockedResponse) {
|
||||
var request = mockedResponse.request;
|
||||
if (mockedResponse.variableMatcher && request.variables) {
|
||||
throw new Error("Mocked response should contain either variableMatcher or request.variables");
|
||||
}
|
||||
if (!mockedResponse.variableMatcher) {
|
||||
request.variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(utilities.getOperationDefinition(request.query))), request.variables);
|
||||
mockedResponse.variableMatcher = function (vars) {
|
||||
var requestVariables = vars || {};
|
||||
var mockedResponseVariables = request.variables || {};
|
||||
return equality.equal(requestVariables, mockedResponseVariables);
|
||||
};
|
||||
}
|
||||
};
|
||||
return MockLink;
|
||||
}(core.ApolloLink));
|
||||
function mockSingleLink() {
|
||||
var mockedResponses = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
mockedResponses[_i] = arguments[_i];
|
||||
}
|
||||
var maybeTypename = mockedResponses[mockedResponses.length - 1];
|
||||
var mocks = mockedResponses.slice(0, mockedResponses.length - 1);
|
||||
if (typeof maybeTypename !== "boolean") {
|
||||
mocks = mockedResponses;
|
||||
maybeTypename = true;
|
||||
}
|
||||
return new MockLink(mocks, maybeTypename);
|
||||
}
|
||||
function stringifyForDebugging(value, space) {
|
||||
if (space === void 0) { space = 0; }
|
||||
var undefId = utilities.makeUniqueId("undefined");
|
||||
var nanId = utilities.makeUniqueId("NaN");
|
||||
return JSON.stringify(value, function (_, value) {
|
||||
if (value === void 0) {
|
||||
return undefId;
|
||||
}
|
||||
if (Number.isNaN(value)) {
|
||||
return nanId;
|
||||
}
|
||||
return value;
|
||||
}, space)
|
||||
.replace(new RegExp(JSON.stringify(undefId), "g"), "<undefined>")
|
||||
.replace(new RegExp(JSON.stringify(nanId), "g"), "NaN");
|
||||
}
|
||||
|
||||
var MockSubscriptionLink = (function (_super) {
|
||||
tslib.__extends(MockSubscriptionLink, _super);
|
||||
function MockSubscriptionLink() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.unsubscribers = [];
|
||||
_this.setups = [];
|
||||
_this.observers = [];
|
||||
return _this;
|
||||
}
|
||||
MockSubscriptionLink.prototype.request = function (operation) {
|
||||
var _this = this;
|
||||
this.operation = operation;
|
||||
return new utilities.Observable(function (observer) {
|
||||
_this.setups.forEach(function (x) { return x(); });
|
||||
_this.observers.push(observer);
|
||||
return function () {
|
||||
_this.unsubscribers.forEach(function (x) { return x(); });
|
||||
};
|
||||
});
|
||||
};
|
||||
MockSubscriptionLink.prototype.simulateResult = function (result, complete) {
|
||||
var _this = this;
|
||||
if (complete === void 0) { complete = false; }
|
||||
setTimeout(function () {
|
||||
var observers = _this.observers;
|
||||
if (!observers.length)
|
||||
throw new Error("subscription torn down");
|
||||
observers.forEach(function (observer) {
|
||||
if (result.result && observer.next)
|
||||
observer.next(result.result);
|
||||
if (result.error && observer.error)
|
||||
observer.error(result.error);
|
||||
if (complete && observer.complete)
|
||||
observer.complete();
|
||||
});
|
||||
}, result.delay || 0);
|
||||
};
|
||||
MockSubscriptionLink.prototype.simulateComplete = function () {
|
||||
var observers = this.observers;
|
||||
if (!observers.length)
|
||||
throw new Error("subscription torn down");
|
||||
observers.forEach(function (observer) {
|
||||
if (observer.complete)
|
||||
observer.complete();
|
||||
});
|
||||
};
|
||||
MockSubscriptionLink.prototype.onSetup = function (listener) {
|
||||
this.setups = this.setups.concat([listener]);
|
||||
};
|
||||
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) {
|
||||
this.unsubscribers = this.unsubscribers.concat([listener]);
|
||||
};
|
||||
return MockSubscriptionLink;
|
||||
}(core.ApolloLink));
|
||||
function mockObservableLink() {
|
||||
return new MockSubscriptionLink();
|
||||
}
|
||||
|
||||
function createMockClient(data, query, variables) {
|
||||
if (variables === void 0) { variables = {}; }
|
||||
return new core$1.ApolloClient({
|
||||
link: mockSingleLink({
|
||||
request: { query: query, variables: variables },
|
||||
result: { data: data },
|
||||
}).setOnError(function (error) {
|
||||
throw error;
|
||||
}),
|
||||
cache: new cache.InMemoryCache({ addTypename: false }),
|
||||
});
|
||||
}
|
||||
|
||||
function subscribeAndCount(reject, observable, cb) {
|
||||
var queue = Promise.resolve();
|
||||
var handleCount = 0;
|
||||
var subscription = utilities.asyncMap(observable, function (result) {
|
||||
return (queue = queue
|
||||
.then(function () {
|
||||
return cb(++handleCount, result);
|
||||
})
|
||||
.catch(error));
|
||||
}).subscribe({ error: error });
|
||||
function error(e) {
|
||||
subscription.unsubscribe();
|
||||
reject(e);
|
||||
}
|
||||
return subscription;
|
||||
}
|
||||
|
||||
function wrap(key) {
|
||||
return function (message, callback, timeout) {
|
||||
return (key ? it[key] : it)(message, function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
return callback.call(_this, resolve, reject);
|
||||
});
|
||||
}, timeout);
|
||||
};
|
||||
}
|
||||
var wrappedIt = wrap();
|
||||
var itAsync = Object.assign(function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
return wrappedIt.apply(this, args);
|
||||
}, {
|
||||
only: wrap("only"),
|
||||
skip: wrap("skip"),
|
||||
todo: wrap("todo"),
|
||||
});
|
||||
|
||||
function wait(ms) {
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib.__generator(this, function (_a) {
|
||||
return [2 , new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
||||
});
|
||||
});
|
||||
}
|
||||
function tick() {
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib.__generator(this, function (_a) {
|
||||
return [2 , wait(0)];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function wrapTestFunction(fn, consoleMethodName) {
|
||||
return function () {
|
||||
var _this = this;
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
var spy = jest.spyOn(console, consoleMethodName);
|
||||
spy.mockImplementation(function () { });
|
||||
return new Promise(function (resolve) {
|
||||
resolve(fn === null || fn === void 0 ? void 0 : fn.apply(_this, args));
|
||||
}).finally(function () {
|
||||
expect(spy).toMatchSnapshot();
|
||||
spy.mockReset();
|
||||
});
|
||||
};
|
||||
}
|
||||
function withErrorSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "error");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
function withWarningSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "warn");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
function withLogSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "log");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
|
||||
exports.MockLink = MockLink;
|
||||
exports.MockSubscriptionLink = MockSubscriptionLink;
|
||||
exports.createMockClient = createMockClient;
|
||||
exports.itAsync = itAsync;
|
||||
exports.mockObservableLink = mockObservableLink;
|
||||
exports.mockSingleLink = mockSingleLink;
|
||||
exports.subscribeAndCount = subscribeAndCount;
|
||||
exports.tick = tick;
|
||||
exports.wait = wait;
|
||||
exports.withErrorSpy = withErrorSpy;
|
||||
exports.withLogSpy = withLogSpy;
|
||||
exports.withWarningSpy = withWarningSpy;
|
||||
//# sourceMappingURL=core.cjs.map
|
||||
1
node_modules/@apollo/client/testing/core/core.cjs.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/core.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
370
node_modules/@apollo/client/testing/core/core.cjs.native.js
generated
vendored
Normal file
370
node_modules/@apollo/client/testing/core/core.cjs.native.js
generated
vendored
Normal file
@@ -0,0 +1,370 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var tslib = require('tslib');
|
||||
var globals = require('../../utilities/globals');
|
||||
var equality = require('@wry/equality');
|
||||
var core = require('../../link/core');
|
||||
var utilities = require('../../utilities');
|
||||
var core$1 = require('../../core');
|
||||
var cache = require('../../cache');
|
||||
|
||||
function requestToKey(request, addTypename) {
|
||||
var queryString = request.query &&
|
||||
utilities.print(addTypename ? utilities.addTypenameToDocument(request.query) : request.query);
|
||||
var requestKey = { query: queryString };
|
||||
return JSON.stringify(requestKey);
|
||||
}
|
||||
var MockLink = (function (_super) {
|
||||
tslib.__extends(MockLink, _super);
|
||||
function MockLink(mockedResponses, addTypename, options) {
|
||||
if (addTypename === void 0) { addTypename = true; }
|
||||
if (options === void 0) { options = Object.create(null); }
|
||||
var _a;
|
||||
var _this = _super.call(this) || this;
|
||||
_this.addTypename = true;
|
||||
_this.showWarnings = true;
|
||||
_this.mockedResponsesByKey = {};
|
||||
_this.addTypename = addTypename;
|
||||
_this.showWarnings = (_a = options.showWarnings) !== null && _a !== void 0 ? _a : true;
|
||||
if (mockedResponses) {
|
||||
mockedResponses.forEach(function (mockedResponse) {
|
||||
_this.addMockedResponse(mockedResponse);
|
||||
});
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
MockLink.prototype.addMockedResponse = function (mockedResponse) {
|
||||
var normalizedMockedResponse = this.normalizeMockedResponse(mockedResponse);
|
||||
var key = requestToKey(normalizedMockedResponse.request, this.addTypename);
|
||||
var mockedResponses = this.mockedResponsesByKey[key];
|
||||
if (!mockedResponses) {
|
||||
mockedResponses = [];
|
||||
this.mockedResponsesByKey[key] = mockedResponses;
|
||||
}
|
||||
mockedResponses.push(normalizedMockedResponse);
|
||||
};
|
||||
MockLink.prototype.request = function (operation) {
|
||||
var _this = this;
|
||||
var _a;
|
||||
this.operation = operation;
|
||||
var key = requestToKey(operation, this.addTypename);
|
||||
var unmatchedVars = [];
|
||||
var requestVariables = operation.variables || {};
|
||||
var mockedResponses = this.mockedResponsesByKey[key];
|
||||
var responseIndex = mockedResponses ?
|
||||
mockedResponses.findIndex(function (res, index) {
|
||||
var mockedResponseVars = res.request.variables || {};
|
||||
if (equality.equal(requestVariables, mockedResponseVars)) {
|
||||
return true;
|
||||
}
|
||||
if (res.variableMatcher && res.variableMatcher(operation.variables)) {
|
||||
return true;
|
||||
}
|
||||
unmatchedVars.push(mockedResponseVars);
|
||||
return false;
|
||||
})
|
||||
: -1;
|
||||
var response = responseIndex >= 0 ? mockedResponses[responseIndex] : void 0;
|
||||
var delay = (response === null || response === void 0 ? void 0 : response.delay) === Infinity ? 0 : (_a = response === null || response === void 0 ? void 0 : response.delay) !== null && _a !== void 0 ? _a : 0;
|
||||
var configError;
|
||||
if (!response) {
|
||||
configError = new Error("No more mocked responses for the query: ".concat(utilities.print(operation.query), "\nExpected variables: ").concat(stringifyForDebugging(operation.variables), "\n").concat(unmatchedVars.length > 0 ?
|
||||
"\nFailed to match ".concat(unmatchedVars.length, " mock").concat(unmatchedVars.length === 1 ? "" : "s", " for this query. The mocked response had the following variables:\n").concat(unmatchedVars.map(function (d) { return " ".concat(stringifyForDebugging(d)); }).join("\n"), "\n")
|
||||
: ""));
|
||||
if (this.showWarnings) {
|
||||
console.warn(configError.message +
|
||||
"\nThis typically indicates a configuration error in your mocks " +
|
||||
"setup, usually due to a typo or mismatched variable.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (response.maxUsageCount && response.maxUsageCount > 1) {
|
||||
response.maxUsageCount--;
|
||||
}
|
||||
else {
|
||||
mockedResponses.splice(responseIndex, 1);
|
||||
}
|
||||
var newData = response.newData;
|
||||
if (newData) {
|
||||
response.result = newData(operation.variables);
|
||||
mockedResponses.push(response);
|
||||
}
|
||||
if (!response.result && !response.error && response.delay !== Infinity) {
|
||||
configError = new Error("Mocked response should contain either `result`, `error` or a `delay` of `Infinity`: ".concat(key));
|
||||
}
|
||||
}
|
||||
return new utilities.Observable(function (observer) {
|
||||
var timer = setTimeout(function () {
|
||||
if (configError) {
|
||||
try {
|
||||
if (_this.onError(configError, observer) !== false) {
|
||||
throw configError;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
observer.error(error);
|
||||
}
|
||||
}
|
||||
else if (response && response.delay !== Infinity) {
|
||||
if (response.error) {
|
||||
observer.error(response.error);
|
||||
}
|
||||
else {
|
||||
if (response.result) {
|
||||
observer.next(typeof response.result === "function" ?
|
||||
response.result(operation.variables)
|
||||
: response.result);
|
||||
}
|
||||
observer.complete();
|
||||
}
|
||||
}
|
||||
}, delay);
|
||||
return function () {
|
||||
clearTimeout(timer);
|
||||
};
|
||||
});
|
||||
};
|
||||
MockLink.prototype.normalizeMockedResponse = function (mockedResponse) {
|
||||
var _a;
|
||||
var newMockedResponse = utilities.cloneDeep(mockedResponse);
|
||||
var queryWithoutClientOnlyDirectives = utilities.removeDirectivesFromDocument([{ name: "connection" }, { name: "nonreactive" }, { name: "unmask" }], utilities.checkDocument(newMockedResponse.request.query));
|
||||
globals.invariant(queryWithoutClientOnlyDirectives, 75);
|
||||
newMockedResponse.request.query = queryWithoutClientOnlyDirectives;
|
||||
var query = utilities.removeClientSetsFromDocument(newMockedResponse.request.query);
|
||||
if (query) {
|
||||
newMockedResponse.request.query = query;
|
||||
}
|
||||
mockedResponse.maxUsageCount = (_a = mockedResponse.maxUsageCount) !== null && _a !== void 0 ? _a : 1;
|
||||
globals.invariant(mockedResponse.maxUsageCount > 0, 76, mockedResponse.maxUsageCount);
|
||||
this.normalizeVariableMatching(newMockedResponse);
|
||||
return newMockedResponse;
|
||||
};
|
||||
MockLink.prototype.normalizeVariableMatching = function (mockedResponse) {
|
||||
var request = mockedResponse.request;
|
||||
if (mockedResponse.variableMatcher && request.variables) {
|
||||
throw new Error("Mocked response should contain either variableMatcher or request.variables");
|
||||
}
|
||||
if (!mockedResponse.variableMatcher) {
|
||||
request.variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(utilities.getOperationDefinition(request.query))), request.variables);
|
||||
mockedResponse.variableMatcher = function (vars) {
|
||||
var requestVariables = vars || {};
|
||||
var mockedResponseVariables = request.variables || {};
|
||||
return equality.equal(requestVariables, mockedResponseVariables);
|
||||
};
|
||||
}
|
||||
};
|
||||
return MockLink;
|
||||
}(core.ApolloLink));
|
||||
function mockSingleLink() {
|
||||
var mockedResponses = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
mockedResponses[_i] = arguments[_i];
|
||||
}
|
||||
var maybeTypename = mockedResponses[mockedResponses.length - 1];
|
||||
var mocks = mockedResponses.slice(0, mockedResponses.length - 1);
|
||||
if (typeof maybeTypename !== "boolean") {
|
||||
mocks = mockedResponses;
|
||||
maybeTypename = true;
|
||||
}
|
||||
return new MockLink(mocks, maybeTypename);
|
||||
}
|
||||
function stringifyForDebugging(value, space) {
|
||||
if (space === void 0) { space = 0; }
|
||||
var undefId = utilities.makeUniqueId("undefined");
|
||||
var nanId = utilities.makeUniqueId("NaN");
|
||||
return JSON.stringify(value, function (_, value) {
|
||||
if (value === void 0) {
|
||||
return undefId;
|
||||
}
|
||||
if (Number.isNaN(value)) {
|
||||
return nanId;
|
||||
}
|
||||
return value;
|
||||
}, space)
|
||||
.replace(new RegExp(JSON.stringify(undefId), "g"), "<undefined>")
|
||||
.replace(new RegExp(JSON.stringify(nanId), "g"), "NaN");
|
||||
}
|
||||
|
||||
var MockSubscriptionLink = (function (_super) {
|
||||
tslib.__extends(MockSubscriptionLink, _super);
|
||||
function MockSubscriptionLink() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.unsubscribers = [];
|
||||
_this.setups = [];
|
||||
_this.observers = [];
|
||||
return _this;
|
||||
}
|
||||
MockSubscriptionLink.prototype.request = function (operation) {
|
||||
var _this = this;
|
||||
this.operation = operation;
|
||||
return new utilities.Observable(function (observer) {
|
||||
_this.setups.forEach(function (x) { return x(); });
|
||||
_this.observers.push(observer);
|
||||
return function () {
|
||||
_this.unsubscribers.forEach(function (x) { return x(); });
|
||||
};
|
||||
});
|
||||
};
|
||||
MockSubscriptionLink.prototype.simulateResult = function (result, complete) {
|
||||
var _this = this;
|
||||
if (complete === void 0) { complete = false; }
|
||||
setTimeout(function () {
|
||||
var observers = _this.observers;
|
||||
if (!observers.length)
|
||||
throw new Error("subscription torn down");
|
||||
observers.forEach(function (observer) {
|
||||
if (result.result && observer.next)
|
||||
observer.next(result.result);
|
||||
if (result.error && observer.error)
|
||||
observer.error(result.error);
|
||||
if (complete && observer.complete)
|
||||
observer.complete();
|
||||
});
|
||||
}, result.delay || 0);
|
||||
};
|
||||
MockSubscriptionLink.prototype.simulateComplete = function () {
|
||||
var observers = this.observers;
|
||||
if (!observers.length)
|
||||
throw new Error("subscription torn down");
|
||||
observers.forEach(function (observer) {
|
||||
if (observer.complete)
|
||||
observer.complete();
|
||||
});
|
||||
};
|
||||
MockSubscriptionLink.prototype.onSetup = function (listener) {
|
||||
this.setups = this.setups.concat([listener]);
|
||||
};
|
||||
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) {
|
||||
this.unsubscribers = this.unsubscribers.concat([listener]);
|
||||
};
|
||||
return MockSubscriptionLink;
|
||||
}(core.ApolloLink));
|
||||
function mockObservableLink() {
|
||||
return new MockSubscriptionLink();
|
||||
}
|
||||
|
||||
function createMockClient(data, query, variables) {
|
||||
if (variables === void 0) { variables = {}; }
|
||||
return new core$1.ApolloClient({
|
||||
link: mockSingleLink({
|
||||
request: { query: query, variables: variables },
|
||||
result: { data: data },
|
||||
}).setOnError(function (error) {
|
||||
throw error;
|
||||
}),
|
||||
cache: new cache.InMemoryCache({ addTypename: false }),
|
||||
});
|
||||
}
|
||||
|
||||
function subscribeAndCount(reject, observable, cb) {
|
||||
var queue = Promise.resolve();
|
||||
var handleCount = 0;
|
||||
var subscription = utilities.asyncMap(observable, function (result) {
|
||||
return (queue = queue
|
||||
.then(function () {
|
||||
return cb(++handleCount, result);
|
||||
})
|
||||
.catch(error));
|
||||
}).subscribe({ error: error });
|
||||
function error(e) {
|
||||
subscription.unsubscribe();
|
||||
reject(e);
|
||||
}
|
||||
return subscription;
|
||||
}
|
||||
|
||||
function wrap(key) {
|
||||
return function (message, callback, timeout) {
|
||||
return (key ? it[key] : it)(message, function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
return callback.call(_this, resolve, reject);
|
||||
});
|
||||
}, timeout);
|
||||
};
|
||||
}
|
||||
var wrappedIt = wrap();
|
||||
var itAsync = Object.assign(function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
return wrappedIt.apply(this, args);
|
||||
}, {
|
||||
only: wrap("only"),
|
||||
skip: wrap("skip"),
|
||||
todo: wrap("todo"),
|
||||
});
|
||||
|
||||
function wait(ms) {
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib.__generator(this, function (_a) {
|
||||
return [2 , new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
||||
});
|
||||
});
|
||||
}
|
||||
function tick() {
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib.__generator(this, function (_a) {
|
||||
return [2 , wait(0)];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function wrapTestFunction(fn, consoleMethodName) {
|
||||
return function () {
|
||||
var _this = this;
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
var spy = jest.spyOn(console, consoleMethodName);
|
||||
spy.mockImplementation(function () { });
|
||||
return new Promise(function (resolve) {
|
||||
resolve(fn === null || fn === void 0 ? void 0 : fn.apply(_this, args));
|
||||
}).finally(function () {
|
||||
expect(spy).toMatchSnapshot();
|
||||
spy.mockReset();
|
||||
});
|
||||
};
|
||||
}
|
||||
function withErrorSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "error");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
function withWarningSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "warn");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
function withLogSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "log");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
|
||||
exports.MockLink = MockLink;
|
||||
exports.MockSubscriptionLink = MockSubscriptionLink;
|
||||
exports.createMockClient = createMockClient;
|
||||
exports.itAsync = itAsync;
|
||||
exports.mockObservableLink = mockObservableLink;
|
||||
exports.mockSingleLink = mockSingleLink;
|
||||
exports.subscribeAndCount = subscribeAndCount;
|
||||
exports.tick = tick;
|
||||
exports.wait = wait;
|
||||
exports.withErrorSpy = withErrorSpy;
|
||||
exports.withLogSpy = withLogSpy;
|
||||
exports.withWarningSpy = withWarningSpy;
|
||||
//# sourceMappingURL=core.cjs.map
|
||||
1
node_modules/@apollo/client/testing/core/core.d.cts
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/core.d.cts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./index.d.ts";
|
||||
9
node_modules/@apollo/client/testing/core/index.d.ts
generated
vendored
Normal file
9
node_modules/@apollo/client/testing/core/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export type { MockedResponse, MockLinkOptions, ResultFunction, } from "./mocking/mockLink.js";
|
||||
export { MockLink, mockSingleLink } from "./mocking/mockLink.js";
|
||||
export { MockSubscriptionLink, mockObservableLink, } from "./mocking/mockSubscriptionLink.js";
|
||||
export { createMockClient } from "./mocking/mockClient.js";
|
||||
export { default as subscribeAndCount } from "./subscribeAndCount.js";
|
||||
export { itAsync } from "./itAsync.js";
|
||||
export { wait, tick } from "./wait.js";
|
||||
export * from "./withConsoleSpy.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
8
node_modules/@apollo/client/testing/core/index.js
generated
vendored
Normal file
8
node_modules/@apollo/client/testing/core/index.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export { MockLink, mockSingleLink } from "./mocking/mockLink.js";
|
||||
export { MockSubscriptionLink, mockObservableLink, } from "./mocking/mockSubscriptionLink.js";
|
||||
export { createMockClient } from "./mocking/mockClient.js";
|
||||
export { default as subscribeAndCount } from "./subscribeAndCount.js";
|
||||
export { itAsync } from "./itAsync.js";
|
||||
export { wait, tick } from "./wait.js";
|
||||
export * from "./withConsoleSpy.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/client/testing/core/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/core/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACvC,cAAc,qBAAqB,CAAC","sourcesContent":["export type {\n MockedResponse,\n MockLinkOptions,\n ResultFunction,\n} from \"./mocking/mockLink.js\";\nexport { MockLink, mockSingleLink } from \"./mocking/mockLink.js\";\nexport {\n MockSubscriptionLink,\n mockObservableLink,\n} from \"./mocking/mockSubscriptionLink.js\";\nexport { createMockClient } from \"./mocking/mockClient.js\";\nexport { default as subscribeAndCount } from \"./subscribeAndCount.js\";\nexport { itAsync } from \"./itAsync.js\";\nexport { wait, tick } from \"./wait.js\";\nexport * from \"./withConsoleSpy.js\";\n"]}
|
||||
6
node_modules/@apollo/client/testing/core/itAsync.d.ts
generated
vendored
Normal file
6
node_modules/@apollo/client/testing/core/itAsync.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export declare const itAsync: ((this: unknown, message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number | undefined) => void) & {
|
||||
only: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void;
|
||||
skip: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void;
|
||||
todo: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void;
|
||||
};
|
||||
//# sourceMappingURL=itAsync.d.ts.map
|
||||
23
node_modules/@apollo/client/testing/core/itAsync.js
generated
vendored
Normal file
23
node_modules/@apollo/client/testing/core/itAsync.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
function wrap(key) {
|
||||
return function (message, callback, timeout) {
|
||||
return (key ? it[key] : it)(message, function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
return callback.call(_this, resolve, reject);
|
||||
});
|
||||
}, timeout);
|
||||
};
|
||||
}
|
||||
var wrappedIt = wrap();
|
||||
export var itAsync = Object.assign(function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
return wrappedIt.apply(this, args);
|
||||
}, {
|
||||
only: wrap("only"),
|
||||
skip: wrap("skip"),
|
||||
todo: wrap("todo"),
|
||||
});
|
||||
//# sourceMappingURL=itAsync.js.map
|
||||
1
node_modules/@apollo/client/testing/core/itAsync.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/itAsync.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"itAsync.js","sourceRoot":"","sources":["../../../src/testing/core/itAsync.ts"],"names":[],"mappings":"AAAA,SAAS,IAAI,CAAC,GAA8B;IAC1C,OAAO,UACL,OAAe,EACf,QAGQ,EACR,OAAgB;QAEhB,OAAA,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAClB,OAAO,EACP;YAAA,iBAIC;YAHC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;gBACjC,OAAA,QAAQ,CAAC,IAAI,CAAC,KAAI,EAAE,OAAO,EAAE,MAAM,CAAC;YAApC,CAAoC,CACrC,CAAC;QACJ,CAAC,EACD,OAAO,CACR;IARD,CAQC,CAAC;AACN,CAAC;AAED,IAAM,SAAS,GAAG,IAAI,EAAE,CAAC;AAEzB,MAAM,CAAC,IAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAClC;IAAyB,cAAqC;SAArC,UAAqC,EAArC,qBAAqC,EAArC,IAAqC;QAArC,yBAAqC;;IAC5D,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,EACD;IACE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;CACnB,CACF,CAAC","sourcesContent":["function wrap(key?: \"only\" | \"skip\" | \"todo\") {\n return (\n message: string,\n callback: (\n resolve: (result?: any) => void,\n reject: (reason?: any) => void\n ) => any,\n timeout?: number\n ) =>\n (key ? it[key] : it)(\n message,\n function (this: unknown) {\n return new Promise((resolve, reject) =>\n callback.call(this, resolve, reject)\n );\n },\n timeout\n );\n}\n\nconst wrappedIt = wrap();\n\nexport const itAsync = Object.assign(\n function (this: unknown, ...args: Parameters<typeof wrappedIt>) {\n return wrappedIt.apply(this, args);\n },\n {\n only: wrap(\"only\"),\n skip: wrap(\"skip\"),\n todo: wrap(\"todo\"),\n }\n);\n"]}
|
||||
5
node_modules/@apollo/client/testing/core/mocking/mockClient.d.ts
generated
vendored
Normal file
5
node_modules/@apollo/client/testing/core/mocking/mockClient.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { DocumentNode } from "graphql";
|
||||
import { ApolloClient } from "../../../core/index.js";
|
||||
import type { NormalizedCacheObject } from "../../../cache/index.js";
|
||||
export declare function createMockClient<TData>(data: TData, query: DocumentNode, variables?: {}): ApolloClient<NormalizedCacheObject>;
|
||||
//# sourceMappingURL=mockClient.d.ts.map
|
||||
16
node_modules/@apollo/client/testing/core/mocking/mockClient.js
generated
vendored
Normal file
16
node_modules/@apollo/client/testing/core/mocking/mockClient.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ApolloClient } from "../../../core/index.js";
|
||||
import { InMemoryCache } from "../../../cache/index.js";
|
||||
import { mockSingleLink } from "./mockLink.js";
|
||||
export function createMockClient(data, query, variables) {
|
||||
if (variables === void 0) { variables = {}; }
|
||||
return new ApolloClient({
|
||||
link: mockSingleLink({
|
||||
request: { query: query, variables: variables },
|
||||
result: { data: data },
|
||||
}).setOnError(function (error) {
|
||||
throw error;
|
||||
}),
|
||||
cache: new InMemoryCache({ addTypename: false }),
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=mockClient.js.map
|
||||
1
node_modules/@apollo/client/testing/core/mocking/mockClient.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/mocking/mockClient.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mockClient.js","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAC9B,IAAW,EACX,KAAmB,EACnB,SAAc;IAAd,0BAAA,EAAA,cAAc;IAEd,OAAO,IAAI,YAAY,CAAC;QACtB,IAAI,EAAE,cAAc,CAAC;YACnB,OAAO,EAAE,EAAE,KAAK,OAAA,EAAE,SAAS,WAAA,EAAE;YAC7B,MAAM,EAAE,EAAE,IAAI,MAAA,EAAE;SACjB,CAAC,CAAC,UAAU,CAAC,UAAC,KAAK;YAClB,MAAM,KAAK,CAAC;QACd,CAAC,CAAC;QACF,KAAK,EAAE,IAAI,aAAa,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;KACjD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\n\nimport { ApolloClient } from \"../../../core/index.js\";\nimport type { NormalizedCacheObject } from \"../../../cache/index.js\";\nimport { InMemoryCache } from \"../../../cache/index.js\";\nimport { mockSingleLink } from \"./mockLink.js\";\n\nexport function createMockClient<TData>(\n data: TData,\n query: DocumentNode,\n variables = {}\n): ApolloClient<NormalizedCacheObject> {\n return new ApolloClient({\n link: mockSingleLink({\n request: { query, variables },\n result: { data },\n }).setOnError((error) => {\n throw error;\n }),\n cache: new InMemoryCache({ addTypename: false }),\n });\n}\n"]}
|
||||
24
node_modules/@apollo/client/testing/core/mocking/mockFetch.d.ts
generated
vendored
Normal file
24
node_modules/@apollo/client/testing/core/mocking/mockFetch.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import "whatwg-fetch";
|
||||
export interface MockedIResponse {
|
||||
ok: boolean;
|
||||
status: number;
|
||||
statusText?: string;
|
||||
json(): Promise<Object>;
|
||||
}
|
||||
export interface MockedFetchResponse {
|
||||
url: string;
|
||||
opts: RequestInit;
|
||||
result: MockedIResponse;
|
||||
delay?: number;
|
||||
}
|
||||
export declare function createMockedIResponse(result: Object, options?: any): MockedIResponse;
|
||||
export declare class MockFetch {
|
||||
private mockedResponsesByKey;
|
||||
constructor(...mockedResponses: MockedFetchResponse[]);
|
||||
addMockedResponse(mockedResponse: MockedFetchResponse): void;
|
||||
fetch(url: string, opts: RequestInit): Promise<unknown>;
|
||||
fetchParamsToKey(url: string, opts: RequestInit): string;
|
||||
getFetch(): (url: string, opts: RequestInit) => Promise<unknown>;
|
||||
}
|
||||
export declare function createMockFetch(...mockedResponses: MockedFetchResponse[]): (url: string, opts: RequestInit) => Promise<unknown>;
|
||||
//# sourceMappingURL=mockFetch.d.ts.map
|
||||
87
node_modules/@apollo/client/testing/core/mocking/mockFetch.js
generated
vendored
Normal file
87
node_modules/@apollo/client/testing/core/mocking/mockFetch.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
import { __spreadArray } from "tslib";
|
||||
import "whatwg-fetch";
|
||||
export function createMockedIResponse(result, options) {
|
||||
var status = (options && options.status) || 200;
|
||||
var statusText = (options && options.statusText) || undefined;
|
||||
return {
|
||||
ok: status === 200,
|
||||
status: status,
|
||||
statusText: statusText,
|
||||
json: function () {
|
||||
return Promise.resolve(result);
|
||||
},
|
||||
};
|
||||
}
|
||||
var MockFetch = /** @class */ (function () {
|
||||
function MockFetch() {
|
||||
var mockedResponses = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
mockedResponses[_i] = arguments[_i];
|
||||
}
|
||||
var _this = this;
|
||||
this.mockedResponsesByKey = {};
|
||||
mockedResponses.forEach(function (mockedResponse) {
|
||||
_this.addMockedResponse(mockedResponse);
|
||||
});
|
||||
}
|
||||
MockFetch.prototype.addMockedResponse = function (mockedResponse) {
|
||||
var key = this.fetchParamsToKey(mockedResponse.url, mockedResponse.opts);
|
||||
var mockedResponses = this.mockedResponsesByKey[key];
|
||||
if (!mockedResponses) {
|
||||
mockedResponses = [];
|
||||
this.mockedResponsesByKey[key] = mockedResponses;
|
||||
}
|
||||
mockedResponses.push(mockedResponse);
|
||||
};
|
||||
MockFetch.prototype.fetch = function (url, opts) {
|
||||
var key = this.fetchParamsToKey(url, opts);
|
||||
var responses = this.mockedResponsesByKey[key];
|
||||
if (!responses || responses.length === 0) {
|
||||
throw new Error("No more mocked fetch responses for the params ".concat(url, " and ").concat(opts));
|
||||
}
|
||||
var _a = responses.shift(), result = _a.result, delay = _a.delay;
|
||||
if (!result) {
|
||||
throw new Error("Mocked fetch response should contain a result.");
|
||||
}
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(function () {
|
||||
resolve(result);
|
||||
}, delay ? delay : 0);
|
||||
});
|
||||
};
|
||||
MockFetch.prototype.fetchParamsToKey = function (url, opts) {
|
||||
return JSON.stringify({
|
||||
url: url,
|
||||
opts: sortByKey(opts),
|
||||
});
|
||||
};
|
||||
// Returns a "fetch" function equivalent that mocks the given responses.
|
||||
// The function by returned by this should be tacked onto the global scope
|
||||
// in order to test functions that use "fetch".
|
||||
MockFetch.prototype.getFetch = function () {
|
||||
return this.fetch.bind(this);
|
||||
};
|
||||
return MockFetch;
|
||||
}());
|
||||
export { MockFetch };
|
||||
function sortByKey(obj) {
|
||||
return Object.keys(obj)
|
||||
.sort()
|
||||
.reduce(function (ret, key) {
|
||||
var _a;
|
||||
return Object.assign((_a = {},
|
||||
_a[key] = (Object.prototype.toString.call(obj[key]).slice(8, -1) ===
|
||||
"Object") ?
|
||||
sortByKey(obj[key])
|
||||
: obj[key],
|
||||
_a), ret);
|
||||
}, {});
|
||||
}
|
||||
export function createMockFetch() {
|
||||
var mockedResponses = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
mockedResponses[_i] = arguments[_i];
|
||||
}
|
||||
return new (MockFetch.bind.apply(MockFetch, __spreadArray([void 0], mockedResponses, false)))().getFetch();
|
||||
}
|
||||
//# sourceMappingURL=mockFetch.js.map
|
||||
1
node_modules/@apollo/client/testing/core/mocking/mockFetch.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/mocking/mockFetch.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
40
node_modules/@apollo/client/testing/core/mocking/mockLink.d.ts
generated
vendored
Normal file
40
node_modules/@apollo/client/testing/core/mocking/mockLink.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { Operation, GraphQLRequest, FetchResult } from "../../../link/core/index.js";
|
||||
import { ApolloLink } from "../../../link/core/index.js";
|
||||
import { Observable } from "../../../utilities/index.js";
|
||||
import type { Unmasked } from "../../../masking/index.js";
|
||||
/** @internal */
|
||||
type CovariantUnaryFunction<out Arg, out Ret> = {
|
||||
fn(arg: Arg): Ret;
|
||||
}["fn"];
|
||||
export type ResultFunction<T, V = Record<string, any>> = CovariantUnaryFunction<V, T>;
|
||||
export type VariableMatcher<V = Record<string, any>> = CovariantUnaryFunction<V, boolean>;
|
||||
export interface MockedResponse<out TData = Record<string, any>, out TVariables = Record<string, any>> {
|
||||
request: GraphQLRequest<TVariables>;
|
||||
maxUsageCount?: number;
|
||||
result?: FetchResult<Unmasked<TData>> | ResultFunction<FetchResult<Unmasked<TData>>, TVariables>;
|
||||
error?: Error;
|
||||
delay?: number;
|
||||
variableMatcher?: VariableMatcher<TVariables>;
|
||||
newData?: ResultFunction<FetchResult<Unmasked<TData>>, TVariables>;
|
||||
}
|
||||
export interface MockLinkOptions {
|
||||
showWarnings?: boolean;
|
||||
}
|
||||
export declare class MockLink extends ApolloLink {
|
||||
operation: Operation;
|
||||
addTypename: Boolean;
|
||||
showWarnings: boolean;
|
||||
private mockedResponsesByKey;
|
||||
constructor(mockedResponses: ReadonlyArray<MockedResponse<any, any>>, addTypename?: Boolean, options?: MockLinkOptions);
|
||||
addMockedResponse(mockedResponse: MockedResponse): void;
|
||||
request(operation: Operation): Observable<FetchResult> | null;
|
||||
private normalizeMockedResponse;
|
||||
private normalizeVariableMatching;
|
||||
}
|
||||
export interface MockApolloLink extends ApolloLink {
|
||||
operation?: Operation;
|
||||
}
|
||||
export declare function mockSingleLink(...mockedResponses: Array<any>): MockApolloLink;
|
||||
export declare function stringifyForDebugging(value: any, space?: number): string;
|
||||
export {};
|
||||
//# sourceMappingURL=mockLink.d.ts.map
|
||||
201
node_modules/@apollo/client/testing/core/mocking/mockLink.js
generated
vendored
Normal file
201
node_modules/@apollo/client/testing/core/mocking/mockLink.js
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
import { __assign, __extends } from "tslib";
|
||||
import { invariant } from "../../../utilities/globals/index.js";
|
||||
import { equal } from "@wry/equality";
|
||||
import { ApolloLink } from "../../../link/core/index.js";
|
||||
import { Observable, addTypenameToDocument, removeClientSetsFromDocument, cloneDeep, print, getOperationDefinition, getDefaultValues, removeDirectivesFromDocument, checkDocument, makeUniqueId, } from "../../../utilities/index.js";
|
||||
function requestToKey(request, addTypename) {
|
||||
var queryString = request.query &&
|
||||
print(addTypename ? addTypenameToDocument(request.query) : request.query);
|
||||
var requestKey = { query: queryString };
|
||||
return JSON.stringify(requestKey);
|
||||
}
|
||||
var MockLink = /** @class */ (function (_super) {
|
||||
__extends(MockLink, _super);
|
||||
function MockLink(mockedResponses, addTypename, options) {
|
||||
if (addTypename === void 0) { addTypename = true; }
|
||||
if (options === void 0) { options = Object.create(null); }
|
||||
var _a;
|
||||
var _this = _super.call(this) || this;
|
||||
_this.addTypename = true;
|
||||
_this.showWarnings = true;
|
||||
_this.mockedResponsesByKey = {};
|
||||
_this.addTypename = addTypename;
|
||||
_this.showWarnings = (_a = options.showWarnings) !== null && _a !== void 0 ? _a : true;
|
||||
if (mockedResponses) {
|
||||
mockedResponses.forEach(function (mockedResponse) {
|
||||
_this.addMockedResponse(mockedResponse);
|
||||
});
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
MockLink.prototype.addMockedResponse = function (mockedResponse) {
|
||||
var normalizedMockedResponse = this.normalizeMockedResponse(mockedResponse);
|
||||
var key = requestToKey(normalizedMockedResponse.request, this.addTypename);
|
||||
var mockedResponses = this.mockedResponsesByKey[key];
|
||||
if (!mockedResponses) {
|
||||
mockedResponses = [];
|
||||
this.mockedResponsesByKey[key] = mockedResponses;
|
||||
}
|
||||
mockedResponses.push(normalizedMockedResponse);
|
||||
};
|
||||
MockLink.prototype.request = function (operation) {
|
||||
var _this = this;
|
||||
var _a;
|
||||
this.operation = operation;
|
||||
var key = requestToKey(operation, this.addTypename);
|
||||
var unmatchedVars = [];
|
||||
var requestVariables = operation.variables || {};
|
||||
var mockedResponses = this.mockedResponsesByKey[key];
|
||||
var responseIndex = mockedResponses ?
|
||||
mockedResponses.findIndex(function (res, index) {
|
||||
var mockedResponseVars = res.request.variables || {};
|
||||
if (equal(requestVariables, mockedResponseVars)) {
|
||||
return true;
|
||||
}
|
||||
if (res.variableMatcher && res.variableMatcher(operation.variables)) {
|
||||
return true;
|
||||
}
|
||||
unmatchedVars.push(mockedResponseVars);
|
||||
return false;
|
||||
})
|
||||
: -1;
|
||||
var response = responseIndex >= 0 ? mockedResponses[responseIndex] : void 0;
|
||||
// There have been platform- and engine-dependent differences with
|
||||
// setInterval(fn, Infinity), so we pass 0 instead (but detect
|
||||
// Infinity where we call observer.error or observer.next to pend
|
||||
// indefinitely in those cases.)
|
||||
var delay = (response === null || response === void 0 ? void 0 : response.delay) === Infinity ? 0 : (_a = response === null || response === void 0 ? void 0 : response.delay) !== null && _a !== void 0 ? _a : 0;
|
||||
var configError;
|
||||
if (!response) {
|
||||
configError = new Error("No more mocked responses for the query: ".concat(print(operation.query), "\nExpected variables: ").concat(stringifyForDebugging(operation.variables), "\n").concat(unmatchedVars.length > 0 ?
|
||||
"\nFailed to match ".concat(unmatchedVars.length, " mock").concat(unmatchedVars.length === 1 ? "" : "s", " for this query. The mocked response had the following variables:\n").concat(unmatchedVars.map(function (d) { return " ".concat(stringifyForDebugging(d)); }).join("\n"), "\n")
|
||||
: ""));
|
||||
if (this.showWarnings) {
|
||||
console.warn(configError.message +
|
||||
"\nThis typically indicates a configuration error in your mocks " +
|
||||
"setup, usually due to a typo or mismatched variable.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (response.maxUsageCount && response.maxUsageCount > 1) {
|
||||
response.maxUsageCount--;
|
||||
}
|
||||
else {
|
||||
mockedResponses.splice(responseIndex, 1);
|
||||
}
|
||||
var newData = response.newData;
|
||||
if (newData) {
|
||||
response.result = newData(operation.variables);
|
||||
mockedResponses.push(response);
|
||||
}
|
||||
if (!response.result && !response.error && response.delay !== Infinity) {
|
||||
configError = new Error("Mocked response should contain either `result`, `error` or a `delay` of `Infinity`: ".concat(key));
|
||||
}
|
||||
}
|
||||
return new Observable(function (observer) {
|
||||
var timer = setTimeout(function () {
|
||||
if (configError) {
|
||||
try {
|
||||
// The onError function can return false to indicate that
|
||||
// configError need not be passed to observer.error. For
|
||||
// example, the default implementation of onError calls
|
||||
// observer.error(configError) and then returns false to
|
||||
// prevent this extra (harmless) observer.error call.
|
||||
if (_this.onError(configError, observer) !== false) {
|
||||
throw configError;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
observer.error(error);
|
||||
}
|
||||
}
|
||||
else if (response && response.delay !== Infinity) {
|
||||
if (response.error) {
|
||||
observer.error(response.error);
|
||||
}
|
||||
else {
|
||||
if (response.result) {
|
||||
observer.next(typeof response.result === "function" ?
|
||||
response.result(operation.variables)
|
||||
: response.result);
|
||||
}
|
||||
observer.complete();
|
||||
}
|
||||
}
|
||||
}, delay);
|
||||
return function () {
|
||||
clearTimeout(timer);
|
||||
};
|
||||
});
|
||||
};
|
||||
MockLink.prototype.normalizeMockedResponse = function (mockedResponse) {
|
||||
var _a;
|
||||
var newMockedResponse = cloneDeep(mockedResponse);
|
||||
var queryWithoutClientOnlyDirectives = removeDirectivesFromDocument([{ name: "connection" }, { name: "nonreactive" }, { name: "unmask" }], checkDocument(newMockedResponse.request.query));
|
||||
invariant(queryWithoutClientOnlyDirectives, 75);
|
||||
newMockedResponse.request.query = queryWithoutClientOnlyDirectives;
|
||||
var query = removeClientSetsFromDocument(newMockedResponse.request.query);
|
||||
if (query) {
|
||||
newMockedResponse.request.query = query;
|
||||
}
|
||||
mockedResponse.maxUsageCount = (_a = mockedResponse.maxUsageCount) !== null && _a !== void 0 ? _a : 1;
|
||||
invariant(mockedResponse.maxUsageCount > 0, 76, mockedResponse.maxUsageCount);
|
||||
this.normalizeVariableMatching(newMockedResponse);
|
||||
return newMockedResponse;
|
||||
};
|
||||
MockLink.prototype.normalizeVariableMatching = function (mockedResponse) {
|
||||
var request = mockedResponse.request;
|
||||
if (mockedResponse.variableMatcher && request.variables) {
|
||||
throw new Error("Mocked response should contain either variableMatcher or request.variables");
|
||||
}
|
||||
if (!mockedResponse.variableMatcher) {
|
||||
request.variables = __assign(__assign({}, getDefaultValues(getOperationDefinition(request.query))), request.variables);
|
||||
mockedResponse.variableMatcher = function (vars) {
|
||||
var requestVariables = vars || {};
|
||||
var mockedResponseVariables = request.variables || {};
|
||||
return equal(requestVariables, mockedResponseVariables);
|
||||
};
|
||||
}
|
||||
};
|
||||
return MockLink;
|
||||
}(ApolloLink));
|
||||
export { MockLink };
|
||||
// Pass in multiple mocked responses, so that you can test flows that end up
|
||||
// making multiple queries to the server.
|
||||
// NOTE: The last arg can optionally be an `addTypename` arg.
|
||||
export function mockSingleLink() {
|
||||
var mockedResponses = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
mockedResponses[_i] = arguments[_i];
|
||||
}
|
||||
// To pull off the potential typename. If this isn't a boolean, we'll just
|
||||
// set it true later.
|
||||
var maybeTypename = mockedResponses[mockedResponses.length - 1];
|
||||
var mocks = mockedResponses.slice(0, mockedResponses.length - 1);
|
||||
if (typeof maybeTypename !== "boolean") {
|
||||
mocks = mockedResponses;
|
||||
maybeTypename = true;
|
||||
}
|
||||
return new MockLink(mocks, maybeTypename);
|
||||
}
|
||||
// This is similiar to the stringifyForDisplay utility we ship, but includes
|
||||
// support for NaN in addition to undefined. More values may be handled in the
|
||||
// future. This is not added to the primary stringifyForDisplay helper since it
|
||||
// is used for the cache and other purposes. We need this for debuggging only.
|
||||
export function stringifyForDebugging(value, space) {
|
||||
if (space === void 0) { space = 0; }
|
||||
var undefId = makeUniqueId("undefined");
|
||||
var nanId = makeUniqueId("NaN");
|
||||
return JSON.stringify(value, function (_, value) {
|
||||
if (value === void 0) {
|
||||
return undefId;
|
||||
}
|
||||
if (Number.isNaN(value)) {
|
||||
return nanId;
|
||||
}
|
||||
return value;
|
||||
}, space)
|
||||
.replace(new RegExp(JSON.stringify(undefId), "g"), "<undefined>")
|
||||
.replace(new RegExp(JSON.stringify(nanId), "g"), "NaN");
|
||||
}
|
||||
//# sourceMappingURL=mockLink.js.map
|
||||
1
node_modules/@apollo/client/testing/core/mocking/mockLink.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/mocking/mockLink.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
25
node_modules/@apollo/client/testing/core/mocking/mockSubscriptionLink.d.ts
generated
vendored
Normal file
25
node_modules/@apollo/client/testing/core/mocking/mockSubscriptionLink.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Observable } from "../../../utilities/index.js";
|
||||
import type { FetchResult, Operation } from "../../../link/core/index.js";
|
||||
import { ApolloLink } from "../../../link/core/index.js";
|
||||
export interface MockedSubscription {
|
||||
request: Operation;
|
||||
}
|
||||
export interface MockedSubscriptionResult {
|
||||
result?: FetchResult;
|
||||
error?: Error;
|
||||
delay?: number;
|
||||
}
|
||||
export declare class MockSubscriptionLink extends ApolloLink {
|
||||
unsubscribers: any[];
|
||||
setups: any[];
|
||||
operation?: Operation;
|
||||
private observers;
|
||||
constructor();
|
||||
request(operation: Operation): Observable<FetchResult>;
|
||||
simulateResult(result: MockedSubscriptionResult, complete?: boolean): void;
|
||||
simulateComplete(): void;
|
||||
onSetup(listener: any): void;
|
||||
onUnsubscribe(listener: any): void;
|
||||
}
|
||||
export declare function mockObservableLink(): MockSubscriptionLink;
|
||||
//# sourceMappingURL=mockSubscriptionLink.d.ts.map
|
||||
62
node_modules/@apollo/client/testing/core/mocking/mockSubscriptionLink.js
generated
vendored
Normal file
62
node_modules/@apollo/client/testing/core/mocking/mockSubscriptionLink.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
import { __extends } from "tslib";
|
||||
import { Observable } from "../../../utilities/index.js";
|
||||
import { ApolloLink } from "../../../link/core/index.js";
|
||||
var MockSubscriptionLink = /** @class */ (function (_super) {
|
||||
__extends(MockSubscriptionLink, _super);
|
||||
function MockSubscriptionLink() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.unsubscribers = [];
|
||||
_this.setups = [];
|
||||
_this.observers = [];
|
||||
return _this;
|
||||
}
|
||||
MockSubscriptionLink.prototype.request = function (operation) {
|
||||
var _this = this;
|
||||
this.operation = operation;
|
||||
return new Observable(function (observer) {
|
||||
_this.setups.forEach(function (x) { return x(); });
|
||||
_this.observers.push(observer);
|
||||
return function () {
|
||||
_this.unsubscribers.forEach(function (x) { return x(); });
|
||||
};
|
||||
});
|
||||
};
|
||||
MockSubscriptionLink.prototype.simulateResult = function (result, complete) {
|
||||
var _this = this;
|
||||
if (complete === void 0) { complete = false; }
|
||||
setTimeout(function () {
|
||||
var observers = _this.observers;
|
||||
if (!observers.length)
|
||||
throw new Error("subscription torn down");
|
||||
observers.forEach(function (observer) {
|
||||
if (result.result && observer.next)
|
||||
observer.next(result.result);
|
||||
if (result.error && observer.error)
|
||||
observer.error(result.error);
|
||||
if (complete && observer.complete)
|
||||
observer.complete();
|
||||
});
|
||||
}, result.delay || 0);
|
||||
};
|
||||
MockSubscriptionLink.prototype.simulateComplete = function () {
|
||||
var observers = this.observers;
|
||||
if (!observers.length)
|
||||
throw new Error("subscription torn down");
|
||||
observers.forEach(function (observer) {
|
||||
if (observer.complete)
|
||||
observer.complete();
|
||||
});
|
||||
};
|
||||
MockSubscriptionLink.prototype.onSetup = function (listener) {
|
||||
this.setups = this.setups.concat([listener]);
|
||||
};
|
||||
MockSubscriptionLink.prototype.onUnsubscribe = function (listener) {
|
||||
this.unsubscribers = this.unsubscribers.concat([listener]);
|
||||
};
|
||||
return MockSubscriptionLink;
|
||||
}(ApolloLink));
|
||||
export { MockSubscriptionLink };
|
||||
export function mockObservableLink() {
|
||||
return new MockSubscriptionLink();
|
||||
}
|
||||
//# sourceMappingURL=mockSubscriptionLink.js.map
|
||||
1
node_modules/@apollo/client/testing/core/mocking/mockSubscriptionLink.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/mocking/mockSubscriptionLink.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mockSubscriptionLink.js","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockSubscriptionLink.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAYzD;IAA0C,wCAAU;IAOlD;QACE,YAAA,MAAK,WAAE,SAAC;QAPH,mBAAa,GAAU,EAAE,CAAC;QAC1B,YAAM,GAAU,EAAE,CAAC;QAGlB,eAAS,GAAU,EAAE,CAAC;;IAI9B,CAAC;IAEM,sCAAO,GAAd,UAAe,SAAoB;QAAnC,iBASC;QARC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,OAAO,IAAI,UAAU,CAAc,UAAC,QAAQ;YAC1C,KAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,EAAE,EAAH,CAAG,CAAC,CAAC;YAChC,KAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9B,OAAO;gBACL,KAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,EAAE,EAAH,CAAG,CAAC,CAAC;YACzC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,6CAAc,GAArB,UAAsB,MAAgC,EAAE,QAAgB;QAAxE,iBAUC;QAVuD,yBAAA,EAAA,gBAAgB;QACtE,UAAU,CAAC;YACD,IAAA,SAAS,GAAK,KAAI,UAAT,CAAU;YAC3B,IAAI,CAAC,SAAS,CAAC,MAAM;gBAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;YACjE,SAAS,CAAC,OAAO,CAAC,UAAC,QAAQ;gBACzB,IAAI,MAAM,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI;oBAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACjE,IAAI,MAAM,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK;oBAAE,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACjE,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ;oBAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACzD,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;IACxB,CAAC;IAEM,+CAAgB,GAAvB;QACU,IAAA,SAAS,GAAK,IAAI,UAAT,CAAU;QAC3B,IAAI,CAAC,SAAS,CAAC,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QACjE,SAAS,CAAC,OAAO,CAAC,UAAC,QAAQ;YACzB,IAAI,QAAQ,CAAC,QAAQ;gBAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,sCAAO,GAAd,UAAe,QAAa;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,CAAC;IAEM,4CAAa,GAApB,UAAqB,QAAa;QAChC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7D,CAAC;IACH,2BAAC;AAAD,CAAC,AAjDD,CAA0C,UAAU,GAiDnD;;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,oBAAoB,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import { Observable } from \"../../../utilities/index.js\";\nimport type { FetchResult, Operation } from \"../../../link/core/index.js\";\nimport { ApolloLink } from \"../../../link/core/index.js\";\n\nexport interface MockedSubscription {\n request: Operation;\n}\n\nexport interface MockedSubscriptionResult {\n result?: FetchResult;\n error?: Error;\n delay?: number;\n}\n\nexport class MockSubscriptionLink extends ApolloLink {\n public unsubscribers: any[] = [];\n public setups: any[] = [];\n public operation?: Operation;\n\n private observers: any[] = [];\n\n constructor() {\n super();\n }\n\n public request(operation: Operation) {\n this.operation = operation;\n return new Observable<FetchResult>((observer) => {\n this.setups.forEach((x) => x());\n this.observers.push(observer);\n return () => {\n this.unsubscribers.forEach((x) => x());\n };\n });\n }\n\n public simulateResult(result: MockedSubscriptionResult, complete = false) {\n setTimeout(() => {\n const { observers } = this;\n if (!observers.length) throw new Error(\"subscription torn down\");\n observers.forEach((observer) => {\n if (result.result && observer.next) observer.next(result.result);\n if (result.error && observer.error) observer.error(result.error);\n if (complete && observer.complete) observer.complete();\n });\n }, result.delay || 0);\n }\n\n public simulateComplete() {\n const { observers } = this;\n if (!observers.length) throw new Error(\"subscription torn down\");\n observers.forEach((observer) => {\n if (observer.complete) observer.complete();\n });\n }\n\n public onSetup(listener: any): void {\n this.setups = this.setups.concat([listener]);\n }\n\n public onUnsubscribe(listener: any): void {\n this.unsubscribers = this.unsubscribers.concat([listener]);\n }\n}\n\nexport function mockObservableLink(): MockSubscriptionLink {\n return new MockSubscriptionLink();\n}\n"]}
|
||||
8
node_modules/@apollo/client/testing/core/package.json
generated
vendored
Normal file
8
node_modules/@apollo/client/testing/core/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@apollo/client/testing/core",
|
||||
"type": "module",
|
||||
"main": "core.cjs",
|
||||
"module": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"sideEffects": false
|
||||
}
|
||||
3
node_modules/@apollo/client/testing/core/subscribeAndCount.d.ts
generated
vendored
Normal file
3
node_modules/@apollo/client/testing/core/subscribeAndCount.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { ObservableSubscription, Observable } from "../../utilities/index.js";
|
||||
export default function subscribeAndCount<TResult>(reject: (reason: any) => any, observable: Observable<TResult>, cb: (handleCount: number, result: TResult) => any): ObservableSubscription;
|
||||
//# sourceMappingURL=subscribeAndCount.d.ts.map
|
||||
21
node_modules/@apollo/client/testing/core/subscribeAndCount.js
generated
vendored
Normal file
21
node_modules/@apollo/client/testing/core/subscribeAndCount.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { asyncMap } from "../../utilities/index.js";
|
||||
export default function subscribeAndCount(reject, observable, cb) {
|
||||
// Use a Promise queue to prevent callbacks from being run out of order.
|
||||
var queue = Promise.resolve();
|
||||
var handleCount = 0;
|
||||
var subscription = asyncMap(observable, function (result) {
|
||||
// All previous asynchronous callbacks must complete before cb can
|
||||
// be invoked with this result.
|
||||
return (queue = queue
|
||||
.then(function () {
|
||||
return cb(++handleCount, result);
|
||||
})
|
||||
.catch(error));
|
||||
}).subscribe({ error: error });
|
||||
function error(e) {
|
||||
subscription.unsubscribe();
|
||||
reject(e);
|
||||
}
|
||||
return subscription;
|
||||
}
|
||||
//# sourceMappingURL=subscribeAndCount.js.map
|
||||
1
node_modules/@apollo/client/testing/core/subscribeAndCount.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/subscribeAndCount.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"subscribeAndCount.js","sourceRoot":"","sources":["../../../src/testing/core/subscribeAndCount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,MAA4B,EAC5B,UAA+B,EAC/B,EAAiD;IAEjD,wEAAwE;IACxE,IAAI,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC9B,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,IAAM,YAAY,GAAG,QAAQ,CAAC,UAAU,EAAE,UAAC,MAAM;QAC/C,kEAAkE;QAClE,+BAA+B;QAC/B,OAAO,CAAC,KAAK,GAAG,KAAK;aAClB,IAAI,CAAC;YACJ,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC,CAAC;aACD,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;IAExB,SAAS,KAAK,CAAC,CAAM;QACnB,YAAY,CAAC,WAAW,EAAE,CAAC;QAC3B,MAAM,CAAC,CAAC,CAAC,CAAC;IACZ,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import type {\n ObservableSubscription,\n Observable,\n} from \"../../utilities/index.js\";\nimport { asyncMap } from \"../../utilities/index.js\";\n\nexport default function subscribeAndCount<TResult>(\n reject: (reason: any) => any,\n observable: Observable<TResult>,\n cb: (handleCount: number, result: TResult) => any\n): ObservableSubscription {\n // Use a Promise queue to prevent callbacks from being run out of order.\n let queue = Promise.resolve();\n let handleCount = 0;\n\n const subscription = asyncMap(observable, (result) => {\n // All previous asynchronous callbacks must complete before cb can\n // be invoked with this result.\n return (queue = queue\n .then(() => {\n return cb(++handleCount, result);\n })\n .catch(error));\n }).subscribe({ error });\n\n function error(e: any) {\n subscription.unsubscribe();\n reject(e);\n }\n\n return subscription;\n}\n"]}
|
||||
3
node_modules/@apollo/client/testing/core/wait.d.ts
generated
vendored
Normal file
3
node_modules/@apollo/client/testing/core/wait.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare function wait(ms: number): Promise<void>;
|
||||
export declare function tick(): Promise<void>;
|
||||
//# sourceMappingURL=wait.d.ts.map
|
||||
16
node_modules/@apollo/client/testing/core/wait.js
generated
vendored
Normal file
16
node_modules/@apollo/client/testing/core/wait.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
export function wait(ms) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
||||
});
|
||||
});
|
||||
}
|
||||
export function tick() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, wait(0)];
|
||||
});
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=wait.js.map
|
||||
1
node_modules/@apollo/client/testing/core/wait.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/wait.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../../../src/testing/core/wait.ts"],"names":[],"mappings":";AAAA,MAAM,UAAgB,IAAI,CAAC,EAAU;;;YACnC,sBAAO,IAAI,OAAO,CAAO,UAAC,OAAO,IAAK,OAAA,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,EAAvB,CAAuB,CAAC,EAAC;;;CAChE;AAED,MAAM,UAAgB,IAAI;;;YACxB,sBAAO,IAAI,CAAC,CAAC,CAAC,EAAC;;;CAChB","sourcesContent":["export async function wait(ms: number) {\n return new Promise<void>((resolve) => setTimeout(resolve, ms));\n}\n\nexport async function tick() {\n return wait(0);\n}\n"]}
|
||||
7
node_modules/@apollo/client/testing/core/withConsoleSpy.d.ts
generated
vendored
Normal file
7
node_modules/@apollo/client/testing/core/withConsoleSpy.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/** @deprecated This method will be removed in the next major version of Apollo Client */
|
||||
export declare function withErrorSpy<TArgs extends any[], TResult>(it: (...args: TArgs) => TResult, ...args: TArgs): TResult;
|
||||
/** @deprecated This method will be removed in the next major version of Apollo Client */
|
||||
export declare function withWarningSpy<TArgs extends any[], TResult>(it: (...args: TArgs) => TResult, ...args: TArgs): TResult;
|
||||
/** @deprecated This method will be removed in the next major version of Apollo Client */
|
||||
export declare function withLogSpy<TArgs extends any[], TResult>(it: (...args: TArgs) => TResult, ...args: TArgs): TResult;
|
||||
//# sourceMappingURL=withConsoleSpy.d.ts.map
|
||||
45
node_modules/@apollo/client/testing/core/withConsoleSpy.js
generated
vendored
Normal file
45
node_modules/@apollo/client/testing/core/withConsoleSpy.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
function wrapTestFunction(fn, consoleMethodName) {
|
||||
return function () {
|
||||
var _this = this;
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
var spy = jest.spyOn(console, consoleMethodName);
|
||||
spy.mockImplementation(function () { });
|
||||
return new Promise(function (resolve) {
|
||||
resolve(fn === null || fn === void 0 ? void 0 : fn.apply(_this, args));
|
||||
}).finally(function () {
|
||||
expect(spy).toMatchSnapshot();
|
||||
spy.mockReset();
|
||||
});
|
||||
};
|
||||
}
|
||||
/** @deprecated This method will be removed in the next major version of Apollo Client */
|
||||
export function withErrorSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "error");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
/** @deprecated This method will be removed in the next major version of Apollo Client */
|
||||
export function withWarningSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "warn");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
/** @deprecated This method will be removed in the next major version of Apollo Client */
|
||||
export function withLogSpy(it) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
args[1] = wrapTestFunction(args[1], "log");
|
||||
return it.apply(void 0, args);
|
||||
}
|
||||
//# sourceMappingURL=withConsoleSpy.js.map
|
||||
1
node_modules/@apollo/client/testing/core/withConsoleSpy.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/withConsoleSpy.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"withConsoleSpy.js","sourceRoot":"","sources":["../../../src/testing/core/withConsoleSpy.ts"],"names":[],"mappings":"AAAA,SAAS,gBAAgB,CACvB,EAA2B,EAC3B,iBAA2C;IAE3C,OAAO;QAAA,iBASN;QAT2B,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;QACxC,IAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;QACnD,GAAG,CAAC,kBAAkB,CAAC,cAAO,CAAC,CAAC,CAAC;QACjC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO;YACzB,OAAO,CAAC,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,CAAC,KAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC,OAAO,CAAC;YACT,MAAM,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,CAAC;YAC9B,GAAG,CAAC,SAAS,EAAE,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAC1B,EAA+B;IAC/B,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IAEd,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC7C,OAAO,EAAE,eAAI,IAAI,EAAE;AACrB,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,cAAc,CAC5B,EAA+B;IAC/B,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IAEd,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC5C,OAAO,EAAE,eAAI,IAAI,EAAE;AACrB,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,UAAU,CACxB,EAA+B;IAC/B,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IAEd,IAAI,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,EAAE,eAAI,IAAI,EAAE;AACrB,CAAC","sourcesContent":["function wrapTestFunction(\n fn: (...args: any[]) => any,\n consoleMethodName: \"log\" | \"warn\" | \"error\"\n) {\n return function (this: any, ...args: any[]) {\n const spy = jest.spyOn(console, consoleMethodName);\n spy.mockImplementation(() => {});\n return new Promise((resolve) => {\n resolve(fn?.apply(this, args));\n }).finally(() => {\n expect(spy).toMatchSnapshot();\n spy.mockReset();\n });\n };\n}\n\n/** @deprecated This method will be removed in the next major version of Apollo Client */\nexport function withErrorSpy<TArgs extends any[], TResult>(\n it: (...args: TArgs) => TResult,\n ...args: TArgs\n) {\n args[1] = wrapTestFunction(args[1], \"error\");\n return it(...args);\n}\n\n/** @deprecated This method will be removed in the next major version of Apollo Client */\nexport function withWarningSpy<TArgs extends any[], TResult>(\n it: (...args: TArgs) => TResult,\n ...args: TArgs\n) {\n args[1] = wrapTestFunction(args[1], \"warn\");\n return it(...args);\n}\n\n/** @deprecated This method will be removed in the next major version of Apollo Client */\nexport function withLogSpy<TArgs extends any[], TResult>(\n it: (...args: TArgs) => TResult,\n ...args: TArgs\n) {\n args[1] = wrapTestFunction(args[1], \"log\");\n return it(...args);\n}\n"]}
|
||||
4
node_modules/@apollo/client/testing/core/wrap.d.ts
generated
vendored
Normal file
4
node_modules/@apollo/client/testing/core/wrap.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
declare const _default: <TArgs extends any[], TResult>(reject: (reason: any) => any, cb: (...args: TArgs) => TResult) => (...args: TArgs) => TResult | undefined;
|
||||
export default _default;
|
||||
export declare function withError(func: Function, regex: RegExp): any;
|
||||
//# sourceMappingURL=wrap.d.ts.map
|
||||
30
node_modules/@apollo/client/testing/core/wrap.js
generated
vendored
Normal file
30
node_modules/@apollo/client/testing/core/wrap.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// I'm not sure why mocha doesn't provide something like this, you can't
|
||||
// always use promises
|
||||
export default (function(reject, cb) {
|
||||
return function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
try {
|
||||
return cb.apply(void 0, args);
|
||||
}
|
||||
catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
});
|
||||
export function withError(func, regex) {
|
||||
var message = null;
|
||||
var oldError = console.error;
|
||||
console.error = function (m) { return (message = m); };
|
||||
try {
|
||||
var result = func();
|
||||
expect(message).toMatch(regex);
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
console.error = oldError;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=wrap.js.map
|
||||
1
node_modules/@apollo/client/testing/core/wrap.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/core/wrap.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../../../src/testing/core/wrap.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,sBAAsB;AACtB,gBAAe,UACX,MAA4B,EAC5B,EAA+B;IAEjC,OAAA;QAAC,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;QACb,IAAI,CAAC;YACH,OAAO,EAAE,eAAI,IAAI,EAAE;QACrB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,CAAC,CAAC,CAAC;QACZ,CAAC;IACH,CAAC;AAND,CAMC,EAAC;AAEJ,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,KAAa;IACrD,IAAI,OAAO,GAAW,IAAa,CAAC;IACpC,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC;IAE/B,OAAO,CAAC,KAAK,GAAG,UAAC,CAAS,IAAK,OAAA,CAAC,OAAO,GAAG,CAAC,CAAC,EAAb,CAAa,CAAC;IAE7C,IAAI,CAAC;QACH,IAAM,MAAM,GAAG,IAAI,EAAE,CAAC;QACtB,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,MAAM,CAAC;IAChB,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;IAC3B,CAAC;AACH,CAAC","sourcesContent":["// I'm not sure why mocha doesn't provide something like this, you can't\n// always use promises\nexport default <TArgs extends any[], TResult>(\n reject: (reason: any) => any,\n cb: (...args: TArgs) => TResult\n ) =>\n (...args: TArgs) => {\n try {\n return cb(...args);\n } catch (e) {\n reject(e);\n }\n };\n\nexport function withError(func: Function, regex: RegExp) {\n let message: string = null as never;\n const oldError = console.error;\n\n console.error = (m: string) => (message = m);\n\n try {\n const result = func();\n expect(message).toMatch(regex);\n return result;\n } finally {\n console.error = oldError;\n }\n}\n"]}
|
||||
43
node_modules/@apollo/client/testing/experimental/createSchemaFetch.d.ts
generated
vendored
Normal file
43
node_modules/@apollo/client/testing/experimental/createSchemaFetch.d.ts
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import type { GraphQLSchema } from "graphql";
|
||||
/**
|
||||
* A function that accepts a static `schema` and a `mockFetchOpts` object and
|
||||
* returns a disposable object with `mock` and `restore` functions.
|
||||
*
|
||||
* The `mock` function is a mock fetch function that is set on the global
|
||||
* `window` object. This function intercepts any fetch requests and
|
||||
* returns a response by executing the operation against the provided schema.
|
||||
*
|
||||
* The `restore` function is a cleanup function that will restore the previous
|
||||
* `fetch`. It is automatically called if the function's return value is
|
||||
* declared with `using`. If your environment does not support the language
|
||||
* feature `using`, you should manually invoke the `restore` function.
|
||||
*
|
||||
* @param schema - A `GraphQLSchema`.
|
||||
* @param mockFetchOpts - Configuration options.
|
||||
* @returns An object with both `mock` and `restore` functions.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* using _fetch = createSchemaFetch(schema); // automatically restores fetch after exiting the block
|
||||
*
|
||||
* const { restore } = createSchemaFetch(schema);
|
||||
* restore(); // manually restore fetch if `using` is not supported
|
||||
* ```
|
||||
* @since 3.10.0
|
||||
* @alpha
|
||||
* @deprecated `createSchemaFetch` is deprecated and will be removed in 3.12.0.
|
||||
* Please migrate to [`@apollo/graphql-testing-library`](https://github.com/apollographql/graphql-testing-library).
|
||||
*/
|
||||
declare const createSchemaFetch: (schema: GraphQLSchema, mockFetchOpts?: {
|
||||
validate?: boolean;
|
||||
delay?: {
|
||||
min: number;
|
||||
max: number;
|
||||
};
|
||||
}) => ((uri?: any, options?: any) => Promise<Response>) & {
|
||||
mockGlobal: () => {
|
||||
restore: () => void;
|
||||
} & Disposable;
|
||||
};
|
||||
export { createSchemaFetch };
|
||||
//# sourceMappingURL=createSchemaFetch.d.ts.map
|
||||
103
node_modules/@apollo/client/testing/experimental/createSchemaFetch.js
generated
vendored
Normal file
103
node_modules/@apollo/client/testing/experimental/createSchemaFetch.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
import { execute, GraphQLError, validate } from "graphql";
|
||||
import { gql } from "../../core/index.js";
|
||||
import { withCleanup } from "../internal/index.js";
|
||||
import { wait } from "../core/wait.js";
|
||||
/**
|
||||
* A function that accepts a static `schema` and a `mockFetchOpts` object and
|
||||
* returns a disposable object with `mock` and `restore` functions.
|
||||
*
|
||||
* The `mock` function is a mock fetch function that is set on the global
|
||||
* `window` object. This function intercepts any fetch requests and
|
||||
* returns a response by executing the operation against the provided schema.
|
||||
*
|
||||
* The `restore` function is a cleanup function that will restore the previous
|
||||
* `fetch`. It is automatically called if the function's return value is
|
||||
* declared with `using`. If your environment does not support the language
|
||||
* feature `using`, you should manually invoke the `restore` function.
|
||||
*
|
||||
* @param schema - A `GraphQLSchema`.
|
||||
* @param mockFetchOpts - Configuration options.
|
||||
* @returns An object with both `mock` and `restore` functions.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* using _fetch = createSchemaFetch(schema); // automatically restores fetch after exiting the block
|
||||
*
|
||||
* const { restore } = createSchemaFetch(schema);
|
||||
* restore(); // manually restore fetch if `using` is not supported
|
||||
* ```
|
||||
* @since 3.10.0
|
||||
* @alpha
|
||||
* @deprecated `createSchemaFetch` is deprecated and will be removed in 3.12.0.
|
||||
* Please migrate to [`@apollo/graphql-testing-library`](https://github.com/apollographql/graphql-testing-library).
|
||||
*/
|
||||
var createSchemaFetch = function (schema, mockFetchOpts) {
|
||||
var _a, _b, _c, _d;
|
||||
if (mockFetchOpts === void 0) { mockFetchOpts = { validate: true }; }
|
||||
var prevFetch = window.fetch;
|
||||
var delayMin = (_b = (_a = mockFetchOpts.delay) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : 3;
|
||||
var delayMax = (_d = (_c = mockFetchOpts.delay) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : delayMin + 2;
|
||||
if (delayMin > delayMax) {
|
||||
throw new Error("Please configure a minimum delay that is less than the maximum delay. The default minimum delay is 3ms.");
|
||||
}
|
||||
var mockFetch = function (_uri, options) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var randomDelay, body, document, validationErrors, result, stringifiedResult;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!(delayMin > 0)) return [3 /*break*/, 2];
|
||||
randomDelay = Math.random() * (delayMax - delayMin) + delayMin;
|
||||
return [4 /*yield*/, wait(randomDelay)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
body = JSON.parse(options.body);
|
||||
document = gql(body.query);
|
||||
if (mockFetchOpts.validate) {
|
||||
validationErrors = [];
|
||||
try {
|
||||
validationErrors = validate(schema, document);
|
||||
}
|
||||
catch (e) {
|
||||
validationErrors = [
|
||||
e instanceof Error ?
|
||||
GraphQLError.prototype.toJSON.apply(e)
|
||||
: e,
|
||||
];
|
||||
}
|
||||
if ((validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.length) > 0) {
|
||||
return [2 /*return*/, new Response(JSON.stringify({ errors: validationErrors }))];
|
||||
}
|
||||
}
|
||||
return [4 /*yield*/, execute({
|
||||
schema: schema,
|
||||
document: document,
|
||||
variableValues: body.variables,
|
||||
operationName: body.operationName,
|
||||
})];
|
||||
case 3:
|
||||
result = _a.sent();
|
||||
stringifiedResult = JSON.stringify(result);
|
||||
return [2 /*return*/, new Response(stringifiedResult)];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
function mockGlobal() {
|
||||
window.fetch = mockFetch;
|
||||
var restore = function () {
|
||||
if (window.fetch === mockFetch) {
|
||||
window.fetch = prevFetch;
|
||||
}
|
||||
};
|
||||
return withCleanup({ restore: restore }, restore);
|
||||
}
|
||||
return Object.assign(mockFetch, {
|
||||
mockGlobal: mockGlobal,
|
||||
// if https://github.com/rbuckton/proposal-using-enforcement lands
|
||||
// [Symbol.enter]: mockGlobal
|
||||
});
|
||||
};
|
||||
export { createSchemaFetch };
|
||||
//# sourceMappingURL=createSchemaFetch.js.map
|
||||
1
node_modules/@apollo/client/testing/experimental/createSchemaFetch.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/experimental/createSchemaFetch.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
57
node_modules/@apollo/client/testing/experimental/createTestSchema.d.ts
generated
vendored
Normal file
57
node_modules/@apollo/client/testing/experimental/createTestSchema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { GraphQLSchema } from "graphql";
|
||||
import type { Resolvers } from "../../core/types.js";
|
||||
type ProxiedSchema = GraphQLSchema & TestSchemaFns;
|
||||
interface TestSchemaFns {
|
||||
add: (addOptions: {
|
||||
resolvers: Resolvers;
|
||||
}) => ProxiedSchema;
|
||||
fork: (forkOptions?: {
|
||||
resolvers?: Resolvers;
|
||||
}) => ProxiedSchema;
|
||||
reset: () => void;
|
||||
}
|
||||
interface TestSchemaOptions {
|
||||
resolvers: Resolvers;
|
||||
scalars?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* A function that creates a [Proxy object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
|
||||
* around a given `schema` with `resolvers`. This proxied schema can be used to
|
||||
* progressively layer resolvers on top of the original schema using the `add`
|
||||
* method. The `fork` method can be used to create a new proxied schema which
|
||||
* can be modified independently of the original schema. `reset` will restore
|
||||
* resolvers to the original proxied schema.
|
||||
*
|
||||
* @param schema - A `GraphQLSchema`.
|
||||
* @param options - An `options` object that accepts `scalars` and `resolvers` objects.
|
||||
* @returns A `ProxiedSchema` with `add`, `fork` and `reset` methods.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const schema = createTestSchema(schemaWithTypeDefs, {
|
||||
* resolvers: {
|
||||
Query: {
|
||||
writer: () => ({
|
||||
name: "Ada Lovelace",
|
||||
}),
|
||||
}
|
||||
},
|
||||
scalars: {
|
||||
ID: () => "1",
|
||||
Int: () => 36,
|
||||
String: () => "String",
|
||||
Date: () => new Date("December 10, 1815 01:00:00").toJSON().split("T")[0],
|
||||
}
|
||||
});
|
||||
* ```
|
||||
* @since 3.9.0
|
||||
* @alpha
|
||||
* @deprecated `createTestSchema` is deprecated and will be removed in 3.12.0.
|
||||
* Please migrate to [`@apollo/graphql-testing-library`](https://github.com/apollographql/graphql-testing-library).
|
||||
*/
|
||||
declare const createTestSchema: (schemaWithTypeDefs: GraphQLSchema, options: TestSchemaOptions) => ProxiedSchema;
|
||||
export { createTestSchema };
|
||||
//# sourceMappingURL=createTestSchema.d.ts.map
|
||||
112
node_modules/@apollo/client/testing/experimental/createTestSchema.js
generated
vendored
Normal file
112
node_modules/@apollo/client/testing/experimental/createTestSchema.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
import { __assign } from "tslib";
|
||||
import { addResolversToSchema } from "@graphql-tools/schema";
|
||||
import { mergeResolvers } from "@graphql-tools/merge";
|
||||
import { createMockSchema } from "./graphql-tools/utils.js";
|
||||
/**
|
||||
* A function that creates a [Proxy object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
|
||||
* around a given `schema` with `resolvers`. This proxied schema can be used to
|
||||
* progressively layer resolvers on top of the original schema using the `add`
|
||||
* method. The `fork` method can be used to create a new proxied schema which
|
||||
* can be modified independently of the original schema. `reset` will restore
|
||||
* resolvers to the original proxied schema.
|
||||
*
|
||||
* @param schema - A `GraphQLSchema`.
|
||||
* @param options - An `options` object that accepts `scalars` and `resolvers` objects.
|
||||
* @returns A `ProxiedSchema` with `add`, `fork` and `reset` methods.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const schema = createTestSchema(schemaWithTypeDefs, {
|
||||
* resolvers: {
|
||||
Query: {
|
||||
writer: () => ({
|
||||
name: "Ada Lovelace",
|
||||
}),
|
||||
}
|
||||
},
|
||||
scalars: {
|
||||
ID: () => "1",
|
||||
Int: () => 36,
|
||||
String: () => "String",
|
||||
Date: () => new Date("December 10, 1815 01:00:00").toJSON().split("T")[0],
|
||||
}
|
||||
});
|
||||
* ```
|
||||
* @since 3.9.0
|
||||
* @alpha
|
||||
* @deprecated `createTestSchema` is deprecated and will be removed in 3.12.0.
|
||||
* Please migrate to [`@apollo/graphql-testing-library`](https://github.com/apollographql/graphql-testing-library).
|
||||
*/
|
||||
var createTestSchema = function (schemaWithTypeDefs, options) {
|
||||
var _a;
|
||||
var targetResolvers = __assign({}, options.resolvers);
|
||||
var targetSchema = addResolversToSchema({
|
||||
schema: createMockSchema(schemaWithTypeDefs, (_a = options.scalars) !== null && _a !== void 0 ? _a : {}),
|
||||
resolvers: targetResolvers,
|
||||
});
|
||||
var fns = {
|
||||
add: function (_a) {
|
||||
var newResolvers = _a.resolvers;
|
||||
// @ts-ignore TODO(fixme): IResolvers type does not play well with our Resolvers
|
||||
targetResolvers = mergeResolvers([targetResolvers, newResolvers]);
|
||||
targetSchema = addResolversToSchema({
|
||||
schema: targetSchema,
|
||||
resolvers: targetResolvers,
|
||||
});
|
||||
return targetSchema;
|
||||
},
|
||||
fork: function (_a) {
|
||||
var _b;
|
||||
var _c = _a === void 0 ? {} : _a, newResolvers = _c.resolvers;
|
||||
return createTestSchema(targetSchema, {
|
||||
// @ts-ignore TODO(fixme): IResolvers type does not play well with our Resolvers
|
||||
resolvers: (_b = mergeResolvers([targetResolvers, newResolvers])) !== null && _b !== void 0 ? _b : targetResolvers,
|
||||
scalars: options.scalars,
|
||||
});
|
||||
},
|
||||
reset: function () {
|
||||
targetSchema = addResolversToSchema({
|
||||
schema: schemaWithTypeDefs,
|
||||
resolvers: options.resolvers,
|
||||
});
|
||||
},
|
||||
};
|
||||
var schema = new Proxy(targetSchema, {
|
||||
get: function (_target, p) {
|
||||
if (p in fns) {
|
||||
return Reflect.get(fns, p);
|
||||
}
|
||||
// An optimization that eliminates round-trips through the proxy
|
||||
// on class methods invoked via `this` on a base class instance wrapped by
|
||||
// the proxy.
|
||||
//
|
||||
// For example, consider the following class:
|
||||
//
|
||||
// class Base {
|
||||
// foo(){
|
||||
// this.bar()
|
||||
// }
|
||||
// bar(){
|
||||
// ...
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Calling `proxy.foo()` would call `foo` with `this` being the proxy.
|
||||
// This would result in calling `proxy.bar()` which would again invoke
|
||||
// the proxy to resolve `bar` and call that method.
|
||||
//
|
||||
// Instead, calls to `proxy.foo()` should result in a call to
|
||||
// `innerObject.foo()` with a `this` of `innerObject`, and that call
|
||||
// should directly call `innerObject.bar()`.
|
||||
var property = Reflect.get(targetSchema, p);
|
||||
if (typeof property === "function") {
|
||||
return property.bind(targetSchema);
|
||||
}
|
||||
return property;
|
||||
},
|
||||
});
|
||||
return schema;
|
||||
};
|
||||
export { createTestSchema };
|
||||
//# sourceMappingURL=createTestSchema.js.map
|
||||
1
node_modules/@apollo/client/testing/experimental/createTestSchema.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/experimental/createTestSchema.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
276
node_modules/@apollo/client/testing/experimental/experimental.cjs
generated
vendored
Normal file
276
node_modules/@apollo/client/testing/experimental/experimental.cjs
generated
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var tslib = require('tslib');
|
||||
var schema = require('@graphql-tools/schema');
|
||||
var merge = require('@graphql-tools/merge');
|
||||
var graphql = require('graphql');
|
||||
var utilities = require('../../utilities');
|
||||
var utils = require('@graphql-tools/utils');
|
||||
var core = require('../../core');
|
||||
|
||||
var takeRandom = function (arr) { return arr[Math.floor(Math.random() * arr.length)]; };
|
||||
var createMockSchema = function (staticSchema, mocks) {
|
||||
var _a;
|
||||
var getType = function (typeName) {
|
||||
var type = staticSchema.getType(typeName);
|
||||
if (!type || !(graphql.isObjectType(type) || graphql.isInterfaceType(type))) {
|
||||
throw new Error("".concat(typeName, " does not exist on schema or is not an object or interface"));
|
||||
}
|
||||
return type;
|
||||
};
|
||||
var getFieldType = function (typeName, fieldName) {
|
||||
if (fieldName === "__typename") {
|
||||
return graphql.GraphQLString;
|
||||
}
|
||||
var type = getType(typeName);
|
||||
var field = type.getFields()[fieldName];
|
||||
if (!field) {
|
||||
throw new Error("".concat(fieldName, " does not exist on type ").concat(typeName));
|
||||
}
|
||||
return field.type;
|
||||
};
|
||||
var generateValueFromType = function (fieldType) {
|
||||
var nullableType = graphql.getNullableType(fieldType);
|
||||
if (graphql.isScalarType(nullableType)) {
|
||||
var mockFn = mocks[nullableType.name];
|
||||
if (typeof mockFn !== "function") {
|
||||
throw new Error("No mock defined for type \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
return mockFn();
|
||||
}
|
||||
else if (graphql.isEnumType(nullableType)) {
|
||||
var mockFn = mocks[nullableType.name];
|
||||
if (typeof mockFn === "function")
|
||||
return mockFn();
|
||||
var values = nullableType.getValues().map(function (v) { return v.value; });
|
||||
return takeRandom(values);
|
||||
}
|
||||
else if (graphql.isObjectType(nullableType)) {
|
||||
return {};
|
||||
}
|
||||
else if (graphql.isListType(nullableType)) {
|
||||
return tslib.__spreadArray([], new Array(2), true).map(function () {
|
||||
return generateValueFromType(nullableType.ofType);
|
||||
});
|
||||
}
|
||||
else if (graphql.isAbstractType(nullableType)) {
|
||||
var mock = mocks[nullableType.name];
|
||||
var typeName = void 0;
|
||||
var values = {};
|
||||
if (!mock) {
|
||||
typeName = takeRandom(staticSchema.getPossibleTypes(nullableType).map(function (t) { return t.name; }));
|
||||
}
|
||||
else if (typeof mock === "function") {
|
||||
var mockRes = mock();
|
||||
if (mockRes === null)
|
||||
return null;
|
||||
if (!utilities.isNonNullObject(mockRes)) {
|
||||
throw new Error("Value returned by the mock for ".concat(nullableType.name, " is not an object or null"));
|
||||
}
|
||||
values = mockRes;
|
||||
if (typeof values["__typename"] !== "string") {
|
||||
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
typeName = values["__typename"];
|
||||
}
|
||||
else if (utilities.isNonNullObject(mock) &&
|
||||
typeof mock["__typename"] === "function") {
|
||||
var mockRes = mock["__typename"]();
|
||||
if (typeof mockRes !== "string") {
|
||||
throw new Error("'__typename' returned by the mock for abstract type ".concat(nullableType.name, " is not a string"));
|
||||
}
|
||||
typeName = mockRes;
|
||||
}
|
||||
else {
|
||||
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
else {
|
||||
throw new Error("".concat(nullableType, " not implemented"));
|
||||
}
|
||||
};
|
||||
var isRootType = function (type, schema) {
|
||||
var rootTypeNames = utils.getRootTypeNames(schema);
|
||||
return rootTypeNames.has(type.name);
|
||||
};
|
||||
var mockResolver = function (source, args, contex, info) {
|
||||
var defaultResolvedValue = graphql.defaultFieldResolver(source, args, contex, info);
|
||||
if (defaultResolvedValue !== undefined)
|
||||
return defaultResolvedValue;
|
||||
if (isRootType(info.parentType, info.schema)) {
|
||||
return {
|
||||
typeName: info.parentType.name,
|
||||
key: "ROOT",
|
||||
fieldName: info.fieldName,
|
||||
fieldArgs: args,
|
||||
};
|
||||
}
|
||||
if (defaultResolvedValue === undefined) {
|
||||
var fieldType = getFieldType(info.parentType.name, info.fieldName);
|
||||
return generateValueFromType(fieldType);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
return utils.mapSchema(staticSchema, (_a = {},
|
||||
_a[utils.MapperKind.OBJECT_FIELD] = function (fieldConfig) {
|
||||
var newFieldConfig = tslib.__assign({}, fieldConfig);
|
||||
var oldResolver = fieldConfig.resolve;
|
||||
if (!oldResolver) {
|
||||
newFieldConfig.resolve = mockResolver;
|
||||
}
|
||||
return newFieldConfig;
|
||||
},
|
||||
_a[utils.MapperKind.ABSTRACT_TYPE] = function (type) {
|
||||
if (type.resolveType != null && type.resolveType.length) {
|
||||
return;
|
||||
}
|
||||
var typeResolver = function (typename) {
|
||||
return typename;
|
||||
};
|
||||
if (graphql.isUnionType(type)) {
|
||||
return new graphql.GraphQLUnionType(tslib.__assign(tslib.__assign({}, type.toConfig()), { resolveType: typeResolver }));
|
||||
}
|
||||
else {
|
||||
return new graphql.GraphQLInterfaceType(tslib.__assign(tslib.__assign({}, type.toConfig()), { resolveType: typeResolver }));
|
||||
}
|
||||
},
|
||||
_a));
|
||||
};
|
||||
|
||||
var createTestSchema = function (schemaWithTypeDefs, options) {
|
||||
var _a;
|
||||
var targetResolvers = tslib.__assign({}, options.resolvers);
|
||||
var targetSchema = schema.addResolversToSchema({
|
||||
schema: createMockSchema(schemaWithTypeDefs, (_a = options.scalars) !== null && _a !== void 0 ? _a : {}),
|
||||
resolvers: targetResolvers,
|
||||
});
|
||||
var fns = {
|
||||
add: function (_a) {
|
||||
var newResolvers = _a.resolvers;
|
||||
targetResolvers = merge.mergeResolvers([targetResolvers, newResolvers]);
|
||||
targetSchema = schema.addResolversToSchema({
|
||||
schema: targetSchema,
|
||||
resolvers: targetResolvers,
|
||||
});
|
||||
return targetSchema;
|
||||
},
|
||||
fork: function (_a) {
|
||||
var _b;
|
||||
var _c = _a === void 0 ? {} : _a, newResolvers = _c.resolvers;
|
||||
return createTestSchema(targetSchema, {
|
||||
resolvers: (_b = merge.mergeResolvers([targetResolvers, newResolvers])) !== null && _b !== void 0 ? _b : targetResolvers,
|
||||
scalars: options.scalars,
|
||||
});
|
||||
},
|
||||
reset: function () {
|
||||
targetSchema = schema.addResolversToSchema({
|
||||
schema: schemaWithTypeDefs,
|
||||
resolvers: options.resolvers,
|
||||
});
|
||||
},
|
||||
};
|
||||
var schema$1 = new Proxy(targetSchema, {
|
||||
get: function (_target, p) {
|
||||
if (p in fns) {
|
||||
return Reflect.get(fns, p);
|
||||
}
|
||||
var property = Reflect.get(targetSchema, p);
|
||||
if (typeof property === "function") {
|
||||
return property.bind(targetSchema);
|
||||
}
|
||||
return property;
|
||||
},
|
||||
});
|
||||
return schema$1;
|
||||
};
|
||||
|
||||
function withCleanup(item, cleanup) {
|
||||
var _a;
|
||||
return tslib.__assign(tslib.__assign({}, item), (_a = {}, _a[Symbol.dispose] = function () {
|
||||
cleanup(item);
|
||||
if (Symbol.dispose in item) {
|
||||
item[Symbol.dispose]();
|
||||
}
|
||||
}, _a));
|
||||
}
|
||||
|
||||
function wait(ms) {
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib.__generator(this, function (_a) {
|
||||
return [2 , new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var createSchemaFetch = function (schema, mockFetchOpts) {
|
||||
var _a, _b, _c, _d;
|
||||
if (mockFetchOpts === void 0) { mockFetchOpts = { validate: true }; }
|
||||
var prevFetch = window.fetch;
|
||||
var delayMin = (_b = (_a = mockFetchOpts.delay) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : 3;
|
||||
var delayMax = (_d = (_c = mockFetchOpts.delay) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : delayMin + 2;
|
||||
if (delayMin > delayMax) {
|
||||
throw new Error("Please configure a minimum delay that is less than the maximum delay. The default minimum delay is 3ms.");
|
||||
}
|
||||
var mockFetch = function (_uri, options) { return tslib.__awaiter(void 0, void 0, void 0, function () {
|
||||
var randomDelay, body, document, validationErrors, result, stringifiedResult;
|
||||
return tslib.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!(delayMin > 0)) return [3 , 2];
|
||||
randomDelay = Math.random() * (delayMax - delayMin) + delayMin;
|
||||
return [4 , wait(randomDelay)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
body = JSON.parse(options.body);
|
||||
document = core.gql(body.query);
|
||||
if (mockFetchOpts.validate) {
|
||||
validationErrors = [];
|
||||
try {
|
||||
validationErrors = graphql.validate(schema, document);
|
||||
}
|
||||
catch (e) {
|
||||
validationErrors = [
|
||||
e instanceof Error ?
|
||||
graphql.GraphQLError.prototype.toJSON.apply(e)
|
||||
: e,
|
||||
];
|
||||
}
|
||||
if ((validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.length) > 0) {
|
||||
return [2 , new Response(JSON.stringify({ errors: validationErrors }))];
|
||||
}
|
||||
}
|
||||
return [4 , graphql.execute({
|
||||
schema: schema,
|
||||
document: document,
|
||||
variableValues: body.variables,
|
||||
operationName: body.operationName,
|
||||
})];
|
||||
case 3:
|
||||
result = _a.sent();
|
||||
stringifiedResult = JSON.stringify(result);
|
||||
return [2 , new Response(stringifiedResult)];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
function mockGlobal() {
|
||||
window.fetch = mockFetch;
|
||||
var restore = function () {
|
||||
if (window.fetch === mockFetch) {
|
||||
window.fetch = prevFetch;
|
||||
}
|
||||
};
|
||||
return withCleanup({ restore: restore }, restore);
|
||||
}
|
||||
return Object.assign(mockFetch, {
|
||||
mockGlobal: mockGlobal,
|
||||
});
|
||||
};
|
||||
|
||||
exports.createSchemaFetch = createSchemaFetch;
|
||||
exports.createTestSchema = createTestSchema;
|
||||
//# sourceMappingURL=experimental.cjs.map
|
||||
1
node_modules/@apollo/client/testing/experimental/experimental.cjs.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/experimental/experimental.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
276
node_modules/@apollo/client/testing/experimental/experimental.cjs.native.js
generated
vendored
Normal file
276
node_modules/@apollo/client/testing/experimental/experimental.cjs.native.js
generated
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var tslib = require('tslib');
|
||||
var schema = require('@graphql-tools/schema');
|
||||
var merge = require('@graphql-tools/merge');
|
||||
var graphql = require('graphql');
|
||||
var utilities = require('../../utilities');
|
||||
var utils = require('@graphql-tools/utils');
|
||||
var core = require('../../core');
|
||||
|
||||
var takeRandom = function (arr) { return arr[Math.floor(Math.random() * arr.length)]; };
|
||||
var createMockSchema = function (staticSchema, mocks) {
|
||||
var _a;
|
||||
var getType = function (typeName) {
|
||||
var type = staticSchema.getType(typeName);
|
||||
if (!type || !(graphql.isObjectType(type) || graphql.isInterfaceType(type))) {
|
||||
throw new Error("".concat(typeName, " does not exist on schema or is not an object or interface"));
|
||||
}
|
||||
return type;
|
||||
};
|
||||
var getFieldType = function (typeName, fieldName) {
|
||||
if (fieldName === "__typename") {
|
||||
return graphql.GraphQLString;
|
||||
}
|
||||
var type = getType(typeName);
|
||||
var field = type.getFields()[fieldName];
|
||||
if (!field) {
|
||||
throw new Error("".concat(fieldName, " does not exist on type ").concat(typeName));
|
||||
}
|
||||
return field.type;
|
||||
};
|
||||
var generateValueFromType = function (fieldType) {
|
||||
var nullableType = graphql.getNullableType(fieldType);
|
||||
if (graphql.isScalarType(nullableType)) {
|
||||
var mockFn = mocks[nullableType.name];
|
||||
if (typeof mockFn !== "function") {
|
||||
throw new Error("No mock defined for type \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
return mockFn();
|
||||
}
|
||||
else if (graphql.isEnumType(nullableType)) {
|
||||
var mockFn = mocks[nullableType.name];
|
||||
if (typeof mockFn === "function")
|
||||
return mockFn();
|
||||
var values = nullableType.getValues().map(function (v) { return v.value; });
|
||||
return takeRandom(values);
|
||||
}
|
||||
else if (graphql.isObjectType(nullableType)) {
|
||||
return {};
|
||||
}
|
||||
else if (graphql.isListType(nullableType)) {
|
||||
return tslib.__spreadArray([], new Array(2), true).map(function () {
|
||||
return generateValueFromType(nullableType.ofType);
|
||||
});
|
||||
}
|
||||
else if (graphql.isAbstractType(nullableType)) {
|
||||
var mock = mocks[nullableType.name];
|
||||
var typeName = void 0;
|
||||
var values = {};
|
||||
if (!mock) {
|
||||
typeName = takeRandom(staticSchema.getPossibleTypes(nullableType).map(function (t) { return t.name; }));
|
||||
}
|
||||
else if (typeof mock === "function") {
|
||||
var mockRes = mock();
|
||||
if (mockRes === null)
|
||||
return null;
|
||||
if (!utilities.isNonNullObject(mockRes)) {
|
||||
throw new Error("Value returned by the mock for ".concat(nullableType.name, " is not an object or null"));
|
||||
}
|
||||
values = mockRes;
|
||||
if (typeof values["__typename"] !== "string") {
|
||||
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
typeName = values["__typename"];
|
||||
}
|
||||
else if (utilities.isNonNullObject(mock) &&
|
||||
typeof mock["__typename"] === "function") {
|
||||
var mockRes = mock["__typename"]();
|
||||
if (typeof mockRes !== "string") {
|
||||
throw new Error("'__typename' returned by the mock for abstract type ".concat(nullableType.name, " is not a string"));
|
||||
}
|
||||
typeName = mockRes;
|
||||
}
|
||||
else {
|
||||
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
else {
|
||||
throw new Error("".concat(nullableType, " not implemented"));
|
||||
}
|
||||
};
|
||||
var isRootType = function (type, schema) {
|
||||
var rootTypeNames = utils.getRootTypeNames(schema);
|
||||
return rootTypeNames.has(type.name);
|
||||
};
|
||||
var mockResolver = function (source, args, contex, info) {
|
||||
var defaultResolvedValue = graphql.defaultFieldResolver(source, args, contex, info);
|
||||
if (defaultResolvedValue !== undefined)
|
||||
return defaultResolvedValue;
|
||||
if (isRootType(info.parentType, info.schema)) {
|
||||
return {
|
||||
typeName: info.parentType.name,
|
||||
key: "ROOT",
|
||||
fieldName: info.fieldName,
|
||||
fieldArgs: args,
|
||||
};
|
||||
}
|
||||
if (defaultResolvedValue === undefined) {
|
||||
var fieldType = getFieldType(info.parentType.name, info.fieldName);
|
||||
return generateValueFromType(fieldType);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
return utils.mapSchema(staticSchema, (_a = {},
|
||||
_a[utils.MapperKind.OBJECT_FIELD] = function (fieldConfig) {
|
||||
var newFieldConfig = tslib.__assign({}, fieldConfig);
|
||||
var oldResolver = fieldConfig.resolve;
|
||||
if (!oldResolver) {
|
||||
newFieldConfig.resolve = mockResolver;
|
||||
}
|
||||
return newFieldConfig;
|
||||
},
|
||||
_a[utils.MapperKind.ABSTRACT_TYPE] = function (type) {
|
||||
if (type.resolveType != null && type.resolveType.length) {
|
||||
return;
|
||||
}
|
||||
var typeResolver = function (typename) {
|
||||
return typename;
|
||||
};
|
||||
if (graphql.isUnionType(type)) {
|
||||
return new graphql.GraphQLUnionType(tslib.__assign(tslib.__assign({}, type.toConfig()), { resolveType: typeResolver }));
|
||||
}
|
||||
else {
|
||||
return new graphql.GraphQLInterfaceType(tslib.__assign(tslib.__assign({}, type.toConfig()), { resolveType: typeResolver }));
|
||||
}
|
||||
},
|
||||
_a));
|
||||
};
|
||||
|
||||
var createTestSchema = function (schemaWithTypeDefs, options) {
|
||||
var _a;
|
||||
var targetResolvers = tslib.__assign({}, options.resolvers);
|
||||
var targetSchema = schema.addResolversToSchema({
|
||||
schema: createMockSchema(schemaWithTypeDefs, (_a = options.scalars) !== null && _a !== void 0 ? _a : {}),
|
||||
resolvers: targetResolvers,
|
||||
});
|
||||
var fns = {
|
||||
add: function (_a) {
|
||||
var newResolvers = _a.resolvers;
|
||||
targetResolvers = merge.mergeResolvers([targetResolvers, newResolvers]);
|
||||
targetSchema = schema.addResolversToSchema({
|
||||
schema: targetSchema,
|
||||
resolvers: targetResolvers,
|
||||
});
|
||||
return targetSchema;
|
||||
},
|
||||
fork: function (_a) {
|
||||
var _b;
|
||||
var _c = _a === void 0 ? {} : _a, newResolvers = _c.resolvers;
|
||||
return createTestSchema(targetSchema, {
|
||||
resolvers: (_b = merge.mergeResolvers([targetResolvers, newResolvers])) !== null && _b !== void 0 ? _b : targetResolvers,
|
||||
scalars: options.scalars,
|
||||
});
|
||||
},
|
||||
reset: function () {
|
||||
targetSchema = schema.addResolversToSchema({
|
||||
schema: schemaWithTypeDefs,
|
||||
resolvers: options.resolvers,
|
||||
});
|
||||
},
|
||||
};
|
||||
var schema$1 = new Proxy(targetSchema, {
|
||||
get: function (_target, p) {
|
||||
if (p in fns) {
|
||||
return Reflect.get(fns, p);
|
||||
}
|
||||
var property = Reflect.get(targetSchema, p);
|
||||
if (typeof property === "function") {
|
||||
return property.bind(targetSchema);
|
||||
}
|
||||
return property;
|
||||
},
|
||||
});
|
||||
return schema$1;
|
||||
};
|
||||
|
||||
function withCleanup(item, cleanup) {
|
||||
var _a;
|
||||
return tslib.__assign(tslib.__assign({}, item), (_a = {}, _a[Symbol.dispose] = function () {
|
||||
cleanup(item);
|
||||
if (Symbol.dispose in item) {
|
||||
item[Symbol.dispose]();
|
||||
}
|
||||
}, _a));
|
||||
}
|
||||
|
||||
function wait(ms) {
|
||||
return tslib.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib.__generator(this, function (_a) {
|
||||
return [2 , new Promise(function (resolve) { return setTimeout(resolve, ms); })];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var createSchemaFetch = function (schema, mockFetchOpts) {
|
||||
var _a, _b, _c, _d;
|
||||
if (mockFetchOpts === void 0) { mockFetchOpts = { validate: true }; }
|
||||
var prevFetch = window.fetch;
|
||||
var delayMin = (_b = (_a = mockFetchOpts.delay) === null || _a === void 0 ? void 0 : _a.min) !== null && _b !== void 0 ? _b : 3;
|
||||
var delayMax = (_d = (_c = mockFetchOpts.delay) === null || _c === void 0 ? void 0 : _c.max) !== null && _d !== void 0 ? _d : delayMin + 2;
|
||||
if (delayMin > delayMax) {
|
||||
throw new Error("Please configure a minimum delay that is less than the maximum delay. The default minimum delay is 3ms.");
|
||||
}
|
||||
var mockFetch = function (_uri, options) { return tslib.__awaiter(void 0, void 0, void 0, function () {
|
||||
var randomDelay, body, document, validationErrors, result, stringifiedResult;
|
||||
return tslib.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!(delayMin > 0)) return [3 , 2];
|
||||
randomDelay = Math.random() * (delayMax - delayMin) + delayMin;
|
||||
return [4 , wait(randomDelay)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
body = JSON.parse(options.body);
|
||||
document = core.gql(body.query);
|
||||
if (mockFetchOpts.validate) {
|
||||
validationErrors = [];
|
||||
try {
|
||||
validationErrors = graphql.validate(schema, document);
|
||||
}
|
||||
catch (e) {
|
||||
validationErrors = [
|
||||
e instanceof Error ?
|
||||
graphql.GraphQLError.prototype.toJSON.apply(e)
|
||||
: e,
|
||||
];
|
||||
}
|
||||
if ((validationErrors === null || validationErrors === void 0 ? void 0 : validationErrors.length) > 0) {
|
||||
return [2 , new Response(JSON.stringify({ errors: validationErrors }))];
|
||||
}
|
||||
}
|
||||
return [4 , graphql.execute({
|
||||
schema: schema,
|
||||
document: document,
|
||||
variableValues: body.variables,
|
||||
operationName: body.operationName,
|
||||
})];
|
||||
case 3:
|
||||
result = _a.sent();
|
||||
stringifiedResult = JSON.stringify(result);
|
||||
return [2 , new Response(stringifiedResult)];
|
||||
}
|
||||
});
|
||||
}); };
|
||||
function mockGlobal() {
|
||||
window.fetch = mockFetch;
|
||||
var restore = function () {
|
||||
if (window.fetch === mockFetch) {
|
||||
window.fetch = prevFetch;
|
||||
}
|
||||
};
|
||||
return withCleanup({ restore: restore }, restore);
|
||||
}
|
||||
return Object.assign(mockFetch, {
|
||||
mockGlobal: mockGlobal,
|
||||
});
|
||||
};
|
||||
|
||||
exports.createSchemaFetch = createSchemaFetch;
|
||||
exports.createTestSchema = createTestSchema;
|
||||
//# sourceMappingURL=experimental.cjs.map
|
||||
1
node_modules/@apollo/client/testing/experimental/experimental.d.cts
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/experimental/experimental.d.cts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./index.d.ts";
|
||||
26
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.d.ts
generated
vendored
Normal file
26
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { GraphQLSchema } from "graphql";
|
||||
/**
|
||||
* A function that accepts a static `schema` and a `mocks` object for specifying
|
||||
* default scalar mocks and returns a `GraphQLSchema`.
|
||||
*
|
||||
* @param staticSchema - A static `GraphQLSchema`.
|
||||
* @param mocks - An object containing scalar mocks.
|
||||
* @returns A `GraphQLSchema` with scalar mocks.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const mockedSchema = createMockSchema(schema, {
|
||||
ID: () => "1",
|
||||
Int: () => 42,
|
||||
String: () => "String",
|
||||
Date: () => new Date("January 1, 2024 01:00:00").toJSON().split("T")[0],
|
||||
});
|
||||
* ```
|
||||
* @since 3.10.0
|
||||
* @alpha
|
||||
*/
|
||||
declare const createMockSchema: (staticSchema: GraphQLSchema, mocks: {
|
||||
[key: string]: any;
|
||||
}) => GraphQLSchema;
|
||||
export { createMockSchema };
|
||||
//# sourceMappingURL=utils.d.ts.map
|
||||
172
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.js
generated
vendored
Normal file
172
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.js
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
import { __assign, __spreadArray } from "tslib";
|
||||
import { GraphQLInterfaceType, GraphQLString, GraphQLUnionType, defaultFieldResolver, getNullableType, isAbstractType, isEnumType, isInterfaceType, isListType, isObjectType, isScalarType, isUnionType, } from "graphql";
|
||||
import { isNonNullObject } from "../../../utilities/index.js";
|
||||
import { MapperKind, mapSchema, getRootTypeNames } from "@graphql-tools/utils";
|
||||
// Taken from @graphql-tools/mock:
|
||||
// https://github.com/ardatan/graphql-tools/blob/4b56b04d69b02919f6c5fa4f97d33da63f36e8c8/packages/mock/src/utils.ts#L20
|
||||
var takeRandom = function (arr) { return arr[Math.floor(Math.random() * arr.length)]; };
|
||||
/**
|
||||
* A function that accepts a static `schema` and a `mocks` object for specifying
|
||||
* default scalar mocks and returns a `GraphQLSchema`.
|
||||
*
|
||||
* @param staticSchema - A static `GraphQLSchema`.
|
||||
* @param mocks - An object containing scalar mocks.
|
||||
* @returns A `GraphQLSchema` with scalar mocks.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* const mockedSchema = createMockSchema(schema, {
|
||||
ID: () => "1",
|
||||
Int: () => 42,
|
||||
String: () => "String",
|
||||
Date: () => new Date("January 1, 2024 01:00:00").toJSON().split("T")[0],
|
||||
});
|
||||
* ```
|
||||
* @since 3.10.0
|
||||
* @alpha
|
||||
*/
|
||||
var createMockSchema = function (staticSchema, mocks) {
|
||||
var _a;
|
||||
// Taken from @graphql-tools/mock:
|
||||
// https://github.com/ardatan/graphql-tools/blob/5ed60e44f94868f976cd28fe1b6a764fb146bbe9/packages/mock/src/MockStore.ts#L613
|
||||
var getType = function (typeName) {
|
||||
var type = staticSchema.getType(typeName);
|
||||
if (!type || !(isObjectType(type) || isInterfaceType(type))) {
|
||||
throw new Error("".concat(typeName, " does not exist on schema or is not an object or interface"));
|
||||
}
|
||||
return type;
|
||||
};
|
||||
// Taken from @graphql-tools/mock:
|
||||
// https://github.com/ardatan/graphql-tools/blob/5ed60e44f94868f976cd28fe1b6a764fb146bbe9/packages/mock/src/MockStore.ts#L597
|
||||
var getFieldType = function (typeName, fieldName) {
|
||||
if (fieldName === "__typename") {
|
||||
return GraphQLString;
|
||||
}
|
||||
var type = getType(typeName);
|
||||
var field = type.getFields()[fieldName];
|
||||
if (!field) {
|
||||
throw new Error("".concat(fieldName, " does not exist on type ").concat(typeName));
|
||||
}
|
||||
return field.type;
|
||||
};
|
||||
// Taken from @graphql-tools/mock:
|
||||
// https://github.com/ardatan/graphql-tools/blob/5ed60e44f94868f976cd28fe1b6a764fb146bbe9/packages/mock/src/MockStore.ts#L527
|
||||
var generateValueFromType = function (fieldType) {
|
||||
var nullableType = getNullableType(fieldType);
|
||||
if (isScalarType(nullableType)) {
|
||||
var mockFn = mocks[nullableType.name];
|
||||
if (typeof mockFn !== "function") {
|
||||
throw new Error("No mock defined for type \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
return mockFn();
|
||||
}
|
||||
else if (isEnumType(nullableType)) {
|
||||
var mockFn = mocks[nullableType.name];
|
||||
if (typeof mockFn === "function")
|
||||
return mockFn();
|
||||
var values = nullableType.getValues().map(function (v) { return v.value; });
|
||||
return takeRandom(values);
|
||||
}
|
||||
else if (isObjectType(nullableType)) {
|
||||
return {};
|
||||
}
|
||||
else if (isListType(nullableType)) {
|
||||
return __spreadArray([], new Array(2), true).map(function () {
|
||||
return generateValueFromType(nullableType.ofType);
|
||||
});
|
||||
}
|
||||
else if (isAbstractType(nullableType)) {
|
||||
var mock = mocks[nullableType.name];
|
||||
var typeName = void 0;
|
||||
var values = {};
|
||||
if (!mock) {
|
||||
typeName = takeRandom(staticSchema.getPossibleTypes(nullableType).map(function (t) { return t.name; }));
|
||||
}
|
||||
else if (typeof mock === "function") {
|
||||
var mockRes = mock();
|
||||
if (mockRes === null)
|
||||
return null;
|
||||
if (!isNonNullObject(mockRes)) {
|
||||
throw new Error("Value returned by the mock for ".concat(nullableType.name, " is not an object or null"));
|
||||
}
|
||||
values = mockRes;
|
||||
if (typeof values["__typename"] !== "string") {
|
||||
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
typeName = values["__typename"];
|
||||
}
|
||||
else if (isNonNullObject(mock) &&
|
||||
typeof mock["__typename"] === "function") {
|
||||
var mockRes = mock["__typename"]();
|
||||
if (typeof mockRes !== "string") {
|
||||
throw new Error("'__typename' returned by the mock for abstract type ".concat(nullableType.name, " is not a string"));
|
||||
}
|
||||
typeName = mockRes;
|
||||
}
|
||||
else {
|
||||
throw new Error("Please return a __typename in \"".concat(nullableType.name, "\""));
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
else {
|
||||
throw new Error("".concat(nullableType, " not implemented"));
|
||||
}
|
||||
};
|
||||
// Taken from @graphql-tools/mock:
|
||||
// https://github.com/ardatan/graphql-tools/blob/5ed60e44f94868f976cd28fe1b6a764fb146bbe9/packages/mock/src/utils.ts#L53
|
||||
var isRootType = function (type, schema) {
|
||||
var rootTypeNames = getRootTypeNames(schema);
|
||||
return rootTypeNames.has(type.name);
|
||||
};
|
||||
// Taken from @graphql-tools/mock:
|
||||
// https://github.com/ardatan/graphql-tools/blob/5ed60e44f94868f976cd28fe1b6a764fb146bbe9/packages/mock/src/addMocksToSchema.ts#L123
|
||||
var mockResolver = function (source, args, contex, info) {
|
||||
var defaultResolvedValue = defaultFieldResolver(source, args, contex, info);
|
||||
// priority to default resolved value
|
||||
if (defaultResolvedValue !== undefined)
|
||||
return defaultResolvedValue;
|
||||
// we have to handle the root mutation, root query and root subscription types
|
||||
// differently, because no resolver is called at the root
|
||||
if (isRootType(info.parentType, info.schema)) {
|
||||
return {
|
||||
typeName: info.parentType.name,
|
||||
key: "ROOT",
|
||||
fieldName: info.fieldName,
|
||||
fieldArgs: args,
|
||||
};
|
||||
}
|
||||
if (defaultResolvedValue === undefined) {
|
||||
var fieldType = getFieldType(info.parentType.name, info.fieldName);
|
||||
return generateValueFromType(fieldType);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
// Taken from @graphql-tools/mock:
|
||||
// https://github.com/ardatan/graphql-tools/blob/5ed60e44f94868f976cd28fe1b6a764fb146bbe9/packages/mock/src/addMocksToSchema.ts#L176
|
||||
return mapSchema(staticSchema, (_a = {},
|
||||
_a[MapperKind.OBJECT_FIELD] = function (fieldConfig) {
|
||||
var newFieldConfig = __assign({}, fieldConfig);
|
||||
var oldResolver = fieldConfig.resolve;
|
||||
if (!oldResolver) {
|
||||
newFieldConfig.resolve = mockResolver;
|
||||
}
|
||||
return newFieldConfig;
|
||||
},
|
||||
_a[MapperKind.ABSTRACT_TYPE] = function (type) {
|
||||
if (type.resolveType != null && type.resolveType.length) {
|
||||
return;
|
||||
}
|
||||
var typeResolver = function (typename) {
|
||||
return typename;
|
||||
};
|
||||
if (isUnionType(type)) {
|
||||
return new GraphQLUnionType(__assign(__assign({}, type.toConfig()), { resolveType: typeResolver }));
|
||||
}
|
||||
else {
|
||||
return new GraphQLInterfaceType(__assign(__assign({}, type.toConfig()), { resolveType: typeResolver }));
|
||||
}
|
||||
},
|
||||
_a));
|
||||
};
|
||||
export { createMockSchema };
|
||||
//# sourceMappingURL=utils.js.map
|
||||
1
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.test.d.ts
generated
vendored
Normal file
2
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.test.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=utils.test.d.ts.map
|
||||
139
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.test.js
generated
vendored
Normal file
139
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.test.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
// Originally from @graphql-tools/mock
|
||||
// https://github.com/ardatan/graphql-tools/blob/4b56b04d69b02919f6c5fa4f97d33da63f36e8c8/packages/mock/tests/addMocksToSchema.spec.ts
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
import { buildSchema, graphql } from "graphql";
|
||||
import { createMockSchema } from "./utils.js";
|
||||
var mockDate = new Date().toJSON().split("T")[0];
|
||||
var mocks = {
|
||||
Int: function () { return 6; },
|
||||
Float: function () { return 22.1; },
|
||||
String: function () { return "string"; },
|
||||
ID: function () { return "id"; },
|
||||
Date: function () { return mockDate; },
|
||||
};
|
||||
var typeDefs = /* GraphQL */ "\n type User {\n id: ID!\n age: Int!\n name: String!\n image: UserImage!\n book: Book!\n }\n\n type Author {\n _id: ID!\n name: String!\n book: Book!\n }\n\n union UserImage = UserImageSolidColor | UserImageURL\n\n type UserImageSolidColor {\n color: String!\n }\n\n type UserImageURL {\n url: String!\n }\n\n scalar Date\n\n interface Book {\n id: ID!\n title: String\n publishedAt: Date\n }\n\n type TextBook implements Book {\n id: ID!\n title: String\n publishedAt: Date\n text: String\n }\n\n type ColoringBook implements Book {\n id: ID!\n title: String\n publishedAt: Date\n colors: [String]\n }\n\n type Query {\n viewer: User!\n userById(id: ID!): User!\n author: Author!\n }\n\n type Mutation {\n changeViewerName(newName: String!): User!\n }\n";
|
||||
var schema = buildSchema(typeDefs);
|
||||
describe("addMocksToSchema", function () {
|
||||
it("basic", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var query, mockedSchema, _a, data, errors, viewerData, data2, viewerData2;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
query = "\n query {\n viewer {\n id\n name\n age\n }\n }\n ";
|
||||
mockedSchema = createMockSchema(schema, mocks);
|
||||
return [4 /*yield*/, graphql({
|
||||
schema: mockedSchema,
|
||||
source: query,
|
||||
})];
|
||||
case 1:
|
||||
_a = _b.sent(), data = _a.data, errors = _a.errors;
|
||||
expect(errors).not.toBeDefined();
|
||||
expect(data).toBeDefined();
|
||||
viewerData = data === null || data === void 0 ? void 0 : data["viewer"];
|
||||
expect(typeof viewerData["id"]).toBe("string");
|
||||
expect(typeof viewerData["name"]).toBe("string");
|
||||
expect(typeof viewerData["age"]).toBe("number");
|
||||
return [4 /*yield*/, graphql({
|
||||
schema: mockedSchema,
|
||||
source: query,
|
||||
})];
|
||||
case 2:
|
||||
data2 = (_b.sent()).data;
|
||||
viewerData2 = data2 === null || data2 === void 0 ? void 0 : data2["viewer"];
|
||||
expect(viewerData2["id"]).toEqual(viewerData["id"]);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("handle _id key field", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var query, mockedSchema, _a, data, errors, viewerData, data2, viewerData2;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
query = "\n query {\n author {\n _id\n name\n }\n }\n ";
|
||||
mockedSchema = createMockSchema(schema, mocks);
|
||||
return [4 /*yield*/, graphql({
|
||||
schema: mockedSchema,
|
||||
source: query,
|
||||
})];
|
||||
case 1:
|
||||
_a = _b.sent(), data = _a.data, errors = _a.errors;
|
||||
expect(errors).not.toBeDefined();
|
||||
expect(data).toBeDefined();
|
||||
viewerData = data === null || data === void 0 ? void 0 : data["author"];
|
||||
expect(typeof viewerData["_id"]).toBe("string");
|
||||
expect(typeof viewerData["name"]).toBe("string");
|
||||
return [4 /*yield*/, graphql({
|
||||
schema: mockedSchema,
|
||||
source: query,
|
||||
})];
|
||||
case 2:
|
||||
data2 = (_b.sent()).data;
|
||||
viewerData2 = data2 === null || data2 === void 0 ? void 0 : data2["author"];
|
||||
expect(viewerData2["_id"]).toEqual(viewerData["_id"]);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should handle union type", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var query, mockedSchema, _a, data, errors;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
query = "\n query {\n viewer {\n image {\n __typename\n ... on UserImageURL {\n url\n }\n ... on UserImageSolidColor {\n color\n }\n }\n }\n }\n ";
|
||||
mockedSchema = createMockSchema(schema, mocks);
|
||||
return [4 /*yield*/, graphql({
|
||||
schema: mockedSchema,
|
||||
source: query,
|
||||
})];
|
||||
case 1:
|
||||
_a = _b.sent(), data = _a.data, errors = _a.errors;
|
||||
expect(errors).not.toBeDefined();
|
||||
expect(data).toBeDefined();
|
||||
expect(data["viewer"]["image"]["__typename"]).toBeDefined();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should handle interface type", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var query, mockedSchema, _a, data, errors;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
query = "\n query {\n viewer {\n book {\n title\n __typename\n ... on TextBook {\n text\n }\n ... on ColoringBook {\n colors\n }\n }\n }\n }\n ";
|
||||
mockedSchema = createMockSchema(schema, mocks);
|
||||
return [4 /*yield*/, graphql({
|
||||
schema: mockedSchema,
|
||||
source: query,
|
||||
})];
|
||||
case 1:
|
||||
_a = _b.sent(), data = _a.data, errors = _a.errors;
|
||||
expect(errors).not.toBeDefined();
|
||||
expect(data).toBeDefined();
|
||||
expect(data["viewer"]["book"]["__typename"]).toBeDefined();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should handle custom scalars", function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var query, mockedSchema, _a, data, errors;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
query = "\n query {\n viewer {\n book {\n title\n publishedAt\n }\n }\n }\n ";
|
||||
mockedSchema = createMockSchema(schema, mocks);
|
||||
return [4 /*yield*/, graphql({
|
||||
schema: mockedSchema,
|
||||
source: query,
|
||||
})];
|
||||
case 1:
|
||||
_a = _b.sent(), data = _a.data, errors = _a.errors;
|
||||
expect(errors).not.toBeDefined();
|
||||
expect(data).toBeDefined();
|
||||
expect(data["viewer"]["book"]["publishedAt"]).toBe(mockDate);
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
});
|
||||
//# sourceMappingURL=utils.test.js.map
|
||||
1
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.test.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/experimental/graphql-tools/utils.test.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
3
node_modules/@apollo/client/testing/experimental/index.d.ts
generated
vendored
Normal file
3
node_modules/@apollo/client/testing/experimental/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export { createTestSchema } from "./createTestSchema.js";
|
||||
export { createSchemaFetch } from "./createSchemaFetch.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
3
node_modules/@apollo/client/testing/experimental/index.js
generated
vendored
Normal file
3
node_modules/@apollo/client/testing/experimental/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export { createTestSchema } from "./createTestSchema.js";
|
||||
export { createSchemaFetch } from "./createSchemaFetch.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/client/testing/experimental/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/experimental/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/experimental/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { createTestSchema } from \"./createTestSchema.js\";\nexport { createSchemaFetch } from \"./createSchemaFetch.js\";\n"]}
|
||||
8
node_modules/@apollo/client/testing/experimental/package.json
generated
vendored
Normal file
8
node_modules/@apollo/client/testing/experimental/package.json
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@apollo/client/testing/experimental",
|
||||
"type": "module",
|
||||
"main": "experimental.cjs",
|
||||
"module": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"sideEffects": false
|
||||
}
|
||||
5
node_modules/@apollo/client/testing/index.d.ts
generated
vendored
Normal file
5
node_modules/@apollo/client/testing/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import "../utilities/globals/index.js";
|
||||
export type { MockedProviderProps } from "./react/MockedProvider.js";
|
||||
export { MockedProvider } from "./react/MockedProvider.js";
|
||||
export * from "./core/index.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
4
node_modules/@apollo/client/testing/index.js
generated
vendored
Normal file
4
node_modules/@apollo/client/testing/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import "../utilities/globals/index.js";
|
||||
export { MockedProvider } from "./react/MockedProvider.js";
|
||||
export * from "./core/index.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/client/testing/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,+BAA+B,CAAC;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,cAAc,iBAAiB,CAAC","sourcesContent":["import \"../utilities/globals/index.js\";\nexport type { MockedProviderProps } from \"./react/MockedProvider.js\";\nexport { MockedProvider } from \"./react/MockedProvider.js\";\nexport * from \"./core/index.js\";\n"]}
|
||||
28
node_modules/@apollo/client/testing/internal/ObservableStream.d.ts
generated
vendored
Normal file
28
node_modules/@apollo/client/testing/internal/ObservableStream.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { Observable } from "../../utilities/index.js";
|
||||
export interface TakeOptions {
|
||||
timeout?: number;
|
||||
}
|
||||
type ObservableEvent<T> = {
|
||||
type: "next";
|
||||
value: T;
|
||||
} | {
|
||||
type: "error";
|
||||
error: any;
|
||||
} | {
|
||||
type: "complete";
|
||||
};
|
||||
export declare class ObservableStream<T> {
|
||||
private reader;
|
||||
private subscription;
|
||||
private readerQueue;
|
||||
constructor(observable: Observable<T>);
|
||||
peek({ timeout }?: TakeOptions): Promise<ObservableEvent<T>>;
|
||||
take({ timeout }?: TakeOptions): Promise<ObservableEvent<T>>;
|
||||
unsubscribe(): void;
|
||||
takeNext(options?: TakeOptions): Promise<T>;
|
||||
takeError(options?: TakeOptions): Promise<any>;
|
||||
takeComplete(options?: TakeOptions): Promise<void>;
|
||||
private readNextValue;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=ObservableStream.d.ts.map
|
||||
123
node_modules/@apollo/client/testing/internal/ObservableStream.js
generated
vendored
Normal file
123
node_modules/@apollo/client/testing/internal/ObservableStream.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
import { __awaiter, __generator, __spreadArray } from "tslib";
|
||||
import { equals, iterableEquality } from "@jest/expect-utils";
|
||||
import { expect } from "@jest/globals";
|
||||
import * as matcherUtils from "jest-matcher-utils";
|
||||
import { ReadableStream } from "node:stream/web";
|
||||
var ObservableStream = /** @class */ (function () {
|
||||
function ObservableStream(observable) {
|
||||
var _this = this;
|
||||
this.readerQueue = [];
|
||||
this.reader = new ReadableStream({
|
||||
start: function (controller) {
|
||||
_this.subscription = observable.subscribe(function (value) { return controller.enqueue({ type: "next", value: value }); }, function (error) { return controller.enqueue({ type: "error", error: error }); }, function () { return controller.enqueue({ type: "complete" }); });
|
||||
},
|
||||
}).getReader();
|
||||
}
|
||||
ObservableStream.prototype.peek = function (_a) {
|
||||
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 100 : _c;
|
||||
// Calling `peek` multiple times in a row should not advance the reader
|
||||
// multiple times until this value has been consumed.
|
||||
var readerPromise = this.readerQueue[0];
|
||||
if (!readerPromise) {
|
||||
// Since this.reader.read() advances the reader in the stream, we don't
|
||||
// want to consume this promise entirely, otherwise we will miss it when
|
||||
// calling `take`. Instead, we push it into a queue that can be consumed
|
||||
// by `take` the next time its called so that we avoid advancing the
|
||||
// reader until we are finished processing all peeked values.
|
||||
readerPromise = this.readNextValue();
|
||||
this.readerQueue.push(readerPromise);
|
||||
}
|
||||
return Promise.race([
|
||||
readerPromise,
|
||||
new Promise(function (_, reject) {
|
||||
setTimeout(reject, timeout, new Error("Timeout waiting for next event"));
|
||||
}),
|
||||
]);
|
||||
};
|
||||
ObservableStream.prototype.take = function (_a) {
|
||||
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 100 : _c;
|
||||
return Promise.race([
|
||||
this.readerQueue.shift() || this.readNextValue(),
|
||||
new Promise(function (_, reject) {
|
||||
setTimeout(reject, timeout, new Error("Timeout waiting for next event"));
|
||||
}),
|
||||
]);
|
||||
};
|
||||
ObservableStream.prototype.unsubscribe = function () {
|
||||
this.subscription.unsubscribe();
|
||||
};
|
||||
ObservableStream.prototype.takeNext = function (options) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var event;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.take(options)];
|
||||
case 1:
|
||||
event = _a.sent();
|
||||
validateEquals(event, { type: "next", value: expect.anything() });
|
||||
return [2 /*return*/, event.value];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
ObservableStream.prototype.takeError = function (options) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var event;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.take(options)];
|
||||
case 1:
|
||||
event = _a.sent();
|
||||
validateEquals(event, { type: "error", error: expect.anything() });
|
||||
return [2 /*return*/, event.error];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
ObservableStream.prototype.takeComplete = function (options) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var event;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.take(options)];
|
||||
case 1:
|
||||
event = _a.sent();
|
||||
validateEquals(event, { type: "complete" });
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
ObservableStream.prototype.readNextValue = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.reader.read().then(function (result) { return result.value; })];
|
||||
});
|
||||
});
|
||||
};
|
||||
return ObservableStream;
|
||||
}());
|
||||
export { ObservableStream };
|
||||
// Lightweight expect(...).toEqual(...) check that avoids using `expect` so that
|
||||
// `expect.assertions(num)` does not double count assertions when using the take*
|
||||
// functions inside of expect(stream).toEmit* matchers.
|
||||
function validateEquals(actualEvent, expectedEvent) {
|
||||
// Uses the same matchers as expect(...).toEqual(...)
|
||||
// https://github.com/jestjs/jest/blob/611d1a4ba0008d67b5dcda485177f0813b2b573e/packages/expect/src/matchers.ts#L626-L629
|
||||
var isEqual = equals(actualEvent, expectedEvent, __spreadArray(__spreadArray([], getCustomMatchers(), true), [
|
||||
iterableEquality,
|
||||
], false));
|
||||
if (isEqual) {
|
||||
return;
|
||||
}
|
||||
var hint = matcherUtils.matcherHint("toEqual", "stream", "expected");
|
||||
throw new Error(hint +
|
||||
"\n\n" +
|
||||
matcherUtils.printDiffOrStringify(expectedEvent, actualEvent, "Expected", "Received", true));
|
||||
}
|
||||
function getCustomMatchers() {
|
||||
// https://github.com/jestjs/jest/blob/611d1a4ba0008d67b5dcda485177f0813b2b573e/packages/expect/src/jestMatchersObject.ts#L141-L143
|
||||
var JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
|
||||
return globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters;
|
||||
}
|
||||
//# sourceMappingURL=ObservableStream.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/ObservableStream.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/ObservableStream.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
7
node_modules/@apollo/client/testing/internal/disposables/enableFakeTimers.d.ts
generated
vendored
Normal file
7
node_modules/@apollo/client/testing/internal/disposables/enableFakeTimers.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
declare global {
|
||||
interface DateConstructor {
|
||||
isFake: boolean;
|
||||
}
|
||||
}
|
||||
export declare function enableFakeTimers(config?: FakeTimersConfig | LegacyFakeTimersConfig): Disposable;
|
||||
//# sourceMappingURL=enableFakeTimers.d.ts.map
|
||||
16
node_modules/@apollo/client/testing/internal/disposables/enableFakeTimers.js
generated
vendored
Normal file
16
node_modules/@apollo/client/testing/internal/disposables/enableFakeTimers.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { withCleanup } from "./withCleanup.js";
|
||||
export function enableFakeTimers(config) {
|
||||
if (global.Date.isFake === true) {
|
||||
// Nothing to do here, fake timers have already been set up.
|
||||
// That also means we don't want to clean that up later.
|
||||
return withCleanup({}, function () { });
|
||||
}
|
||||
jest.useFakeTimers(config);
|
||||
return withCleanup({}, function () {
|
||||
if (global.Date.isFake === true) {
|
||||
jest.runOnlyPendingTimers();
|
||||
jest.useRealTimers();
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=enableFakeTimers.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/disposables/enableFakeTimers.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/disposables/enableFakeTimers.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"enableFakeTimers.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/enableFakeTimers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAS/C,MAAM,UAAU,gBAAgB,CAC9B,MAAkD;IAElD,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAChC,4DAA4D;QAC5D,wDAAwD;QACxD,OAAO,WAAW,CAAC,EAAE,EAAE,cAAO,CAAC,CAAC,CAAC;IACnC,CAAC;IAED,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3B,OAAO,WAAW,CAAC,EAAE,EAAE;QACrB,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { withCleanup } from \"./withCleanup.js\";\n\ndeclare global {\n interface DateConstructor {\n /* Jest uses @sinonjs/fake-timers, that add this flag */\n isFake: boolean;\n }\n}\n\nexport function enableFakeTimers(\n config?: FakeTimersConfig | LegacyFakeTimersConfig\n) {\n if (global.Date.isFake === true) {\n // Nothing to do here, fake timers have already been set up.\n // That also means we don't want to clean that up later.\n return withCleanup({}, () => {});\n }\n\n jest.useFakeTimers(config);\n return withCleanup({}, () => {\n if (global.Date.isFake === true) {\n jest.runOnlyPendingTimers();\n jest.useRealTimers();\n }\n });\n}\n"]}
|
||||
5
node_modules/@apollo/client/testing/internal/disposables/index.d.ts
generated
vendored
Normal file
5
node_modules/@apollo/client/testing/internal/disposables/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export { spyOnConsole } from "./spyOnConsole.js";
|
||||
export { withCleanup } from "./withCleanup.js";
|
||||
export { enableFakeTimers } from "./enableFakeTimers.js";
|
||||
export { withProdMode } from "./withProdMode.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
5
node_modules/@apollo/client/testing/internal/disposables/index.js
generated
vendored
Normal file
5
node_modules/@apollo/client/testing/internal/disposables/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export { spyOnConsole } from "./spyOnConsole.js";
|
||||
export { withCleanup } from "./withCleanup.js";
|
||||
export { enableFakeTimers } from "./enableFakeTimers.js";
|
||||
export { withProdMode } from "./withProdMode.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/disposables/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/disposables/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { spyOnConsole } from \"./spyOnConsole.js\";\nexport { withCleanup } from \"./withCleanup.js\";\nexport { enableFakeTimers } from \"./enableFakeTimers.js\";\nexport { withProdMode } from \"./withProdMode.js\";\n"]}
|
||||
9
node_modules/@apollo/client/testing/internal/disposables/spyOnConsole.d.ts
generated
vendored
Normal file
9
node_modules/@apollo/client/testing/internal/disposables/spyOnConsole.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
type ConsoleMethod = "log" | "info" | "warn" | "error" | "debug";
|
||||
type Spies<Keys extends ConsoleMethod[]> = Record<Keys[number], jest.SpyInstance<void, any[], any>>;
|
||||
/** @internal */
|
||||
export declare function spyOnConsole<Keys extends ConsoleMethod[]>(...spyOn: Keys): Spies<Keys> & Disposable;
|
||||
export declare namespace spyOnConsole {
|
||||
var takeSnapshots: <Keys extends ConsoleMethod[]>(...spyOn: Keys) => Spies<Keys> & Disposable;
|
||||
}
|
||||
export {};
|
||||
//# sourceMappingURL=spyOnConsole.d.ts.map
|
||||
35
node_modules/@apollo/client/testing/internal/disposables/spyOnConsole.js
generated
vendored
Normal file
35
node_modules/@apollo/client/testing/internal/disposables/spyOnConsole.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import { withCleanup } from "./withCleanup.js";
|
||||
var noOp = function () { };
|
||||
var restore = function (spy) { return spy.mockRestore(); };
|
||||
/** @internal */
|
||||
export function spyOnConsole() {
|
||||
var spyOn = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
spyOn[_i] = arguments[_i];
|
||||
}
|
||||
var spies = {};
|
||||
for (var _a = 0, spyOn_1 = spyOn; _a < spyOn_1.length; _a++) {
|
||||
var key = spyOn_1[_a];
|
||||
// @ts-ignore
|
||||
spies[key] = jest.spyOn(console, key).mockImplementation(noOp);
|
||||
}
|
||||
return withCleanup(spies, function (spies) {
|
||||
for (var _i = 0, _a = Object.values(spies); _i < _a.length; _i++) {
|
||||
var spy = _a[_i];
|
||||
restore(spy);
|
||||
}
|
||||
});
|
||||
}
|
||||
spyOnConsole.takeSnapshots = function () {
|
||||
var spyOn = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
spyOn[_i] = arguments[_i];
|
||||
}
|
||||
return withCleanup(spyOnConsole.apply(void 0, spyOn), function (spies) {
|
||||
for (var _i = 0, _a = Object.values(spies); _i < _a.length; _i++) {
|
||||
var spy = _a[_i];
|
||||
expect(spy).toMatchSnapshot();
|
||||
}
|
||||
});
|
||||
};
|
||||
//# sourceMappingURL=spyOnConsole.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/disposables/spyOnConsole.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/disposables/spyOnConsole.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"spyOnConsole.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/spyOnConsole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,IAAM,IAAI,GAAG,cAAO,CAAC,CAAC;AACtB,IAAM,OAAO,GAAG,UAAC,GAAqB,IAAK,OAAA,GAAG,CAAC,WAAW,EAAE,EAAjB,CAAiB,CAAC;AAS7D,gBAAgB;AAChB,MAAM,UAAU,YAAY;IAC1B,eAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,0BAAc;;IAEd,IAAM,KAAK,GAAG,EAAiB,CAAC;IAChC,KAAkB,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAE,CAAC;QAArB,IAAM,GAAG,cAAA;QACZ,aAAa;QACb,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,EAAE,UAAC,KAAK;QAC9B,KAAkB,UAA0C,EAA1C,KAAA,MAAM,CAAC,MAAM,CAAC,KAAK,CAAuB,EAA1C,cAA0C,EAA1C,IAA0C,EAAE,CAAC;YAA1D,IAAM,GAAG,SAAA;YACZ,OAAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,YAAY,CAAC,aAAa,GAAG;IAC3B,eAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,0BAAc;;IAEd,OAAA,WAAW,CAAC,YAAY,eAAI,KAAK,GAAG,UAAC,KAAK;QACxC,KAAkB,UAA0C,EAA1C,KAAA,MAAM,CAAC,MAAM,CAAC,KAAK,CAAuB,EAA1C,cAA0C,EAA1C,IAA0C,EAAE,CAAC;YAA1D,IAAM,GAAG,SAAA;YACZ,MAAM,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,CAAC;QAChC,CAAC;IACH,CAAC,CAAC;AAJF,CAIE,CAAC","sourcesContent":["import { withCleanup } from \"./withCleanup.js\";\n\nconst noOp = () => {};\nconst restore = (spy: jest.SpyInstance) => spy.mockRestore();\n\ntype ConsoleMethod = \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\";\n\ntype Spies<Keys extends ConsoleMethod[]> = Record<\n Keys[number],\n jest.SpyInstance<void, any[], any>\n>;\n\n/** @internal */\nexport function spyOnConsole<Keys extends ConsoleMethod[]>(\n ...spyOn: Keys\n): Spies<Keys> & Disposable {\n const spies = {} as Spies<Keys>;\n for (const key of spyOn) {\n // @ts-ignore\n spies[key] = jest.spyOn(console, key).mockImplementation(noOp);\n }\n return withCleanup(spies, (spies) => {\n for (const spy of Object.values(spies) as jest.SpyInstance[]) {\n restore(spy);\n }\n });\n}\n\nspyOnConsole.takeSnapshots = <Keys extends ConsoleMethod[]>(\n ...spyOn: Keys\n): Spies<Keys> & Disposable =>\n withCleanup(spyOnConsole(...spyOn), (spies) => {\n for (const spy of Object.values(spies) as jest.SpyInstance[]) {\n expect(spy).toMatchSnapshot();\n }\n });\n"]}
|
||||
3
node_modules/@apollo/client/testing/internal/disposables/withCleanup.d.ts
generated
vendored
Normal file
3
node_modules/@apollo/client/testing/internal/disposables/withCleanup.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/** @internal */
|
||||
export declare function withCleanup<T extends object>(item: T, cleanup: (item: T) => void): T & Disposable;
|
||||
//# sourceMappingURL=withCleanup.d.ts.map
|
||||
14
node_modules/@apollo/client/testing/internal/disposables/withCleanup.js
generated
vendored
Normal file
14
node_modules/@apollo/client/testing/internal/disposables/withCleanup.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { __assign } from "tslib";
|
||||
/** @internal */
|
||||
export function withCleanup(item, cleanup) {
|
||||
var _a;
|
||||
return __assign(__assign({}, item), (_a = {}, _a[Symbol.dispose] = function () {
|
||||
cleanup(item);
|
||||
// if `item` already has a cleanup function, we also need to call the original cleanup function
|
||||
// (e.g. if something is wrapped in `withCleanup` twice)
|
||||
if (Symbol.dispose in item) {
|
||||
item[Symbol.dispose]();
|
||||
}
|
||||
}, _a));
|
||||
}
|
||||
//# sourceMappingURL=withCleanup.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/disposables/withCleanup.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/disposables/withCleanup.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"withCleanup.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/withCleanup.ts"],"names":[],"mappings":";AAAA,gBAAgB;AAChB,MAAM,UAAU,WAAW,CACzB,IAAO,EACP,OAA0B;;IAE1B,6BACK,IAAI,aACP,GAAC,MAAM,CAAC,OAAO,IAAf;QACE,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,+FAA+F;QAC/F,wDAAwD;QACxD,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAC1B,IAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,CAAC;IACH,CAAC,OACD;AACJ,CAAC","sourcesContent":["/** @internal */\nexport function withCleanup<T extends object>(\n item: T,\n cleanup: (item: T) => void\n): T & Disposable {\n return {\n ...item,\n [Symbol.dispose]() {\n cleanup(item);\n // if `item` already has a cleanup function, we also need to call the original cleanup function\n // (e.g. if something is wrapped in `withCleanup` twice)\n if (Symbol.dispose in item) {\n (item as Disposable)[Symbol.dispose]();\n }\n },\n };\n}\n"]}
|
||||
4
node_modules/@apollo/client/testing/internal/disposables/withProdMode.d.ts
generated
vendored
Normal file
4
node_modules/@apollo/client/testing/internal/disposables/withProdMode.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export declare function withProdMode(): {
|
||||
prevDEV: boolean;
|
||||
} & Disposable;
|
||||
//# sourceMappingURL=withProdMode.d.ts.map
|
||||
10
node_modules/@apollo/client/testing/internal/disposables/withProdMode.js
generated
vendored
Normal file
10
node_modules/@apollo/client/testing/internal/disposables/withProdMode.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { withCleanup } from "./withCleanup.js";
|
||||
export function withProdMode() {
|
||||
var prev = { prevDEV: globalThis.__DEV__ !== false };
|
||||
Object.defineProperty(globalThis, "__DEV__", { value: false });
|
||||
return withCleanup(prev, function (_a) {
|
||||
var prevDEV = _a.prevDEV;
|
||||
Object.defineProperty(globalThis, "__DEV__", { value: prevDEV });
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=withProdMode.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/disposables/withProdMode.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/disposables/withProdMode.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"withProdMode.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/withProdMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,UAAU,YAAY;IAC1B,IAAM,IAAI,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAClC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAE/D,OAAO,WAAW,CAAC,IAAI,EAAE,UAAC,EAAW;YAAT,OAAO,aAAA;QACjC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { withCleanup } from \"./withCleanup.js\";\n\nexport function withProdMode() {\n const prev = { prevDEV: __DEV__ };\n Object.defineProperty(globalThis, \"__DEV__\", { value: false });\n\n return withCleanup(prev, ({ prevDEV }) => {\n Object.defineProperty(globalThis, \"__DEV__\", { value: prevDEV });\n });\n}\n"]}
|
||||
23
node_modules/@apollo/client/testing/internal/incremental.d.ts
generated
vendored
Normal file
23
node_modules/@apollo/client/testing/internal/incremental.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { HttpLink } from "../../link/http/index.js";
|
||||
import type { GraphQLFormattedError, InitialIncrementalExecutionResult, SubsequentIncrementalExecutionResult } from "graphql-17-alpha2";
|
||||
import type { ApolloPayloadResult } from "../../core/index.js";
|
||||
export declare function mockIncrementalStream<Chunks>({ responseHeaders, }: {
|
||||
responseHeaders: Headers;
|
||||
}): {
|
||||
httpLink: HttpLink;
|
||||
enqueue: (chunk: Chunks, hasNext: boolean) => void;
|
||||
close: () => void;
|
||||
};
|
||||
export declare function mockDeferStream<TData = Record<string, unknown>, TExtensions = Record<string, unknown>>(): {
|
||||
httpLink: HttpLink;
|
||||
enqueueInitialChunk(chunk: InitialIncrementalExecutionResult<TData, TExtensions>): void;
|
||||
enqueueSubsequentChunk(chunk: SubsequentIncrementalExecutionResult<TData, TExtensions>): void;
|
||||
enqueueErrorChunk(errors: GraphQLFormattedError[]): void;
|
||||
};
|
||||
export declare function mockMultipartSubscriptionStream<TData = Record<string, unknown>, TExtensions = Record<string, unknown>>(): {
|
||||
httpLink: HttpLink;
|
||||
enqueueHeartbeat: () => void;
|
||||
enqueuePayloadResult(payload: ApolloPayloadResult<TData, TExtensions>["payload"], hasNext?: boolean): void;
|
||||
enqueueProtocolErrors(errors: ApolloPayloadResult["errors"]): void;
|
||||
};
|
||||
//# sourceMappingURL=incremental.d.ts.map
|
||||
124
node_modules/@apollo/client/testing/internal/incremental.js
generated
vendored
Normal file
124
node_modules/@apollo/client/testing/internal/incremental.js
generated
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
import { __assign } from "tslib";
|
||||
import { HttpLink } from "../../link/http/index.js";
|
||||
import { ReadableStream as NodeReadableStream, TextEncoderStream, TransformStream, } from "node:stream/web";
|
||||
var hasNextSymbol = Symbol("hasNext");
|
||||
export function mockIncrementalStream(_a) {
|
||||
var responseHeaders = _a.responseHeaders;
|
||||
var CLOSE = Symbol();
|
||||
var streamController = null;
|
||||
var sentInitialChunk = false;
|
||||
var queue = [];
|
||||
function processQueue() {
|
||||
if (!streamController) {
|
||||
throw new Error("Cannot process queue without stream controller");
|
||||
}
|
||||
var chunk;
|
||||
while ((chunk = queue.shift())) {
|
||||
if (chunk === CLOSE) {
|
||||
streamController.close();
|
||||
}
|
||||
else {
|
||||
streamController.enqueue(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
function createStream() {
|
||||
return new NodeReadableStream({
|
||||
start: function (c) {
|
||||
streamController = c;
|
||||
processQueue();
|
||||
},
|
||||
})
|
||||
.pipeThrough(new TransformStream({
|
||||
transform: function (chunk, controller) {
|
||||
controller.enqueue((!sentInitialChunk ? "\r\n---\r\n" : "") +
|
||||
"content-type: application/json; charset=utf-8\r\n\r\n" +
|
||||
JSON.stringify(chunk) +
|
||||
(chunk[hasNextSymbol] ? "\r\n---\r\n" : "\r\n-----\r\n"));
|
||||
sentInitialChunk = true;
|
||||
},
|
||||
}))
|
||||
.pipeThrough(new TextEncoderStream());
|
||||
}
|
||||
var httpLink = new HttpLink({
|
||||
fetch: function (input, init) {
|
||||
return Promise.resolve(new Response(createStream(), {
|
||||
status: 200,
|
||||
headers: responseHeaders,
|
||||
}));
|
||||
},
|
||||
});
|
||||
function queueNext(event) {
|
||||
queue.push(event);
|
||||
if (streamController) {
|
||||
processQueue();
|
||||
}
|
||||
}
|
||||
function close() {
|
||||
queueNext(CLOSE);
|
||||
streamController = null;
|
||||
sentInitialChunk = false;
|
||||
}
|
||||
function enqueue(chunk, hasNext) {
|
||||
var _a;
|
||||
queueNext(__assign(__assign({}, chunk), (_a = {}, _a[hasNextSymbol] = hasNext, _a)));
|
||||
if (!hasNext) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
return {
|
||||
httpLink: httpLink,
|
||||
enqueue: enqueue,
|
||||
close: close,
|
||||
};
|
||||
}
|
||||
export function mockDeferStream() {
|
||||
var _a = mockIncrementalStream({
|
||||
responseHeaders: new Headers({
|
||||
"Content-Type": 'multipart/mixed; boundary="-"; deferSpec=20220824',
|
||||
}),
|
||||
}), httpLink = _a.httpLink, enqueue = _a.enqueue;
|
||||
return {
|
||||
httpLink: httpLink,
|
||||
enqueueInitialChunk: function (chunk) {
|
||||
enqueue(chunk, chunk.hasNext);
|
||||
},
|
||||
enqueueSubsequentChunk: function (chunk) {
|
||||
enqueue(chunk, chunk.hasNext);
|
||||
},
|
||||
enqueueErrorChunk: function (errors) {
|
||||
enqueue({
|
||||
hasNext: true,
|
||||
incremental: [
|
||||
{
|
||||
// eslint-disable-next-line @typescript-eslint/no-restricted-types
|
||||
errors: errors,
|
||||
},
|
||||
],
|
||||
}, true);
|
||||
},
|
||||
};
|
||||
}
|
||||
export function mockMultipartSubscriptionStream() {
|
||||
var _a = mockIncrementalStream({
|
||||
responseHeaders: new Headers({
|
||||
"Content-Type": "multipart/mixed",
|
||||
}),
|
||||
}), httpLink = _a.httpLink, enqueue = _a.enqueue;
|
||||
enqueueHeartbeat();
|
||||
function enqueueHeartbeat() {
|
||||
enqueue({}, true);
|
||||
}
|
||||
return {
|
||||
httpLink: httpLink,
|
||||
enqueueHeartbeat: enqueueHeartbeat,
|
||||
enqueuePayloadResult: function (payload, hasNext) {
|
||||
if (hasNext === void 0) { hasNext = true; }
|
||||
enqueue({ payload: payload }, hasNext);
|
||||
},
|
||||
enqueueProtocolErrors: function (errors) {
|
||||
enqueue({ payload: null, errors: errors }, false);
|
||||
},
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=incremental.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/incremental.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/incremental.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
11
node_modules/@apollo/client/testing/internal/index.d.ts
generated
vendored
Normal file
11
node_modules/@apollo/client/testing/internal/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export * from "./disposables/index.js";
|
||||
export { ObservableStream } from "./ObservableStream.js";
|
||||
export type { SimpleCaseData, PaginatedCaseData, PaginatedCaseVariables, VariablesCaseData, VariablesCaseVariables, } from "./scenarios/index.js";
|
||||
export { setupSimpleCase, setupVariablesCase, setupPaginatedCase, addDelayToMocks, } from "./scenarios/index.js";
|
||||
export type { RenderWithClientOptions, RenderWithMocksOptions, } from "./renderHelpers.js";
|
||||
export { renderWithClient, renderWithMocks, createMockWrapper, createClientWrapper, } from "./renderHelpers.js";
|
||||
export { actAsync } from "./rtl/actAsync.js";
|
||||
export { renderAsync } from "./rtl/renderAsync.js";
|
||||
export { renderHookAsync } from "./rtl/renderHookAsync.js";
|
||||
export { mockIncrementalStream, mockDeferStream, mockMultipartSubscriptionStream, } from "./incremental.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
9
node_modules/@apollo/client/testing/internal/index.js
generated
vendored
Normal file
9
node_modules/@apollo/client/testing/internal/index.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export * from "./disposables/index.js";
|
||||
export { ObservableStream } from "./ObservableStream.js";
|
||||
export { setupSimpleCase, setupVariablesCase, setupPaginatedCase, addDelayToMocks, } from "./scenarios/index.js";
|
||||
export { renderWithClient, renderWithMocks, createMockWrapper, createClientWrapper, } from "./renderHelpers.js";
|
||||
export { actAsync } from "./rtl/actAsync.js";
|
||||
export { renderAsync } from "./rtl/renderAsync.js";
|
||||
export { renderHookAsync } from "./rtl/renderHookAsync.js";
|
||||
export { mockIncrementalStream, mockDeferStream, mockMultipartSubscriptionStream, } from "./incremental.js";
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/internal/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AASzD,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,+BAA+B,GAChC,MAAM,kBAAkB,CAAC","sourcesContent":["export * from \"./disposables/index.js\";\nexport { ObservableStream } from \"./ObservableStream.js\";\n\nexport type {\n SimpleCaseData,\n PaginatedCaseData,\n PaginatedCaseVariables,\n VariablesCaseData,\n VariablesCaseVariables,\n} from \"./scenarios/index.js\";\nexport {\n setupSimpleCase,\n setupVariablesCase,\n setupPaginatedCase,\n addDelayToMocks,\n} from \"./scenarios/index.js\";\n\nexport type {\n RenderWithClientOptions,\n RenderWithMocksOptions,\n} from \"./renderHelpers.js\";\nexport {\n renderWithClient,\n renderWithMocks,\n createMockWrapper,\n createClientWrapper,\n} from \"./renderHelpers.js\";\nexport { actAsync } from \"./rtl/actAsync.js\";\nexport { renderAsync } from \"./rtl/renderAsync.js\";\nexport { renderHookAsync } from \"./rtl/renderHookAsync.js\";\nexport {\n mockIncrementalStream,\n mockDeferStream,\n mockMultipartSubscriptionStream,\n} from \"./incremental.js\";\n"]}
|
||||
23
node_modules/@apollo/client/testing/internal/renderHelpers.d.ts
generated
vendored
Normal file
23
node_modules/@apollo/client/testing/internal/renderHelpers.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import * as React from "react";
|
||||
import type { ReactElement } from "react";
|
||||
import type { Queries, RenderOptions, queries } from "@testing-library/react";
|
||||
import type { ApolloClient } from "../../core/index.js";
|
||||
import type { MockedProviderProps } from "../react/MockedProvider.js";
|
||||
export interface RenderWithClientOptions<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container> extends RenderOptions<Q, Container, BaseElement> {
|
||||
client: ApolloClient<any>;
|
||||
}
|
||||
export declare function createClientWrapper(client: ApolloClient<any>, Wrapper?: React.JSXElementConstructor<{
|
||||
children: React.ReactNode;
|
||||
}>): React.JSXElementConstructor<{
|
||||
children: React.ReactNode;
|
||||
}>;
|
||||
export declare function renderWithClient<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container>(ui: ReactElement, { client, wrapper, ...renderOptions }: RenderWithClientOptions<Q, Container, BaseElement>): import("@testing-library/react").RenderResult<Q, Container, BaseElement>;
|
||||
export interface RenderWithMocksOptions<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container> extends RenderOptions<Q, Container, BaseElement>, MockedProviderProps<any> {
|
||||
}
|
||||
export declare function createMockWrapper(renderOptions: MockedProviderProps<any>, Wrapper?: React.JSXElementConstructor<{
|
||||
children: React.ReactNode;
|
||||
}>): React.JSXElementConstructor<{
|
||||
children: React.ReactNode;
|
||||
}>;
|
||||
export declare function renderWithMocks<Q extends Queries = typeof queries, Container extends Element | DocumentFragment = HTMLElement, BaseElement extends Element | DocumentFragment = Container>(ui: ReactElement, { wrapper, ...renderOptions }: RenderWithMocksOptions<Q, Container, BaseElement>): import("@testing-library/react").RenderResult<Q, Container, BaseElement>;
|
||||
//# sourceMappingURL=renderHelpers.d.ts.map
|
||||
30
node_modules/@apollo/client/testing/internal/renderHelpers.js
generated
vendored
Normal file
30
node_modules/@apollo/client/testing/internal/renderHelpers.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { __assign, __rest } from "tslib";
|
||||
import * as React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { ApolloProvider } from "../../react/index.js";
|
||||
import { MockedProvider } from "../react/MockedProvider.js";
|
||||
export function createClientWrapper(client, Wrapper) {
|
||||
if (Wrapper === void 0) { Wrapper = React.Fragment; }
|
||||
return function (_a) {
|
||||
var children = _a.children;
|
||||
return (React.createElement(ApolloProvider, { client: client },
|
||||
React.createElement(Wrapper, null, children)));
|
||||
};
|
||||
}
|
||||
export function renderWithClient(ui, _a) {
|
||||
var client = _a.client, wrapper = _a.wrapper, renderOptions = __rest(_a, ["client", "wrapper"]);
|
||||
return render(ui, __assign(__assign({}, renderOptions), { wrapper: createClientWrapper(client, wrapper) }));
|
||||
}
|
||||
export function createMockWrapper(renderOptions, Wrapper) {
|
||||
if (Wrapper === void 0) { Wrapper = React.Fragment; }
|
||||
return function (_a) {
|
||||
var children = _a.children;
|
||||
return (React.createElement(MockedProvider, __assign({}, renderOptions),
|
||||
React.createElement(Wrapper, null, children)));
|
||||
};
|
||||
}
|
||||
export function renderWithMocks(ui, _a) {
|
||||
var wrapper = _a.wrapper, renderOptions = __rest(_a, ["wrapper"]);
|
||||
return render(ui, __assign(__assign({}, renderOptions), { wrapper: createMockWrapper(renderOptions, wrapper) }));
|
||||
}
|
||||
//# sourceMappingURL=renderHelpers.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/renderHelpers.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/renderHelpers.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"renderHelpers.js","sourceRoot":"","sources":["../../../src/testing/internal/renderHelpers.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAU5D,MAAM,UAAU,mBAAmB,CACjC,MAAyB,EACzB,OAEmB;IAFnB,wBAAA,EAAA,UAEK,KAAK,CAAC,QAAQ;IAInB,OAAO,UAAC,EAAY;YAAV,QAAQ,cAAA;QAChB,OAAO,CACL,oBAAC,cAAc,IAAC,MAAM,EAAE,MAAM;YAC5B,oBAAC,OAAO,QAAE,QAAQ,CAAW,CACd,CAClB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAK9B,EAAgB,EAChB,EAIqD;IAHnD,IAAA,MAAM,YAAA,EACN,OAAO,aAAA,EACJ,aAAa,cAHlB,qBAIC,CADiB;IAGlB,OAAO,MAAM,CAAC,EAAE,wBACX,aAAa,KAChB,OAAO,EAAE,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,IAC7C,CAAC;AACL,CAAC;AASD,MAAM,UAAU,iBAAiB,CAC/B,aAAuC,EACvC,OAEmB;IAFnB,wBAAA,EAAA,UAEK,KAAK,CAAC,QAAQ;IAInB,OAAO,UAAC,EAAY;YAAV,QAAQ,cAAA;QAChB,OAAO,CACL,oBAAC,cAAc,eAAK,aAAa;YAC/B,oBAAC,OAAO,QAAE,QAAQ,CAAW,CACd,CAClB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAK7B,EAAgB,EAChB,EAGoD;IAFlD,IAAA,OAAO,aAAA,EACJ,aAAa,cAFlB,WAGC,CADiB;IAGlB,OAAO,MAAM,CAAC,EAAE,wBACX,aAAa,KAChB,OAAO,EAAE,iBAAiB,CAAC,aAAa,EAAE,OAAO,CAAC,IAClD,CAAC;AACL,CAAC","sourcesContent":["import * as React from \"react\";\nimport type { ReactElement } from \"react\";\nimport { render } from \"@testing-library/react\";\nimport type { Queries, RenderOptions, queries } from \"@testing-library/react\";\nimport type { ApolloClient } from \"../../core/index.js\";\nimport { ApolloProvider } from \"../../react/index.js\";\nimport type { MockedProviderProps } from \"../react/MockedProvider.js\";\nimport { MockedProvider } from \"../react/MockedProvider.js\";\n\nexport interface RenderWithClientOptions<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n> extends RenderOptions<Q, Container, BaseElement> {\n client: ApolloClient<any>;\n}\n\nexport function createClientWrapper(\n client: ApolloClient<any>,\n Wrapper: React.JSXElementConstructor<{\n children: React.ReactNode;\n }> = React.Fragment\n): React.JSXElementConstructor<{\n children: React.ReactNode;\n}> {\n return ({ children }) => {\n return (\n <ApolloProvider client={client}>\n <Wrapper>{children}</Wrapper>\n </ApolloProvider>\n );\n };\n}\n\nexport function renderWithClient<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n>(\n ui: ReactElement,\n {\n client,\n wrapper,\n ...renderOptions\n }: RenderWithClientOptions<Q, Container, BaseElement>\n) {\n return render(ui, {\n ...renderOptions,\n wrapper: createClientWrapper(client, wrapper),\n });\n}\n\nexport interface RenderWithMocksOptions<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n> extends RenderOptions<Q, Container, BaseElement>,\n MockedProviderProps<any> {}\n\nexport function createMockWrapper(\n renderOptions: MockedProviderProps<any>,\n Wrapper: React.JSXElementConstructor<{\n children: React.ReactNode;\n }> = React.Fragment\n): React.JSXElementConstructor<{\n children: React.ReactNode;\n}> {\n return ({ children }) => {\n return (\n <MockedProvider {...renderOptions}>\n <Wrapper>{children}</Wrapper>\n </MockedProvider>\n );\n };\n}\n\nexport function renderWithMocks<\n Q extends Queries = typeof queries,\n Container extends Element | DocumentFragment = HTMLElement,\n BaseElement extends Element | DocumentFragment = Container,\n>(\n ui: ReactElement,\n {\n wrapper,\n ...renderOptions\n }: RenderWithMocksOptions<Q, Container, BaseElement>\n) {\n return render(ui, {\n ...renderOptions,\n wrapper: createMockWrapper(renderOptions, wrapper),\n });\n}\n"]}
|
||||
2
node_modules/@apollo/client/testing/internal/rtl/actAsync.d.ts
generated
vendored
Normal file
2
node_modules/@apollo/client/testing/internal/rtl/actAsync.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare function actAsync<T>(scope: () => T | Promise<T>): Promise<T>;
|
||||
//# sourceMappingURL=actAsync.d.ts.map
|
||||
21
node_modules/@apollo/client/testing/internal/rtl/actAsync.js
generated
vendored
Normal file
21
node_modules/@apollo/client/testing/internal/rtl/actAsync.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// This is a helper required for React 19 testing.
|
||||
// There are currently multiple directions this could play out in RTL and none of
|
||||
// them has been released yet, so we are inlining this helper for now.
|
||||
// See https://github.com/testing-library/react-testing-library/pull/1214
|
||||
// and https://github.com/testing-library/react-testing-library/pull/1365
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
import * as React from "react";
|
||||
import * as DeprecatedReactTestUtils from "react-dom/test-utils";
|
||||
var reactAct = typeof React.act === "function" ? React.act : DeprecatedReactTestUtils.act;
|
||||
export function actAsync(scope) {
|
||||
var _this = this;
|
||||
return reactAct(function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, scope()];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
}
|
||||
//# sourceMappingURL=actAsync.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/rtl/actAsync.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/rtl/actAsync.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"actAsync.js","sourceRoot":"","sources":["../../../../src/testing/internal/rtl/actAsync.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,iFAAiF;AACjF,sEAAsE;AACtE,yEAAyE;AACzE,yEAAyE;;AAEzE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,wBAAwB,MAAM,sBAAsB,CAAC;AAEjE,IAAM,QAAQ,GACZ,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,wBAAwB,CAAC,GAAG,CAAC;AAE7E,MAAM,UAAU,QAAQ,CAAI,KAA2B;IAAvD,iBAIC;IAHC,OAAO,QAAQ,CAAC;;;wBACP,qBAAM,KAAK,EAAE,EAAA;wBAApB,sBAAO,SAAa,EAAC;;;SACtB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// This is a helper required for React 19 testing.\n// There are currently multiple directions this could play out in RTL and none of\n// them has been released yet, so we are inlining this helper for now.\n// See https://github.com/testing-library/react-testing-library/pull/1214\n// and https://github.com/testing-library/react-testing-library/pull/1365\n\nimport * as React from \"react\";\nimport * as DeprecatedReactTestUtils from \"react-dom/test-utils\";\n\nconst reactAct =\n typeof React.act === \"function\" ? React.act : DeprecatedReactTestUtils.act;\n\nexport function actAsync<T>(scope: () => T | Promise<T>): Promise<T> {\n return reactAct(async () => {\n return await scope();\n });\n}\n"]}
|
||||
9
node_modules/@apollo/client/testing/internal/rtl/renderAsync.d.ts
generated
vendored
Normal file
9
node_modules/@apollo/client/testing/internal/rtl/renderAsync.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { queries, Queries } from "@testing-library/dom";
|
||||
import type { RenderOptions, RenderResult } from "@testing-library/react";
|
||||
import type * as ReactDOMClient from "react-dom/client";
|
||||
type RendererableContainer = ReactDOMClient.Container;
|
||||
type HydrateableContainer = Parameters<(typeof ReactDOMClient)["hydrateRoot"]>[0];
|
||||
export declare function renderAsync<Q extends Queries = typeof queries, Container extends RendererableContainer | HydrateableContainer = HTMLElement, BaseElement extends RendererableContainer | HydrateableContainer = Container>(ui: React.ReactNode, options: RenderOptions<Q, Container, BaseElement>): Promise<RenderResult<Q, Container, BaseElement>>;
|
||||
export declare function renderAsync(ui: React.ReactNode, options?: Omit<RenderOptions, "queries"> | undefined): Promise<RenderResult>;
|
||||
export {};
|
||||
//# sourceMappingURL=renderAsync.d.ts.map
|
||||
23
node_modules/@apollo/client/testing/internal/rtl/renderAsync.js
generated
vendored
Normal file
23
node_modules/@apollo/client/testing/internal/rtl/renderAsync.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// This is a helper required for React 19 testing.
|
||||
// There are currently multiple directions this could play out in RTL and none of
|
||||
// them has been released yet, so we are inlining this helper for now.
|
||||
// See https://github.com/testing-library/react-testing-library/pull/1214
|
||||
// and https://github.com/testing-library/react-testing-library/pull/1365
|
||||
import { __awaiter, __generator } from "tslib";
|
||||
import { act, render } from "@testing-library/react";
|
||||
export function renderAsync() {
|
||||
var _this = this;
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
return act(function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, render.apply(void 0, args)];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
}
|
||||
//# sourceMappingURL=renderAsync.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/rtl/renderAsync.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/rtl/renderAsync.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"renderAsync.js","sourceRoot":"","sources":["../../../../src/testing/internal/rtl/renderAsync.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,iFAAiF;AACjF,sEAAsE;AACtE,yEAAyE;AACzE,yEAAyE;;AAIzE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAqBrD,MAAM,UAAU,WAAW;IAA3B,iBAIC;IAJ2B,cAAmB;SAAnB,UAAmB,EAAnB,qBAAmB,EAAnB,IAAmB;QAAnB,yBAAmB;;IAC7C,OAAO,GAAG,CAAC;;;wBACF,qBAAM,MAAM,eAAI,IAAI,GAAC;wBAA5B,sBAAO,SAAqB,EAAC;;;SAC9B,CAAC,CAAC;AACL,CAAC","sourcesContent":["// This is a helper required for React 19 testing.\n// There are currently multiple directions this could play out in RTL and none of\n// them has been released yet, so we are inlining this helper for now.\n// See https://github.com/testing-library/react-testing-library/pull/1214\n// and https://github.com/testing-library/react-testing-library/pull/1365\n\nimport type { queries, Queries } from \"@testing-library/dom\";\nimport type { RenderOptions, RenderResult } from \"@testing-library/react\";\nimport { act, render } from \"@testing-library/react\";\nimport type * as ReactDOMClient from \"react-dom/client\";\n\ntype RendererableContainer = ReactDOMClient.Container;\ntype HydrateableContainer = Parameters<\n (typeof ReactDOMClient)[\"hydrateRoot\"]\n>[0];\n\nexport function renderAsync<\n Q extends Queries = typeof queries,\n Container extends RendererableContainer | HydrateableContainer = HTMLElement,\n BaseElement extends RendererableContainer | HydrateableContainer = Container,\n>(\n ui: React.ReactNode,\n options: RenderOptions<Q, Container, BaseElement>\n): Promise<RenderResult<Q, Container, BaseElement>>;\nexport function renderAsync(\n ui: React.ReactNode,\n options?: Omit<RenderOptions, \"queries\"> | undefined\n): Promise<RenderResult>;\n\nexport function renderAsync(...args: [any, any]): any {\n return act(async () => {\n return await render(...args);\n });\n}\n"]}
|
||||
8
node_modules/@apollo/client/testing/internal/rtl/renderHookAsync.d.ts
generated
vendored
Normal file
8
node_modules/@apollo/client/testing/internal/rtl/renderHookAsync.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { queries, Queries } from "@testing-library/dom";
|
||||
import type { RenderHookOptions, RenderHookResult } from "@testing-library/react";
|
||||
import type * as ReactDOMClient from "react-dom/client";
|
||||
type RendererableContainer = ReactDOMClient.Container;
|
||||
type HydrateableContainer = Parameters<(typeof ReactDOMClient)["hydrateRoot"]>[0];
|
||||
export declare function renderHookAsync<Result, Props, Q extends Queries = typeof queries, Container extends RendererableContainer | HydrateableContainer = HTMLElement, BaseElement extends RendererableContainer | HydrateableContainer = Container>(renderCallback: (initialProps: Props) => Result, options?: RenderHookOptions<Props, Q, Container, BaseElement> | undefined): Promise<RenderHookResult<Result, Props>>;
|
||||
export {};
|
||||
//# sourceMappingURL=renderHookAsync.d.ts.map
|
||||
46
node_modules/@apollo/client/testing/internal/rtl/renderHookAsync.js
generated
vendored
Normal file
46
node_modules/@apollo/client/testing/internal/rtl/renderHookAsync.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
// This is a helper required for React 19 testing.
|
||||
// There are currently multiple directions this could play out in RTL and none of
|
||||
// them has been released yet, so we are inlining this helper for now.
|
||||
// See https://github.com/testing-library/react-testing-library/pull/1214
|
||||
// and https://github.com/testing-library/react-testing-library/pull/1365
|
||||
import { __awaiter, __generator, __rest } from "tslib";
|
||||
import * as ReactDOM from "react-dom";
|
||||
import * as React from "react";
|
||||
import { renderAsync } from "./renderAsync.js";
|
||||
export function renderHookAsync(renderCallback_1) {
|
||||
return __awaiter(this, arguments, void 0, function (renderCallback, options) {
|
||||
function TestComponent(_a) {
|
||||
var renderCallbackProps = _a.renderCallbackProps;
|
||||
var pendingResult = renderCallback(renderCallbackProps);
|
||||
React.useEffect(function () {
|
||||
result.current = pendingResult;
|
||||
});
|
||||
return null;
|
||||
}
|
||||
function rerender(rerenderCallbackProps) {
|
||||
return baseRerender(React.createElement(TestComponent, { renderCallbackProps: rerenderCallbackProps }));
|
||||
}
|
||||
var initialProps, renderOptions, error, result, _a, baseRerender, unmount;
|
||||
if (options === void 0) { options = {}; }
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
initialProps = options.initialProps, renderOptions = __rest(options, ["initialProps"]);
|
||||
// @ts-expect-error
|
||||
if (renderOptions.legacyRoot && typeof ReactDOM.render !== "function") {
|
||||
error = new Error("`legacyRoot: true` is not supported in this version of React. " +
|
||||
"If your app runs React 19 or later, you should remove this flag. " +
|
||||
"If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.");
|
||||
Error.captureStackTrace(error, renderHookAsync);
|
||||
throw error;
|
||||
}
|
||||
result = React.createRef();
|
||||
return [4 /*yield*/, renderAsync(React.createElement(TestComponent, { renderCallbackProps: initialProps }), renderOptions)];
|
||||
case 1:
|
||||
_a = _b.sent(), baseRerender = _a.rerender, unmount = _a.unmount;
|
||||
return [2 /*return*/, { result: result, rerender: rerender, unmount: unmount }];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=renderHookAsync.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/rtl/renderHookAsync.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/rtl/renderHookAsync.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"renderHookAsync.js","sourceRoot":"","sources":["../../../../src/testing/internal/rtl/renderHookAsync.tsx"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,iFAAiF;AACjF,sEAAsE;AACtE,yEAAyE;AACzE,yEAAyE;;AAQzE,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO/C,MAAM,UAAgB,eAAe;wDAOnC,cAA+C,EAC/C,OAA6E;QAiB7E,SAAS,aAAa,CAAC,EAItB;gBAHC,mBAAmB,yBAAA;YAInB,IAAM,aAAa,GAAG,cAAc,CAAC,mBAAmB,CAAC,CAAC;YAE1D,KAAK,CAAC,SAAS,CAAC;gBACd,MAAM,CAAC,OAAO,GAAG,aAAa,CAAC;YACjC,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QACd,CAAC;QAOD,SAAS,QAAQ,CAAC,qBAA6B;YAC7C,OAAO,YAAY,CACjB,oBAAC,aAAa,IAAC,mBAAmB,EAAE,qBAAsB,GAAI,CAC/D,CAAC;QACJ,CAAC;;QAxCD,wBAAA,EAAA,YAA6E;;;;oBAErE,YAAY,GAAuB,OAAO,aAA9B,EAAK,aAAa,UAAK,OAAO,EAA5C,gBAAkC,CAAF,CAAa;oBAEnD,mBAAmB;oBACnB,IAAI,aAAa,CAAC,UAAU,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;wBAChE,KAAK,GAAG,IAAI,KAAK,CACrB,gEAAgE;4BAC9D,mEAAmE;4BACnE,gIAAgI,CACnI,CAAC;wBACF,KAAK,CAAC,iBAAiB,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;wBAChD,MAAM,KAAK,CAAC;oBACd,CAAC;oBAEK,MAAM,GAAG,KAAK,CAAC,SAAS,EAAiC,CAAC;oBAgBpB,qBAAM,WAAW,CAC3D,oBAAC,aAAa,IAAC,mBAAmB,EAAE,YAAa,GAAI,EACrD,aAAa,CACd,EAAA;;oBAHK,KAAsC,SAG3C,EAHiB,YAAY,cAAA,EAAE,OAAO,aAAA;oBAWvC,sBAAO,EAAE,MAAM,QAAA,EAAE,QAAQ,UAAA,EAAE,OAAO,SAAA,EAAE,EAAC;;;;CACtC","sourcesContent":["// This is a helper required for React 19 testing.\n// There are currently multiple directions this could play out in RTL and none of\n// them has been released yet, so we are inlining this helper for now.\n// See https://github.com/testing-library/react-testing-library/pull/1214\n// and https://github.com/testing-library/react-testing-library/pull/1365\n\nimport type { queries, Queries } from \"@testing-library/dom\";\nimport type {\n RenderHookOptions,\n RenderHookResult,\n} from \"@testing-library/react\";\nimport type * as ReactDOMClient from \"react-dom/client\";\nimport * as ReactDOM from \"react-dom\";\nimport * as React from \"react\";\nimport { renderAsync } from \"./renderAsync.js\";\n\ntype RendererableContainer = ReactDOMClient.Container;\ntype HydrateableContainer = Parameters<\n (typeof ReactDOMClient)[\"hydrateRoot\"]\n>[0];\n\nexport async function renderHookAsync<\n Result,\n Props,\n Q extends Queries = typeof queries,\n Container extends RendererableContainer | HydrateableContainer = HTMLElement,\n BaseElement extends RendererableContainer | HydrateableContainer = Container,\n>(\n renderCallback: (initialProps: Props) => Result,\n options: RenderHookOptions<Props, Q, Container, BaseElement> | undefined = {}\n): Promise<RenderHookResult<Result, Props>> {\n const { initialProps, ...renderOptions } = options;\n\n // @ts-expect-error\n if (renderOptions.legacyRoot && typeof ReactDOM.render !== \"function\") {\n const error = new Error(\n \"`legacyRoot: true` is not supported in this version of React. \" +\n \"If your app runs React 19 or later, you should remove this flag. \" +\n \"If your app runs React 18 or earlier, visit https://react.dev/blog/2022/03/08/react-18-upgrade-guide for upgrade instructions.\"\n );\n Error.captureStackTrace(error, renderHookAsync);\n throw error;\n }\n\n const result = React.createRef<Result>() as { current: Result };\n\n function TestComponent({\n renderCallbackProps,\n }: {\n renderCallbackProps: Props;\n }) {\n const pendingResult = renderCallback(renderCallbackProps);\n\n React.useEffect(() => {\n result.current = pendingResult;\n });\n\n return null;\n }\n\n const { rerender: baseRerender, unmount } = await renderAsync(\n <TestComponent renderCallbackProps={initialProps!} />,\n renderOptions\n );\n\n function rerender(rerenderCallbackProps?: Props) {\n return baseRerender(\n <TestComponent renderCallbackProps={rerenderCallbackProps!} />\n );\n }\n\n return { result, rerender, unmount };\n}\n"]}
|
||||
85
node_modules/@apollo/client/testing/internal/scenarios/index.d.ts
generated
vendored
Normal file
85
node_modules/@apollo/client/testing/internal/scenarios/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
import { ApolloLink } from "../../../core/index.js";
|
||||
import type { TypedDocumentNode } from "../../../core/index.js";
|
||||
import type { MaskedDocumentNode } from "../../../masking/index.js";
|
||||
import type { MockedResponse } from "../../core/index.js";
|
||||
export interface SimpleCaseData {
|
||||
greeting: string;
|
||||
}
|
||||
export declare function setupSimpleCase(): {
|
||||
query: TypedDocumentNode<SimpleCaseData, Record<string, never>>;
|
||||
mocks: MockedResponse<SimpleCaseData, Record<string, any>>[];
|
||||
};
|
||||
export interface VariablesCaseData {
|
||||
character: {
|
||||
__typename: "Character";
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
export interface VariablesCaseVariables {
|
||||
id: string;
|
||||
}
|
||||
export declare function setupVariablesCase(): {
|
||||
mocks: MockedResponse<VariablesCaseData, Record<string, any>>[];
|
||||
query: TypedDocumentNode<VariablesCaseData, VariablesCaseVariables>;
|
||||
};
|
||||
export type MaskedVariablesCaseFragment = {
|
||||
__typename: "Character";
|
||||
name: string;
|
||||
} & {
|
||||
" $fragmentName"?: "MaskedVariablesCaseFragment";
|
||||
};
|
||||
export interface MaskedVariablesCaseData {
|
||||
character: {
|
||||
__typename: "Character";
|
||||
id: string;
|
||||
} & {
|
||||
" $fragmentRefs"?: {
|
||||
MaskedVariablesCaseFragment: MaskedVariablesCaseFragment;
|
||||
};
|
||||
};
|
||||
}
|
||||
export interface UnmaskedVariablesCaseData {
|
||||
character: {
|
||||
__typename: "Character";
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
export declare function setupMaskedVariablesCase(): {
|
||||
mocks: MockedResponse<MaskedVariablesCaseData, Record<string, any>>[];
|
||||
query: MaskedDocumentNode<MaskedVariablesCaseData, VariablesCaseVariables>;
|
||||
unmaskedQuery: TypedDocumentNode<MaskedVariablesCaseData, VariablesCaseVariables>;
|
||||
};
|
||||
export declare function addDelayToMocks<T extends MockedResponse<unknown>[]>(mocks: T, delay?: number, override?: boolean): {
|
||||
delay: number;
|
||||
request: import("../../../core/index.js").GraphQLRequest<Record<string, any>>;
|
||||
maxUsageCount?: number;
|
||||
result?: import("../../../core/index.js").FetchResult<unknown> | import("../../core/index.js").ResultFunction<import("../../../core/index.js").FetchResult<unknown>, Record<string, any>> | undefined;
|
||||
error?: Error;
|
||||
variableMatcher?: import("../../core/mocking/mockLink.js").VariableMatcher<Record<string, any>> | undefined;
|
||||
newData?: import("../../core/index.js").ResultFunction<import("../../../core/index.js").FetchResult<unknown>, Record<string, any>> | undefined;
|
||||
}[];
|
||||
interface Letter {
|
||||
__typename: "Letter";
|
||||
letter: string;
|
||||
position: number;
|
||||
}
|
||||
export interface PaginatedCaseData {
|
||||
letters: Letter[];
|
||||
}
|
||||
export interface PaginatedCaseVariables {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
}
|
||||
export declare function setupPaginatedCase(): {
|
||||
query: TypedDocumentNode<PaginatedCaseData, PaginatedCaseVariables>;
|
||||
link: ApolloLink;
|
||||
data: {
|
||||
__typename: string;
|
||||
letter: string;
|
||||
position: number;
|
||||
}[];
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
71
node_modules/@apollo/client/testing/internal/scenarios/index.js
generated
vendored
Normal file
71
node_modules/@apollo/client/testing/internal/scenarios/index.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import { __assign, __makeTemplateObject, __spreadArray } from "tslib";
|
||||
import { ApolloLink, Observable, gql } from "../../../core/index.js";
|
||||
export function setupSimpleCase() {
|
||||
var query = gql(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n query GreetingQuery {\n greeting\n }\n "], ["\n query GreetingQuery {\n greeting\n }\n "])));
|
||||
var mocks = [
|
||||
{
|
||||
request: { query: query },
|
||||
result: { data: { greeting: "Hello" } },
|
||||
delay: 20,
|
||||
},
|
||||
];
|
||||
return { query: query, mocks: mocks };
|
||||
}
|
||||
export function setupVariablesCase() {
|
||||
var query = gql(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n query CharacterQuery($id: ID!) {\n character(id: $id) {\n id\n name\n }\n }\n "], ["\n query CharacterQuery($id: ID!) {\n character(id: $id) {\n id\n name\n }\n }\n "])));
|
||||
var CHARACTERS = ["Spider-Man", "Black Widow", "Iron Man", "Hulk"];
|
||||
var mocks = __spreadArray([], CHARACTERS, true).map(function (name, index) { return ({
|
||||
request: { query: query, variables: { id: String(index + 1) } },
|
||||
result: {
|
||||
data: {
|
||||
character: { __typename: "Character", id: String(index + 1), name: name },
|
||||
},
|
||||
},
|
||||
delay: 20,
|
||||
}); });
|
||||
return { mocks: mocks, query: query };
|
||||
}
|
||||
export function setupMaskedVariablesCase() {
|
||||
var document = gql(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n query CharacterQuery($id: ID!) {\n character(id: $id) {\n id\n ...CharacterFragment\n }\n }\n\n fragment CharacterFragment on Character {\n name\n }\n "], ["\n query CharacterQuery($id: ID!) {\n character(id: $id) {\n id\n ...CharacterFragment\n }\n }\n\n fragment CharacterFragment on Character {\n name\n }\n "])));
|
||||
var query = document;
|
||||
var unmaskedQuery = document;
|
||||
var CHARACTERS = ["Spider-Man", "Black Widow", "Iron Man", "Hulk"];
|
||||
var mocks = __spreadArray([], CHARACTERS, true).map(function (name, index) { return ({
|
||||
request: { query: query, variables: { id: String(index + 1) } },
|
||||
result: {
|
||||
data: {
|
||||
character: { __typename: "Character", id: String(index + 1), name: name },
|
||||
},
|
||||
},
|
||||
delay: 20,
|
||||
}); });
|
||||
return { mocks: mocks, query: query, unmaskedQuery: unmaskedQuery };
|
||||
}
|
||||
export function addDelayToMocks(mocks, delay, override) {
|
||||
if (delay === void 0) { delay = 150; }
|
||||
if (override === void 0) { override = false; }
|
||||
return mocks.map(function (mock) {
|
||||
return override ? __assign(__assign({}, mock), { delay: delay }) : __assign({ delay: delay }, mock);
|
||||
});
|
||||
}
|
||||
export function setupPaginatedCase() {
|
||||
var query = gql(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n query LettersQuery($limit: Int, $offset: Int) {\n letters(limit: $limit, offset: $offset) {\n letter\n position\n }\n }\n "], ["\n query LettersQuery($limit: Int, $offset: Int) {\n letters(limit: $limit, offset: $offset) {\n letter\n position\n }\n }\n "])));
|
||||
var data = "ABCDEFGHIJKLMNOPQRSTUV".split("").map(function (letter, index) { return ({
|
||||
__typename: "Letter",
|
||||
letter: letter,
|
||||
position: index + 1,
|
||||
}); });
|
||||
var link = new ApolloLink(function (operation) {
|
||||
var _a = operation.variables, _b = _a.offset, offset = _b === void 0 ? 0 : _b, _c = _a.limit, limit = _c === void 0 ? 2 : _c;
|
||||
var letters = data.slice(offset, offset + limit);
|
||||
return new Observable(function (observer) {
|
||||
setTimeout(function () {
|
||||
observer.next({ data: { letters: letters } });
|
||||
observer.complete();
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
return { query: query, link: link, data: data };
|
||||
}
|
||||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/client/testing/internal/scenarios/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/internal/scenarios/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/@apollo/client/testing/matchers/index.d.ts
generated
vendored
Normal file
2
node_modules/@apollo/client/testing/matchers/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {};
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
36
node_modules/@apollo/client/testing/matchers/index.js
generated
vendored
Normal file
36
node_modules/@apollo/client/testing/matchers/index.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { expect } from "@jest/globals";
|
||||
import { toMatchDocument } from "./toMatchDocument.js";
|
||||
import { toHaveSuspenseCacheEntryUsing } from "./toHaveSuspenseCacheEntryUsing.js";
|
||||
import { toBeGarbageCollected } from "./toBeGarbageCollected.js";
|
||||
import { toBeDisposed } from "./toBeDisposed.js";
|
||||
import { toComplete } from "./toComplete.js";
|
||||
import { toEmitApolloQueryResult } from "./toEmitApolloQueryResult.js";
|
||||
import { toEmitAnything } from "./toEmitAnything.js";
|
||||
import { toEmitError } from "./toEmitError.js";
|
||||
import { toEmitFetchResult } from "./toEmitFetchResult.js";
|
||||
import { toEmitMatchedValue } from "./toEmitMatchedValue.js";
|
||||
import { toEmitNext } from "./toEmitNext.js";
|
||||
import { toEmitValue } from "./toEmitValue.js";
|
||||
import { toEmitValueStrict } from "./toEmitValueStrict.js";
|
||||
import { toEqualApolloQueryResult } from "./toEqualApolloQueryResult.js";
|
||||
import { toEqualFetchResult } from "./toEqualFetchResult.js";
|
||||
import { toEqualQueryResult } from "./toEqualQueryResult.js";
|
||||
expect.extend({
|
||||
toComplete: toComplete,
|
||||
toEmitApolloQueryResult: toEmitApolloQueryResult,
|
||||
toEmitAnything: toEmitAnything,
|
||||
toEmitError: toEmitError,
|
||||
toEmitFetchResult: toEmitFetchResult,
|
||||
toEmitMatchedValue: toEmitMatchedValue,
|
||||
toEmitNext: toEmitNext,
|
||||
toEmitValue: toEmitValue,
|
||||
toEmitValueStrict: toEmitValueStrict,
|
||||
toEqualApolloQueryResult: toEqualApolloQueryResult,
|
||||
toEqualFetchResult: toEqualFetchResult,
|
||||
toEqualQueryResult: toEqualQueryResult,
|
||||
toBeDisposed: toBeDisposed,
|
||||
toHaveSuspenseCacheEntryUsing: toHaveSuspenseCacheEntryUsing,
|
||||
toMatchDocument: toMatchDocument,
|
||||
toBeGarbageCollected: toBeGarbageCollected,
|
||||
});
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/@apollo/client/testing/matchers/index.js.map
generated
vendored
Normal file
1
node_modules/@apollo/client/testing/matchers/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/matchers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,CAAC;IACZ,UAAU,YAAA;IACV,uBAAuB,yBAAA;IACvB,cAAc,gBAAA;IACd,WAAW,aAAA;IACX,iBAAiB,mBAAA;IACjB,kBAAkB,oBAAA;IAClB,UAAU,YAAA;IACV,WAAW,aAAA;IACX,iBAAiB,mBAAA;IACjB,wBAAwB,0BAAA;IACxB,kBAAkB,oBAAA;IAClB,kBAAkB,oBAAA;IAClB,YAAY,cAAA;IACZ,6BAA6B,+BAAA;IAC7B,eAAe,iBAAA;IACf,oBAAoB,sBAAA;CACrB,CAAC,CAAC","sourcesContent":["import { expect } from \"@jest/globals\";\nimport { toMatchDocument } from \"./toMatchDocument.js\";\nimport { toHaveSuspenseCacheEntryUsing } from \"./toHaveSuspenseCacheEntryUsing.js\";\nimport { toBeGarbageCollected } from \"./toBeGarbageCollected.js\";\nimport { toBeDisposed } from \"./toBeDisposed.js\";\nimport { toComplete } from \"./toComplete.js\";\nimport { toEmitApolloQueryResult } from \"./toEmitApolloQueryResult.js\";\nimport { toEmitAnything } from \"./toEmitAnything.js\";\nimport { toEmitError } from \"./toEmitError.js\";\nimport { toEmitFetchResult } from \"./toEmitFetchResult.js\";\nimport { toEmitMatchedValue } from \"./toEmitMatchedValue.js\";\nimport { toEmitNext } from \"./toEmitNext.js\";\nimport { toEmitValue } from \"./toEmitValue.js\";\nimport { toEmitValueStrict } from \"./toEmitValueStrict.js\";\nimport { toEqualApolloQueryResult } from \"./toEqualApolloQueryResult.js\";\nimport { toEqualFetchResult } from \"./toEqualFetchResult.js\";\nimport { toEqualQueryResult } from \"./toEqualQueryResult.js\";\n\nexpect.extend({\n toComplete,\n toEmitApolloQueryResult,\n toEmitAnything,\n toEmitError,\n toEmitFetchResult,\n toEmitMatchedValue,\n toEmitNext,\n toEmitValue,\n toEmitValueStrict,\n toEqualApolloQueryResult,\n toEqualFetchResult,\n toEqualQueryResult,\n toBeDisposed,\n toHaveSuspenseCacheEntryUsing,\n toMatchDocument,\n toBeGarbageCollected,\n});\n"]}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user