-
-
Save RStankov/5c9bb46f0a4e07a3a2e9af19e8738c51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return new ApolloClient({ | |
link: recordRequestsInFlight( | |
new HttpLink(/* ... */), | |
), | |
// ... | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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