Skip to content

Commit

Permalink
Adding a test of retrying via the demo
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Sep 15, 2022
1 parent 38447be commit 49069d0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
55 changes: 55 additions & 0 deletions demo/components/axios-retry-test.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!-- Test of axios retrying -->

<template lang='pug'>

.axios-retry-test
| Tried <strong>{{type}}</strong>
| with <strong>{{ code }}</strong> response
| <strong>{{ tries }} time(s)</strong>

</template>

<!-- ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– -->

<script lang='coffee'>
import MockAdapter from 'axios-mock-adapter'
export default
props:
type: String
code: Number
data: -> tries: 0
# Run query using mounted instead of fetch so that the tries count updates
mounted: ->
# Make a clean client to mock
client = @$addAxiosRetry @$axios.create()
# Mock response using passed in code
mock = new MockAdapter client
mock.onAny().reply (config) =>
@tries++
return [@code, {}]
# Trigger request and ignore erros
try await client.post '/example', query: switch @type
when 'query' then '{ id }'
when 'mutation' then 'mutation update() { id }'
catch e
</script>

<!-- ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– -->

<style lang='stylus' scoped>
.axios-retry-test
border 1px solid currentColor
padding 1em
display inline-block
margin-bottom 0.3em
</style>
9 changes: 7 additions & 2 deletions demo/content/demo.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# [@cloak-app/boilerplate](https://github.com/BKWLD/cloak-boilerplate)

## Heya World
## Axios Retrying

Maecenas faucibus mollis interdum. Donec sed odio dui. Sed posuere consectetur est at lobortis. Etiam porta sem malesuada magna mollis euismod. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.
This component mocks the injected Axios method and simulates a requests, counting the number of attempts made. Only the failed query should be retried multiple times.

<axios-retry-test type='query' :code='200'></axios-retry-test>
<axios-retry-test type='query' :code='500'></axios-retry-test>
<axios-retry-test type='mutation' :code='200'></axios-retry-test>
<axios-retry-test type='mutation' :code='500'></axios-retry-test>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"devDependencies": {
"@cloak-app/demo-theme": "^1.0.5",
"@nuxt/content": "^1.14.0",
"axios-mock-adapter": "^1.21.2",
"nuxt": "^2.14.0"
}
}
12 changes: 10 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,14 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==

axios-mock-adapter@^1.21.2:
version "1.21.2"
resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.21.2.tgz#87a48f80aa89bb1ab1ad630fa467975e30aa4721"
integrity sha512-jzyNxU3JzB2XVhplZboUcF0YDs7xuExzoRSHXPHr+UQajaGmcTqvkkUADgkVI2WkGlpZ1zZlMVdcTMU0ejV8zQ==
dependencies:
fast-deep-equal "^3.1.3"
is-buffer "^2.0.5"

axios-retry@^3.1.9:
version "3.2.4"
resolved "https://registry.yarnpkg.com/axios-retry/-/axios-retry-3.2.4.tgz#f447a53c3456f5bfeca18f20c3a3272207d082ae"
Expand Down Expand Up @@ -4348,7 +4356,7 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.1.tgz#8d172c064867f235c0c84a596806d279bf4bcc07"
integrity sha512-Wrk35e8ydCKDj/ArClo1VrPVmN8zph5V4AtHwIuHhvMXsKf73UT3BOD+azBIW+3wOJ4FhEH7zyaJCFvChjYvMA==

fast-deep-equal@^3.1.1:
fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
Expand Down Expand Up @@ -5450,7 +5458,7 @@ is-buffer@^1.1.5:
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

is-buffer@^2.0.0:
is-buffer@^2.0.0, is-buffer@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.5.tgz#ebc252e400d22ff8d77fa09888821a24a658c191"
integrity sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==
Expand Down

0 comments on commit 49069d0

Please sign in to comment.