Skip to content

Commit

Permalink
Make it work for ServerSnapshotTests
Browse files Browse the repository at this point in the history
Reviewed By: jstejada

Differential Revision: D14738428

fbshipit-source-id: dc27cd969b77361ccf4b371cdb26870f8e1bdab6
  • Loading branch information
alunyov authored and facebook-github-bot committed Apr 3, 2019
1 parent 9baa85a commit ed59ab5
Showing 1 changed file with 33 additions and 28 deletions.
61 changes: 33 additions & 28 deletions packages/relay-test-utils/RelayModernMockEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,40 +374,45 @@ function createMockEnvironment(options?: {|
});

const createExecuteProxy = (
env: IEnvironment,
fn:
| $PropertyType<IEnvironment, 'execute'>
| $PropertyType<IEnvironment, 'executeMutation'>,
) =>
new Proxy(fn, {
apply(target, thisArg, argumentsList) {
const [{operation}] = argumentsList;
pendingOperations = pendingOperations.concat([operation]);
return target.apply(thisArg, argumentsList);
},
});
) => {
return (...argumentsList) => {
const [{operation}] = argumentsList;
pendingOperations = pendingOperations.concat([operation]);
return fn.apply(env, argumentsList);
};
};

// $FlowExpectedError
environment.execute = createExecuteProxy(environment.execute);
environment.execute = createExecuteProxy(environment, environment.execute);
// $FlowExpectedError
environment.executeMutation = createExecuteProxy(environment.executeMutation);

// Mock all the functions with their original behavior
mockDisposableMethod(environment, 'applyUpdate');
mockInstanceMethod(environment, 'commitPayload');
mockInstanceMethod(environment, 'getStore');
mockInstanceMethod(environment, 'lookup');
mockInstanceMethod(environment, 'check');
mockDisposableMethod(environment, 'subscribe');
mockDisposableMethod(environment, 'retain');
mockObservableMethod(environment, 'execute');
mockObservableMethod(environment, 'executeMutation');

mockInstanceMethod(store, 'getSource');
mockInstanceMethod(store, 'lookup');
mockInstanceMethod(store, 'notify');
mockInstanceMethod(store, 'publish');
mockDisposableMethod(store, 'retain');
mockDisposableMethod(store, 'subscribe');
environment.executeMutation = createExecuteProxy(
environment,
environment.executeMutation,
);

if (process.env.NODE_ENV === 'test') {
// Mock all the functions with their original behavior
mockDisposableMethod(environment, 'applyUpdate');
mockInstanceMethod(environment, 'commitPayload');
mockInstanceMethod(environment, 'getStore');
mockInstanceMethod(environment, 'lookup');
mockInstanceMethod(environment, 'check');
mockDisposableMethod(environment, 'subscribe');
mockDisposableMethod(environment, 'retain');
mockObservableMethod(environment, 'execute');
mockObservableMethod(environment, 'executeMutation');

mockInstanceMethod(store, 'getSource');
mockInstanceMethod(store, 'lookup');
mockInstanceMethod(store, 'notify');
mockInstanceMethod(store, 'publish');
mockDisposableMethod(store, 'retain');
mockDisposableMethod(store, 'subscribe');
}

const mock: MockFunctions = {
cachePayload,
Expand Down

0 comments on commit ed59ab5

Please sign in to comment.