Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RStankov
Created November 30, 2020 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RStankov/5c9bb46f0a4e07a3a2e9af19e8738c51 to your computer and use it in GitHub Desktop.
Save RStankov/5c9bb46f0a4e07a3a2e9af19e8738c51 to your computer and use it in GitHub Desktop.
return new ApolloClient({
link: recordRequestsInFlight(
new HttpLink(/* ... */),
),
// ...
});
import { ApolloLink, concat } from 'apollo-link';
import { environment } from '~/config';
declare global {
// tslint:disable-next-line
interface Window {
test: {
apolloRequestsInFlight: number;
};
}
}
let recordRequestsInFlight: any = (networkLink: any) => networkLink;
if (environment.isBrowser && environment.isTest) {
recordRequestsInFlight = (networkLink: any) => {
const recorderLink = new ApolloLink((operation: any, forward: any) => {
window.test.apolloRequestsInFlight += 1;
return forward(operation).map((result: any) => {
window.test.apolloRequestsInFlight -= 1;
return result;
});
});
return concat(recorderLink, networkLink);
};
}
export default recordRequestsInFlight;
# this waits until there are no upcoming XHR request
def wait_for_ajax
Timeout.timeout(Capybara.default_max_wait_time) do
loop while page.evaluate_script('window.test.hasInFlightRequests()')
end
rescue Timeout::Error
# NOTE(rstankov): Some times this fails on CI while code is working
nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment