@shopify/graphql-testing
Advanced tools
Comparing version 8.0.0 to 8.0.1
@@ -21,7 +21,5 @@ 'use strict'; | ||
this.mockLink = null; | ||
this.handleCreate = request => { | ||
this.pendingRequests.add(request); | ||
}; | ||
this.handleResolve = request => { | ||
@@ -31,3 +29,2 @@ this.operations.push(request.operation); | ||
}; | ||
const cache = new client.InMemoryCache(cacheOptions); | ||
@@ -46,3 +43,2 @@ this.mockLink = new mocks.MockLink(mock); | ||
} | ||
update(mock) { | ||
@@ -52,6 +48,4 @@ if (!this.mockLink) { | ||
} | ||
this.mockLink.updateMock(mock); | ||
} | ||
async resolveNext(options = {}) { | ||
@@ -64,6 +58,4 @@ await this.withWrapper(async () => { | ||
} | ||
async resolveAll(options = {}) { | ||
await this.resolveNext(options); | ||
while (this.getMatchingRequests(options).length > 0) { | ||
@@ -73,3 +65,2 @@ await this.resolveNext(options); | ||
} | ||
async waitForQueryUpdates() { | ||
@@ -83,7 +74,5 @@ // queryManager is an internal implementation detail that is a TS-private | ||
} | ||
wrap(wrapper) { | ||
this.wrappers.push(wrapper); | ||
} | ||
getMatchingRequests(options) { | ||
@@ -100,3 +89,2 @@ const requestFilter = Object.keys(options).length ? ({ | ||
} | ||
async withWrapper(cb) { | ||
@@ -109,5 +97,4 @@ await this.wrappers.reduce((perform, wrapper) => { | ||
} | ||
} | ||
exports.GraphQL = GraphQL; |
@@ -12,3 +12,2 @@ 'use strict'; | ||
} | ||
request(operation, nextLink) { | ||
@@ -18,3 +17,2 @@ if (nextLink == null || !nextLink) { | ||
} | ||
let resolver; | ||
@@ -39,3 +37,2 @@ const promise = new Promise(resolve => { | ||
}, | ||
next(result) { | ||
@@ -45,3 +42,2 @@ const next = observer.next.bind(observer, result); | ||
}, | ||
error(error) { | ||
@@ -51,9 +47,7 @@ const fail = observer.error.bind(observer, error); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
exports.InflightLink = InflightLink; |
@@ -13,7 +13,5 @@ 'use strict'; | ||
} | ||
updateMock(mock) { | ||
this.mock = mock; | ||
} | ||
request(operation) { | ||
@@ -28,3 +26,2 @@ return new client.Observable(obs => { | ||
let response = null; | ||
if (typeof mock === 'function') { | ||
@@ -36,15 +33,11 @@ response = mock(operation); | ||
} | ||
let result; | ||
if (response == null || typeof response === 'function') { | ||
let message = `Can’t perform GraphQL operation '${operationName}' because no valid mocks were found`; | ||
if (typeof mock === 'object') { | ||
const operationNames = Object.keys(mock); | ||
const hasOperations = operationNames.length > 0; // We will provide a more helpful message when it looks like they just provided data, | ||
const hasOperations = operationNames.length > 0; | ||
// We will provide a more helpful message when it looks like they just provided data, | ||
// not an object mapping names to fixtures. | ||
const looksLikeDataNotFixtures = hasOperations && operationNames.every(name => name === name.toLowerCase()); | ||
if (typeof response === 'function') { | ||
@@ -63,3 +56,2 @@ message += ' (it looks like you tried to provide a function that returned a function, but the mock should be either an object or a function that retuns an object)'; | ||
} | ||
obs.error(new Error(message)); | ||
@@ -80,3 +72,2 @@ return; | ||
} | ||
obs.next(result); | ||
@@ -86,5 +77,4 @@ obs.complete(); | ||
} | ||
} | ||
exports.MockLink = MockLink; |
@@ -27,3 +27,2 @@ 'use strict'; | ||
} | ||
function diffs(operations, variables, expand) { | ||
@@ -35,3 +34,2 @@ return operations.reduce((diffs, operation, index) => `${diffs}${index === 0 ? '' : '\n\n'}${normalizedDiff(operation, variables, { | ||
} | ||
function normalizedDiff(operation, variables, { | ||
@@ -38,0 +36,0 @@ expand = false, |
@@ -24,4 +24,5 @@ 'use strict'; | ||
}); | ||
} // Original from https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L107 | ||
} | ||
// Original from https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L107 | ||
function getObjectSubset(object, subset) { | ||
@@ -37,3 +38,2 @@ if (Array.isArray(object)) { | ||
Object.keys(subset).filter(key => Reflect.has(object, key)).forEach(key => trimmed[key] = getObjectSubset(object[key], subset[key])); | ||
if (Object.keys(trimmed).length > 0) { | ||
@@ -43,3 +43,2 @@ return trimmed; | ||
} | ||
return object; | ||
@@ -46,0 +45,0 @@ } |
@@ -7,4 +7,2 @@ 'use strict'; | ||
let _Symbol$iterator; | ||
_Symbol$iterator = Symbol.iterator; | ||
class Operations { | ||
@@ -15,23 +13,17 @@ constructor(operations) { | ||
} | ||
[_Symbol$iterator]() { | ||
[Symbol.iterator]() { | ||
return this.operations[Symbol.iterator](); | ||
} | ||
push(...operations) { | ||
this.operations.push(...operations); | ||
} | ||
all(options) { | ||
return this.filterWhere(options); | ||
} | ||
first(options) { | ||
return this.nth(0, options); | ||
} | ||
last(options) { | ||
return this.nth(-1, options); | ||
} | ||
nth(index, options) { | ||
@@ -41,3 +33,2 @@ const found = this.filterWhere(options); | ||
} | ||
filterWhere(options = {}) { | ||
@@ -49,5 +40,4 @@ const finalOperationName = utilities.operationNameFromFindOptions(options); | ||
} | ||
} | ||
exports.Operations = Operations; |
@@ -10,3 +10,2 @@ 'use strict'; | ||
const passedOptions = [query, mutation].filter(Boolean); | ||
if (passedOptions.length === 0) { | ||
@@ -17,3 +16,2 @@ return undefined; | ||
} | ||
return operationNameFromDocument(query || mutation); | ||
@@ -27,3 +25,2 @@ } | ||
} | ||
function operationNameFromDocumentNode(document) { | ||
@@ -35,3 +32,2 @@ const [operation] = document.definitions.filter(({ | ||
} | ||
function operationTypeFromDocumentNode(document) { | ||
@@ -38,0 +34,0 @@ const [operation] = document.definitions.filter(({ |
{ | ||
"name": "@shopify/graphql-testing", | ||
"version": "8.0.0", | ||
"version": "8.0.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Utilities to create mock GraphQL factories", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62378