@automattic/vip 4.1.6 → 4.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/dev-env.lando.template.yml.ejs +1 -1
- package/dist/bin/vip-app-deploy-token-generate.js +110 -78
- package/dist/bin/vip-app-deploy-token.js +24 -16
- package/dist/bin/vip-app-deploy-validate.js +45 -41
- package/dist/bin/vip-app-deploy.js +222 -215
- package/dist/bin/vip-app-list.js +59 -43
- package/dist/bin/vip-app.js +97 -66
- package/dist/bin/vip-backup-db.js +36 -29
- package/dist/bin/vip-backup.js +16 -9
- package/dist/bin/vip-cache-purge-url.js +93 -55
- package/dist/bin/vip-cache.js +23 -14
- package/dist/bin/vip-config-envvar-delete.js +74 -73
- package/dist/bin/vip-config-envvar-get-all.js +68 -68
- package/dist/bin/vip-config-envvar-get.js +46 -46
- package/dist/bin/vip-config-envvar-list.js +54 -57
- package/dist/bin/vip-config-envvar-set.js +102 -96
- package/dist/bin/vip-config-envvar.js +38 -24
- package/dist/bin/vip-config-software-get.js +88 -75
- package/dist/bin/vip-config-software-update.js +116 -120
- package/dist/bin/vip-config-software.js +31 -21
- package/dist/bin/vip-config.js +25 -17
- package/dist/bin/vip-db-phpmyadmin.js +40 -39
- package/dist/bin/vip-db.js +13 -12
- package/dist/bin/vip-defensive-mode-configure.js +197 -197
- package/dist/bin/vip-defensive-mode-disable.js +43 -35
- package/dist/bin/vip-defensive-mode-enable.js +47 -38
- package/dist/bin/vip-defensive-mode.js +28 -17
- package/dist/bin/vip-dev-env-create.js +147 -104
- package/dist/bin/vip-dev-env-destroy.js +48 -39
- package/dist/bin/vip-dev-env-envvar-delete.js +60 -49
- package/dist/bin/vip-dev-env-envvar-get-all.js +52 -45
- package/dist/bin/vip-dev-env-envvar-get.js +48 -37
- package/dist/bin/vip-dev-env-envvar-list.js +48 -41
- package/dist/bin/vip-dev-env-envvar-set.js +83 -70
- package/dist/bin/vip-dev-env-envvar.js +38 -23
- package/dist/bin/vip-dev-env-exec.js +81 -74
- package/dist/bin/vip-dev-env-import-media.js +34 -26
- package/dist/bin/vip-dev-env-import-sql.js +65 -51
- package/dist/bin/vip-dev-env-import.js +23 -14
- package/dist/bin/vip-dev-env-info.js +59 -50
- package/dist/bin/vip-dev-env-list.js +34 -31
- package/dist/bin/vip-dev-env-logs.js +59 -49
- package/dist/bin/vip-dev-env-purge.js +71 -63
- package/dist/bin/vip-dev-env-shell.js +82 -71
- package/dist/bin/vip-dev-env-start.js +77 -65
- package/dist/bin/vip-dev-env-stop.js +80 -74
- package/dist/bin/vip-dev-env-sync-sql.js +80 -72
- package/dist/bin/vip-dev-env-sync.js +18 -11
- package/dist/bin/vip-dev-env-update.js +93 -84
- package/dist/bin/vip-dev-env.js +25 -8
- package/dist/bin/vip-edge-workers-build.js +82 -54
- package/dist/bin/vip-edge-workers-delete.js +84 -52
- package/dist/bin/vip-edge-workers-deploy.js +186 -126
- package/dist/bin/vip-edge-workers-disable.js +75 -44
- package/dist/bin/vip-edge-workers-enable.js +86 -54
- package/dist/bin/vip-edge-workers-get.js +108 -88
- package/dist/bin/vip-edge-workers-init.js +83 -53
- package/dist/bin/vip-edge-workers-list.js +89 -54
- package/dist/bin/vip-edge-workers-new.js +98 -69
- package/dist/bin/vip-edge-workers-validate.js +123 -82
- package/dist/bin/vip-edge-workers.js +19 -6
- package/dist/bin/vip-export-sql.js +75 -69
- package/dist/bin/vip-export.js +12 -7
- package/dist/bin/vip-import-media-abort.js +99 -73
- package/dist/bin/vip-import-media-status.js +83 -51
- package/dist/bin/vip-import-media.js +165 -166
- package/dist/bin/vip-import-sql-status.js +75 -45
- package/dist/bin/vip-import-sql.js +536 -596
- package/dist/bin/vip-import-validate-files.js +122 -141
- package/dist/bin/vip-import-validate-sql.js +52 -16
- package/dist/bin/vip-import.js +16 -7
- package/dist/bin/vip-logout.js +17 -13
- package/dist/bin/vip-logs.js +209 -183
- package/dist/bin/vip-search-replace.js +85 -53
- package/dist/bin/vip-slowlogs.js +168 -147
- package/dist/bin/vip-sync.js +163 -133
- package/dist/bin/vip-whoami.js +71 -35
- package/dist/bin/vip-wp.js +506 -549
- package/dist/bin/vip.js +161 -116
- package/dist/commands/backup-db.js +183 -149
- package/dist/commands/dev-env-import-sql.js +162 -117
- package/dist/commands/dev-env-sync-sql.js +372 -330
- package/dist/commands/export-sql.js +441 -425
- package/dist/commands/phpmyadmin.js +232 -212
- package/dist/commands/wp-ssh.js +218 -187
- package/dist/lib/analytics/clients/tracks.js +84 -91
- package/dist/lib/analytics/index.js +27 -27
- package/dist/lib/api/app.js +37 -36
- package/dist/lib/api/cache-purge.js +17 -20
- package/dist/lib/api/constants.js +5 -6
- package/dist/lib/api/edge-workers.js +84 -135
- package/dist/lib/api/error-debug.js +10 -13
- package/dist/lib/api/feature-flags.js +16 -17
- package/dist/lib/api/http.js +47 -48
- package/dist/lib/api/user.js +17 -18
- package/dist/lib/api.js +107 -116
- package/dist/lib/app-logs/app-logs.js +24 -25
- package/dist/lib/app-slowlogs/app-slowlogs.js +23 -24
- package/dist/lib/app-slowlogs/types.js +2 -1
- package/dist/lib/app.js +6 -8
- package/dist/lib/backup-storage-availability/backup-storage-availability.js +119 -119
- package/dist/lib/backup-storage-availability/docker-machine-not-found-error.js +5 -6
- package/dist/lib/cli/apiConfig.js +71 -41
- package/dist/lib/cli/command.js +1120 -873
- package/dist/lib/cli/config.js +29 -29
- package/dist/lib/cli/envAlias.js +35 -50
- package/dist/lib/cli/exit.js +19 -19
- package/dist/lib/cli/format.js +172 -172
- package/dist/lib/cli/progress.js +193 -236
- package/dist/lib/cli/prompt.js +14 -15
- package/dist/lib/cli/runtime-mode.js +5 -6
- package/dist/lib/client-file-uploader.js +489 -641
- package/dist/lib/config/software.js +206 -212
- package/dist/lib/constants/dev-environment.js +40 -37
- package/dist/lib/constants/file-size.js +6 -7
- package/dist/lib/constants/vipgo.js +24 -12
- package/dist/lib/custom-deploy/custom-deploy.js +138 -120
- package/dist/lib/database.js +88 -85
- package/dist/lib/defensive-mode/api.js +41 -46
- package/dist/lib/defensive-mode/cli-helpers.js +40 -40
- package/dist/lib/dev-environment/dev-environment-cli.js +776 -735
- package/dist/lib/dev-environment/dev-environment-configuration-file.js +224 -191
- package/dist/lib/dev-environment/dev-environment-core.js +697 -732
- package/dist/lib/dev-environment/dev-environment-database.js +57 -41
- package/dist/lib/dev-environment/dev-environment-lando.js +734 -666
- package/dist/lib/dev-environment/docker-utils.js +96 -90
- package/dist/lib/dev-environment/env-vars.js +61 -59
- package/dist/lib/dev-environment/lando-loader.js +6 -7
- package/dist/lib/dev-environment/types.js +2 -1
- package/dist/lib/edge-workers/confirmation.js +42 -36
- package/dist/lib/edge-workers/deployment.js +150 -159
- package/dist/lib/edge-workers/index.js +68 -85
- package/dist/lib/edge-workers/location.js +26 -26
- package/dist/lib/edge-workers/output.js +14 -15
- package/dist/lib/edge-workers/project.js +123 -132
- package/dist/lib/edge-workers/toolchains/assemblyscript/constants.js +6 -8
- package/dist/lib/edge-workers/toolchains/assemblyscript/index.js +100 -101
- package/dist/lib/edge-workers/toolchains/assemblyscript/templates.js +31 -33
- package/dist/lib/edge-workers/toolchains/index.js +15 -15
- package/dist/lib/edge-workers/types.js +10 -38
- package/dist/lib/edge-workers/validation.js +161 -150
- package/dist/lib/env.js +16 -17
- package/dist/lib/envvar/api-delete.js +16 -18
- package/dist/lib/envvar/api-get-all.js +15 -19
- package/dist/lib/envvar/api-get.js +8 -9
- package/dist/lib/envvar/api-list.js +16 -21
- package/dist/lib/envvar/api-set.js +20 -19
- package/dist/lib/envvar/api.js +34 -29
- package/dist/lib/envvar/input.js +29 -34
- package/dist/lib/envvar/logging.js +9 -11
- package/dist/lib/envvar/read-file.js +6 -7
- package/dist/lib/http/download-file.js +76 -44
- package/dist/lib/http/proxy-agent.js +37 -40
- package/dist/lib/http/proxy-dispatcher.js +69 -71
- package/dist/lib/keychain/insecure.js +40 -36
- package/dist/lib/keychain/keychain.js +2 -1
- package/dist/lib/keychain/secure.js +16 -15
- package/dist/lib/keychain.js +22 -22
- package/dist/lib/live-backup-copy.js +117 -115
- package/dist/lib/logout.js +17 -19
- package/dist/lib/media-import/config.js +15 -14
- package/dist/lib/media-import/media-file-import.js +9 -13
- package/dist/lib/media-import/progress.js +53 -65
- package/dist/lib/media-import/status.js +241 -256
- package/dist/lib/media-import/utils.js +15 -15
- package/dist/lib/node-version-check.js +16 -16
- package/dist/lib/promise.js +16 -17
- package/dist/lib/read-file.js +48 -16
- package/dist/lib/rechallenge/client.js +37 -43
- package/dist/lib/rechallenge/errors.js +38 -37
- package/dist/lib/rechallenge/flow.js +148 -123
- package/dist/lib/rechallenge/index.js +23 -24
- package/dist/lib/rechallenge/link.js +153 -151
- package/dist/lib/rechallenge/open-browser.js +14 -17
- package/dist/lib/rechallenge/token-cache.js +83 -86
- package/dist/lib/rechallenge/types.js +5 -14
- package/dist/lib/retry.js +93 -129
- package/dist/lib/search-and-replace.js +164 -148
- package/dist/lib/site-import/db-file-import.js +12 -16
- package/dist/lib/site-import/status.js +291 -291
- package/dist/lib/token.js +86 -87
- package/dist/lib/tracker.js +51 -62
- package/dist/lib/types/graphql/rate-limit-exceeded-error.js +2 -1
- package/dist/lib/types.js +2 -1
- package/dist/lib/user-error.js +6 -8
- package/dist/lib/utils.js +81 -87
- package/dist/lib/validations/custom-deploy.js +218 -186
- package/dist/lib/validations/is-multi-site-sql-dump.js +6 -6
- package/dist/lib/validations/is-multi-site.js +83 -50
- package/dist/lib/validations/is-multisite-domain-mapped.js +92 -62
- package/dist/lib/validations/line-by-line.js +78 -46
- package/dist/lib/validations/site-type.js +59 -63
- package/dist/lib/validations/sql-insert-parser.js +415 -0
- package/dist/lib/validations/sql.js +551 -431
- package/dist/lib/validations/utils.js +27 -29
- package/dist/lib/vip-import-validate-files.js +481 -490
- package/dist/lib/wp/helpers.js +41 -45
- package/dist/lib/wp/readline.js +21 -57
- package/dist/lib/xdg-data.js +11 -12
- package/helpers/mark-cli-executable.js +9 -0
- package/node_modules/@apollo/client/CHANGELOG.md +10 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs +5 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/helpers.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs +2 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs +14 -2
- package/node_modules/@apollo/client/__cjs/cache/inmemory/key-extractor.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs +16 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/cache/inmemory/policies.d.cts +2 -0
- package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs +3 -2
- package/node_modules/@apollo/client/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs +9 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryInfo.d.cts +1 -1
- package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs +10 -3
- package/node_modules/@apollo/client/__cjs/core/QueryManager.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/node_modules/@apollo/client/__cjs/react/hooks/useFragment.d.cts +42 -43
- package/node_modules/@apollo/client/__cjs/version.cjs +1 -1
- package/node_modules/@apollo/client/cache/inmemory/helpers.js +5 -0
- package/node_modules/@apollo/client/cache/inmemory/helpers.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js +2 -1
- package/node_modules/@apollo/client/cache/inmemory/inMemoryCache.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/key-extractor.js +14 -2
- package/node_modules/@apollo/client/cache/inmemory/key-extractor.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/policies.d.ts +2 -0
- package/node_modules/@apollo/client/cache/inmemory/policies.js +17 -1
- package/node_modules/@apollo/client/cache/inmemory/policies.js.map +1 -1
- package/node_modules/@apollo/client/cache/inmemory/writeToStore.js +3 -2
- package/node_modules/@apollo/client/cache/inmemory/writeToStore.js.map +1 -1
- package/node_modules/@apollo/client/core/QueryInfo.d.ts +1 -1
- package/node_modules/@apollo/client/core/QueryInfo.js +10 -2
- package/node_modules/@apollo/client/core/QueryInfo.js.map +1 -1
- package/node_modules/@apollo/client/core/QueryManager.js +10 -3
- package/node_modules/@apollo/client/core/QueryManager.js.map +1 -1
- package/node_modules/@apollo/client/package.json +1 -1
- package/node_modules/@apollo/client/react/hooks/useFragment.d.ts +42 -43
- package/node_modules/@apollo/client/react/hooks/useFragment.js.map +1 -1
- package/node_modules/@apollo/client/react/hooks-compiled/useFragment.d.ts +42 -43
- package/node_modules/@apollo/client/react/hooks-compiled/useFragment.js.map +1 -1
- package/node_modules/@apollo/client/version.js +1 -1
- package/node_modules/@automattic/vip-search-replace/README.md +6 -1
- package/node_modules/@automattic/vip-search-replace/lib/index.js +46 -14
- package/node_modules/@automattic/vip-search-replace/package.json +1 -1
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/zlib.d.ts +752 -0
- package/node_modules/check-disk-space/README.md +92 -32
- package/node_modules/check-disk-space/dist/check-disk-space.d.mts +58 -0
- package/node_modules/check-disk-space/dist/check-disk-space.mjs +170 -190
- package/node_modules/check-disk-space/package.json +43 -71
- package/node_modules/cpu-features/build/Makefile +2 -2
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/filesystem.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_aarch64_windows.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_arm_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_mips_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_ppc_linux.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_freebsd.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_linux_or_android.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_macos.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/impl_x86_windows.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/stack_line_reader.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpu_features/deps/cpu_features/src/string_view.o.d +1 -1
- package/node_modules/cpu-features/build/Release/.deps/Release/obj.target/cpufeatures/src/binding.o.d +157 -145
- package/node_modules/cpu-features/build/Release/cpufeatures.node +0 -0
- package/node_modules/cpu-features/build/Release/obj.target/cpufeatures/src/binding.o +0 -0
- package/node_modules/cpu-features/build/Release/obj.target/cpufeatures.node +0 -0
- package/node_modules/cpu-features/build/config.gypi +100 -31
- package/node_modules/cpu-features/build/cpufeatures.target.mk +14 -14
- package/node_modules/cpu-features/build/deps/cpu_features/cpu_features.target.mk +14 -14
- package/node_modules/ssh2/lib/protocol/crypto/build/Makefile +2 -2
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d.raw +136 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/sshcrypto.target.mk +14 -14
- package/node_modules/undici/docs/docs/api/Interceptors.md +15 -2
- package/node_modules/undici/lib/dispatcher/client-h2.js +78 -3
- package/node_modules/undici/lib/dispatcher/pool-base.js +20 -3
- package/node_modules/undici/package.json +3 -3
- package/node_modules/undici/types/api.d.ts +1 -1
- package/node_modules/undici/types/utility.d.ts +4 -4
- package/package.json +44 -13
- package/dist/lib/analytics/clients/client.js +0 -1
- package/dist/lib/analytics/clients/pendo.js +0 -78
- package/helpers/check-version.js +0 -16
- package/node_modules/check-disk-space/dist/check-disk-space.cjs +0 -210
- package/node_modules/check-disk-space/dist/check-disk-space.d.ts +0 -53
- package/node_modules/fetch-retry/.eslintignore +0 -1
- package/node_modules/fetch-retry/.eslintrc.yml +0 -20
- package/node_modules/fetch-retry/.github/workflows/node.js.yml +0 -32
- package/node_modules/fetch-retry/.husky/pre-commit +0 -6
- package/node_modules/fetch-retry/.nycrc.json +0 -24
- package/node_modules/fetch-retry/.travis.yml +0 -3
- package/node_modules/fetch-retry/LICENSE +0 -21
- package/node_modules/fetch-retry/README.md +0 -128
- package/node_modules/fetch-retry/dist/fetch-retry.umd.js +0 -151
- package/node_modules/fetch-retry/index.d.ts +0 -29
- package/node_modules/fetch-retry/index.js +0 -143
- package/node_modules/fetch-retry/package.json +0 -41
- package/node_modules/fetch-retry/rollup.config.js +0 -12
- package/node_modules/fetch-retry/test/.eslintrc.yml +0 -7
- package/node_modules/fetch-retry/test/integration/index.js +0 -212
- package/node_modules/fetch-retry/test/integration/mock-api/index.js +0 -42
- package/node_modules/fetch-retry/test/unit/index.js +0 -1169
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto/src/binding.o.d +0 -265
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/obj.target/sshcrypto.node.d +0 -1
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/.deps/Release/sshcrypto.node.d +0 -1
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto/src/binding.o +0 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/obj.target/sshcrypto.node +0 -0
- package/node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node +0 -0
|
@@ -1,1169 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var fetchBuilder = require('../../');
|
|
3
|
-
var sinon = require('sinon');
|
|
4
|
-
var expect = require('expectations');
|
|
5
|
-
|
|
6
|
-
describe('fetchBuilder', function () {
|
|
7
|
-
|
|
8
|
-
it('throws when fetch is not a function', function () {
|
|
9
|
-
expect(function () {
|
|
10
|
-
fetchBuilder();
|
|
11
|
-
}).toThrow({
|
|
12
|
-
name: 'ArgumentError',
|
|
13
|
-
message: 'fetch must be a function'
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('throws when default is not an object', function () {
|
|
18
|
-
expect(function () {
|
|
19
|
-
fetchBuilder(function () { }, 'this is a string, not an object');
|
|
20
|
-
}).toThrow({
|
|
21
|
-
name: 'ArgumentError',
|
|
22
|
-
message: 'defaults must be an object'
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('returns fetchRetry when provided valid constructor arguments', function () {
|
|
27
|
-
expect(typeof fetchBuilder(function () { }, {retries: 1})).toBe('function');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('fetch-retry', function () {
|
|
32
|
-
|
|
33
|
-
var fetch;
|
|
34
|
-
var fetchRetry;
|
|
35
|
-
|
|
36
|
-
var deferred1;
|
|
37
|
-
var deferred2;
|
|
38
|
-
var deferred3;
|
|
39
|
-
var deferred4;
|
|
40
|
-
|
|
41
|
-
var thenCallback;
|
|
42
|
-
var catchCallback;
|
|
43
|
-
|
|
44
|
-
var clock;
|
|
45
|
-
var delay;
|
|
46
|
-
|
|
47
|
-
beforeEach(function () {
|
|
48
|
-
delay = 1000;
|
|
49
|
-
clock = sinon.useFakeTimers();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
afterEach(function () {
|
|
53
|
-
clock.restore();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
beforeEach(function () {
|
|
57
|
-
deferred1 = defer();
|
|
58
|
-
deferred2 = defer();
|
|
59
|
-
deferred3 = defer();
|
|
60
|
-
deferred4 = defer();
|
|
61
|
-
|
|
62
|
-
fetch = sinon.stub();
|
|
63
|
-
fetch.onCall(0).returns(deferred1.promise);
|
|
64
|
-
fetch.onCall(1).returns(deferred2.promise);
|
|
65
|
-
fetch.onCall(2).returns(deferred3.promise);
|
|
66
|
-
fetch.onCall(3).returns(deferred4.promise);
|
|
67
|
-
|
|
68
|
-
fetchRetry = fetchBuilder(fetch);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('#input', function () {
|
|
72
|
-
|
|
73
|
-
var expectedUrl = 'http://some-url.com';
|
|
74
|
-
|
|
75
|
-
beforeEach(function () {
|
|
76
|
-
fetchRetry(expectedUrl);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('passes #input to fetch', function () {
|
|
80
|
-
expect(fetch.getCall(0).args[0]).toBe(expectedUrl);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe('#init', function () {
|
|
86
|
-
|
|
87
|
-
describe('when #init is provided', function () {
|
|
88
|
-
|
|
89
|
-
var init;
|
|
90
|
-
|
|
91
|
-
beforeEach(function () {
|
|
92
|
-
init = {
|
|
93
|
-
retries: 3,
|
|
94
|
-
whatever: 'something'
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
fetchRetry('http://someUrl', init);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('passes init to fetch', function () {
|
|
101
|
-
expect(fetch.getCall(0).args[1]).toEqual(init);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('when #init.retryOn is not an array or function', () => {
|
|
105
|
-
|
|
106
|
-
it('throws exception', () => {
|
|
107
|
-
expect(function () {
|
|
108
|
-
init.retryOn = 503;
|
|
109
|
-
fetchRetry('http://someUrl', init);
|
|
110
|
-
}).toThrow({
|
|
111
|
-
name: 'ArgumentError',
|
|
112
|
-
message: 'retryOn property expects an array or function'
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
describe('when #init is undefined or null', function () {
|
|
121
|
-
|
|
122
|
-
[undefined, null].forEach(function (testCase) {
|
|
123
|
-
|
|
124
|
-
beforeEach(function () {
|
|
125
|
-
fetchRetry('http://someUrl', testCase);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('does not pass through init to fetch', function () {
|
|
129
|
-
expect(fetch.getCall(0).args[1]).toEqual(undefined);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe('#init.retries', function () {
|
|
139
|
-
|
|
140
|
-
describe('when #init.retries=3 (default)', function () {
|
|
141
|
-
|
|
142
|
-
beforeEach(function () {
|
|
143
|
-
thenCallback = sinon.spy();
|
|
144
|
-
catchCallback = sinon.spy();
|
|
145
|
-
|
|
146
|
-
fetchRetry('http://someurl')
|
|
147
|
-
.then(thenCallback)
|
|
148
|
-
.catch(catchCallback);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('when first call is a success', function () {
|
|
152
|
-
|
|
153
|
-
beforeEach(function () {
|
|
154
|
-
deferred1.resolve({ status: 200 });
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe('when resolved', function () {
|
|
158
|
-
|
|
159
|
-
it('invokes the then callback', function () {
|
|
160
|
-
expect(thenCallback.called).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('calls fetch once', function () {
|
|
164
|
-
expect(fetch.callCount).toBe(1);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe('when first call is a failure', function () {
|
|
172
|
-
|
|
173
|
-
beforeEach(function () {
|
|
174
|
-
deferred1.reject();
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe('when second call is a success', function () {
|
|
178
|
-
|
|
179
|
-
beforeEach(function () {
|
|
180
|
-
clock.tick(delay);
|
|
181
|
-
deferred2.resolve({ status: 200 });
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe('when resolved', function () {
|
|
185
|
-
|
|
186
|
-
it('invokes the then callback', function () {
|
|
187
|
-
expect(thenCallback.called).toBe(true);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it('calls fetch twice', function () {
|
|
191
|
-
expect(fetch.callCount).toBe(2);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('when second call is a failure', function () {
|
|
199
|
-
|
|
200
|
-
beforeEach(function () {
|
|
201
|
-
deferred2.reject();
|
|
202
|
-
clock.tick(delay);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe('when third call is a success', function () {
|
|
206
|
-
|
|
207
|
-
beforeEach(function () {
|
|
208
|
-
deferred3.resolve({ status: 200 });
|
|
209
|
-
clock.tick(delay);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('when resolved', function () {
|
|
213
|
-
|
|
214
|
-
it('invokes the then callback', function () {
|
|
215
|
-
expect(thenCallback.called).toBe(true);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('calls fetch three times', function () {
|
|
219
|
-
expect(fetch.callCount).toBe(3);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe('when third call is a failure', function () {
|
|
227
|
-
|
|
228
|
-
beforeEach(function () {
|
|
229
|
-
deferred3.reject();
|
|
230
|
-
clock.tick(delay);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
describe('when fourth call is a success', function () {
|
|
234
|
-
|
|
235
|
-
beforeEach(function () {
|
|
236
|
-
deferred4.resolve({ status: 200 });
|
|
237
|
-
clock.tick(delay);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
describe('when resolved', function () {
|
|
241
|
-
|
|
242
|
-
it('invokes the then callback', function () {
|
|
243
|
-
expect(thenCallback.called).toBe(true);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('calls fetch four times', function () {
|
|
247
|
-
expect(fetch.callCount).toBe(4);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
describe('when fourth call is a failure', function () {
|
|
255
|
-
|
|
256
|
-
beforeEach(function () {
|
|
257
|
-
deferred4.reject();
|
|
258
|
-
clock.tick(delay);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
describe('when rejected', function () {
|
|
262
|
-
|
|
263
|
-
it('invokes the catch callback', function () {
|
|
264
|
-
expect(catchCallback.called).toBe(true);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('does not call fetch again', function () {
|
|
268
|
-
expect(fetch.callCount).toBe(4);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
describe('when #defaults.retries is not a a positive integer', () => {
|
|
284
|
-
['1', -1, 'not a number', null].forEach(invalidRetries => {
|
|
285
|
-
it('throws error', () => {
|
|
286
|
-
const expectedError = {
|
|
287
|
-
name: 'ArgumentError',
|
|
288
|
-
message: 'retries must be a positive integer'
|
|
289
|
-
};
|
|
290
|
-
expect(() => {
|
|
291
|
-
var fetchRetryWithDefaults = fetchBuilder(fetch, {retries: invalidRetries});
|
|
292
|
-
fetchRetryWithDefaults('http://someurl');
|
|
293
|
-
}).toThrow(expectedError);
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
describe('when #defaults.retryDelay is not a a positive integer', () => {
|
|
299
|
-
|
|
300
|
-
['1', -1, 'not a number', null].forEach(invalidDelay => {
|
|
301
|
-
|
|
302
|
-
it('throws error', () => {
|
|
303
|
-
const expectedError = {
|
|
304
|
-
name: 'ArgumentError',
|
|
305
|
-
message: 'retryDelay must be a positive integer or a function returning a positive integer'
|
|
306
|
-
};
|
|
307
|
-
expect(() => {
|
|
308
|
-
var fetchRetryWithDefaults = fetchBuilder(fetch, { retryDelay: invalidDelay });
|
|
309
|
-
fetchRetryWithDefaults('http://someurl');
|
|
310
|
-
}).toThrow(expectedError);
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
describe('when #defaults.retryDelay is a function', function () {
|
|
318
|
-
|
|
319
|
-
var defaults;
|
|
320
|
-
var retryDelay;
|
|
321
|
-
|
|
322
|
-
beforeEach(function () {
|
|
323
|
-
retryDelay = sinon.stub().returns(5000);
|
|
324
|
-
defaults = {
|
|
325
|
-
retryDelay: retryDelay
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
thenCallback = sinon.spy();
|
|
329
|
-
|
|
330
|
-
var fetchRetryWithDefaults = fetchBuilder(fetch, defaults);
|
|
331
|
-
fetchRetryWithDefaults('http://someUrl')
|
|
332
|
-
.then(thenCallback);
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
describe('when #defaults.retryOn is not an array or function', function () {
|
|
337
|
-
|
|
338
|
-
var defaults = {};
|
|
339
|
-
|
|
340
|
-
describe('when #defaults.retryOn is not an array or function', () => {
|
|
341
|
-
|
|
342
|
-
it('throws exception', () => {
|
|
343
|
-
expect(function () {
|
|
344
|
-
defaults.retryOn = 503;
|
|
345
|
-
var fetchRetryWithDefaults = fetchBuilder(fetch, defaults);
|
|
346
|
-
fetchRetryWithDefaults('http://someUrl');
|
|
347
|
-
}).toThrow({
|
|
348
|
-
name: 'ArgumentError',
|
|
349
|
-
message: 'retryOn property expects an array or function'
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
describe('when #defaults.retries=0', function () {
|
|
358
|
-
beforeEach(function () {
|
|
359
|
-
thenCallback = sinon.spy();
|
|
360
|
-
catchCallback = sinon.spy();
|
|
361
|
-
|
|
362
|
-
var fetchRetryWithDefaults = fetchBuilder(fetch, {retries: 0});
|
|
363
|
-
|
|
364
|
-
fetchRetryWithDefaults('http://someurl')
|
|
365
|
-
.then(thenCallback)
|
|
366
|
-
.catch(catchCallback);
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
describe('when first call is a failure', function () {
|
|
370
|
-
beforeEach(function () {
|
|
371
|
-
deferred1.reject();
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
describe('when rejected', function () {
|
|
375
|
-
|
|
376
|
-
it('invokes the catch callback', function () {
|
|
377
|
-
expect(catchCallback.called).toBe(true);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
it('does not call fetch again', function () {
|
|
381
|
-
expect(fetch.callCount).toBe(1);
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
describe('when #init.retries=1', function () {
|
|
388
|
-
|
|
389
|
-
beforeEach(function () {
|
|
390
|
-
thenCallback = sinon.spy();
|
|
391
|
-
catchCallback = sinon.spy();
|
|
392
|
-
|
|
393
|
-
fetchRetry('http://someurl', { retries: 1 })
|
|
394
|
-
.then(thenCallback)
|
|
395
|
-
.catch(catchCallback);
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
describe('when first call is a success', function () {
|
|
399
|
-
|
|
400
|
-
beforeEach(function () {
|
|
401
|
-
deferred1.resolve({ status: 200 });
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
describe('when resolved', function () {
|
|
405
|
-
|
|
406
|
-
it('invokes the then callback', function () {
|
|
407
|
-
expect(thenCallback.called).toBe(true);
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
it('calls fetch once', function () {
|
|
411
|
-
expect(fetch.callCount).toBe(1);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
describe('when first call is a failure', function () {
|
|
419
|
-
|
|
420
|
-
beforeEach(function () {
|
|
421
|
-
deferred1.reject();
|
|
422
|
-
clock.tick(delay);
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
describe('when second call is a success', function () {
|
|
426
|
-
|
|
427
|
-
beforeEach(function () {
|
|
428
|
-
deferred2.resolve({ status: 200 });
|
|
429
|
-
clock.tick(delay);
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
describe('when resolved', function () {
|
|
433
|
-
|
|
434
|
-
it('invokes the then callback', function () {
|
|
435
|
-
expect(thenCallback.called).toBe(true);
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
it('calls fetch twice', function () {
|
|
439
|
-
expect(fetch.callCount).toBe(2);
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
describe('when second call is a failure', function () {
|
|
447
|
-
|
|
448
|
-
beforeEach(function () {
|
|
449
|
-
deferred2.reject();
|
|
450
|
-
clock.tick(delay);
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
describe('when rejected', function () {
|
|
454
|
-
|
|
455
|
-
it('invokes the catch callback', function () {
|
|
456
|
-
expect(catchCallback.called).toBe(true);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it('does not call fetch again', function () {
|
|
460
|
-
expect(fetch.callCount).toBe(2);
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
describe('when #init.retries=0', function () {
|
|
472
|
-
|
|
473
|
-
beforeEach(function () {
|
|
474
|
-
thenCallback = sinon.spy();
|
|
475
|
-
catchCallback = sinon.spy();
|
|
476
|
-
|
|
477
|
-
fetchRetry('http://someurl', { retries: 0 })
|
|
478
|
-
.then(thenCallback)
|
|
479
|
-
.catch(catchCallback);
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
describe('when first call is a success', function () {
|
|
483
|
-
|
|
484
|
-
beforeEach(function () {
|
|
485
|
-
deferred1.resolve({ status: 200 });
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
describe('when resolved', function () {
|
|
489
|
-
|
|
490
|
-
it('invokes the then callback', function () {
|
|
491
|
-
expect(thenCallback.called).toBe(true);
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it('calls fetch once', function () {
|
|
495
|
-
expect(fetch.callCount).toBe(1);
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
describe('when first call is a failure', function () {
|
|
503
|
-
|
|
504
|
-
beforeEach(function () {
|
|
505
|
-
deferred1.reject();
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
describe('when rejected', () => {
|
|
509
|
-
|
|
510
|
-
it('invokes the catch callback', function () {
|
|
511
|
-
expect(catchCallback.called).toBe(true);
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
describe('when #init.retries is not a a positive integer', () => {
|
|
521
|
-
|
|
522
|
-
['1', -1, 'not a number', null].forEach(invalidRetries => {
|
|
523
|
-
|
|
524
|
-
it('throws error', () => {
|
|
525
|
-
const expectedError = {
|
|
526
|
-
name: 'ArgumentError',
|
|
527
|
-
message: 'retries must be a positive integer'
|
|
528
|
-
};
|
|
529
|
-
expect(() => {
|
|
530
|
-
fetchRetry('http://someurl', { retries: invalidRetries });
|
|
531
|
-
}).toThrow(expectedError);
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
describe('#init.retryDelay', function () {
|
|
541
|
-
|
|
542
|
-
describe('when #init.retryDelay is a number', function () {
|
|
543
|
-
|
|
544
|
-
var init;
|
|
545
|
-
var retryDelay;
|
|
546
|
-
|
|
547
|
-
beforeEach(function () {
|
|
548
|
-
retryDelay = 5000;
|
|
549
|
-
init = {
|
|
550
|
-
retryDelay: retryDelay
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
thenCallback = sinon.spy();
|
|
554
|
-
|
|
555
|
-
fetchRetry('http://someUrl', init)
|
|
556
|
-
.then(thenCallback);
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
describe('when first call is unsuccessful', function () {
|
|
560
|
-
|
|
561
|
-
beforeEach(function () {
|
|
562
|
-
deferred1.reject();
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
describe('after specified time', function () {
|
|
566
|
-
|
|
567
|
-
beforeEach(function () {
|
|
568
|
-
clock.tick(retryDelay);
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
it('invokes fetch again', function () {
|
|
572
|
-
expect(fetch.callCount).toBe(2);
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
describe('after less than specified time', function () {
|
|
578
|
-
|
|
579
|
-
beforeEach(function () {
|
|
580
|
-
clock.tick(1000);
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
it('does not invoke fetch again', function () {
|
|
584
|
-
expect(fetch.callCount).toBe(1);
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
});
|
|
590
|
-
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
describe('when #init.retryDelay is 0', function () {
|
|
594
|
-
|
|
595
|
-
var init;
|
|
596
|
-
var retryDelay;
|
|
597
|
-
|
|
598
|
-
beforeEach(function () {
|
|
599
|
-
retryDelay = 0;
|
|
600
|
-
init = {
|
|
601
|
-
retryDelay: retryDelay
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
thenCallback = sinon.spy();
|
|
605
|
-
|
|
606
|
-
fetchRetry('http://someUrl', init)
|
|
607
|
-
.then(thenCallback);
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
describe('when first call is unsuccessful', function () {
|
|
611
|
-
|
|
612
|
-
beforeEach(function () {
|
|
613
|
-
deferred1.reject();
|
|
614
|
-
});
|
|
615
|
-
|
|
616
|
-
describe('after one event loop tick', function () {
|
|
617
|
-
|
|
618
|
-
beforeEach(function () {
|
|
619
|
-
clock.tick(0);
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
it('invokes fetch again', function () {
|
|
623
|
-
expect(fetch.callCount).toBe(2);
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
describe('when #init.retryDelay is not a a positive integer', () => {
|
|
633
|
-
|
|
634
|
-
['1', -1, 'not a number', null].forEach(invalidDelay => {
|
|
635
|
-
|
|
636
|
-
it('throws error', () => {
|
|
637
|
-
const expectedError = {
|
|
638
|
-
name: 'ArgumentError',
|
|
639
|
-
message: 'retryDelay must be a positive integer or a function returning a positive integer'
|
|
640
|
-
};
|
|
641
|
-
expect(() => {
|
|
642
|
-
fetchRetry('http://someurl', { retryDelay: invalidDelay });
|
|
643
|
-
}).toThrow(expectedError);
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
describe('when #init.retryDelay is a function', function () {
|
|
651
|
-
|
|
652
|
-
var init;
|
|
653
|
-
var retryDelay;
|
|
654
|
-
|
|
655
|
-
beforeEach(function () {
|
|
656
|
-
retryDelay = sinon.stub().returns(5000);
|
|
657
|
-
init = {
|
|
658
|
-
retryDelay: retryDelay
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
thenCallback = sinon.spy();
|
|
662
|
-
|
|
663
|
-
fetchRetry('http://someUrl', init)
|
|
664
|
-
.then(thenCallback);
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
describe('when first call is unsuccessful', function () {
|
|
668
|
-
|
|
669
|
-
beforeEach(function () {
|
|
670
|
-
deferred1.reject(new Error('first error'));
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
describe('when the second call is a success', function () {
|
|
674
|
-
|
|
675
|
-
beforeEach(function () {
|
|
676
|
-
deferred2.resolve({ status: 200 });
|
|
677
|
-
clock.tick(5000);
|
|
678
|
-
});
|
|
679
|
-
|
|
680
|
-
it('invokes the retryDelay function', function () {
|
|
681
|
-
expect(retryDelay.called).toBe(true);
|
|
682
|
-
expect(retryDelay.lastCall.args[0]).toEqual(0);
|
|
683
|
-
expect(retryDelay.lastCall.args[1].message).toEqual('first error');
|
|
684
|
-
});
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
describe('when second call is a failure', function () {
|
|
690
|
-
|
|
691
|
-
beforeEach(function () {
|
|
692
|
-
deferred2.reject(new Error('second error'));
|
|
693
|
-
clock.tick(5000);
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
describe('when the third call is a success', function () {
|
|
697
|
-
|
|
698
|
-
beforeEach(function () {
|
|
699
|
-
deferred3.resolve({ status: 200 });
|
|
700
|
-
clock.tick(5000);
|
|
701
|
-
});
|
|
702
|
-
|
|
703
|
-
it('invokes the retryDelay function again', function () {
|
|
704
|
-
expect(retryDelay.callCount).toBe(2);
|
|
705
|
-
expect(retryDelay.lastCall.args[0]).toEqual(1);
|
|
706
|
-
expect(retryDelay.lastCall.args[1].message).toEqual('second error');
|
|
707
|
-
});
|
|
708
|
-
|
|
709
|
-
});
|
|
710
|
-
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
});
|
|
714
|
-
|
|
715
|
-
});
|
|
716
|
-
|
|
717
|
-
});
|
|
718
|
-
|
|
719
|
-
describe('#init.retryOn', () => {
|
|
720
|
-
|
|
721
|
-
describe('when #init.retryOn is an array', () => {
|
|
722
|
-
|
|
723
|
-
var init;
|
|
724
|
-
var retryOn;
|
|
725
|
-
|
|
726
|
-
beforeEach(function () {
|
|
727
|
-
retryOn = [503, 404];
|
|
728
|
-
init = {
|
|
729
|
-
retryOn: retryOn
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
thenCallback = sinon.spy();
|
|
733
|
-
catchCallback = sinon.spy();
|
|
734
|
-
|
|
735
|
-
fetchRetry('http://someUrl', init)
|
|
736
|
-
.then(thenCallback)
|
|
737
|
-
.catch((catchCallback));
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
describe('when first fetch is resolved with status code specified in retryOn array', () => {
|
|
741
|
-
|
|
742
|
-
beforeEach(() => {
|
|
743
|
-
deferred1.resolve({ status: 503 });
|
|
744
|
-
});
|
|
745
|
-
|
|
746
|
-
describe('after specified delay', () => {
|
|
747
|
-
|
|
748
|
-
beforeEach(() => {
|
|
749
|
-
clock.tick(delay);
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
it('retries fetch', () => {
|
|
753
|
-
expect(fetch.callCount).toBe(2);
|
|
754
|
-
});
|
|
755
|
-
|
|
756
|
-
describe('when second fetch resolves with a different status code', () => {
|
|
757
|
-
|
|
758
|
-
beforeEach(() => {
|
|
759
|
-
deferred2.resolve({ status: 200 });
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
describe('when resolved', () => {
|
|
763
|
-
|
|
764
|
-
it('invokes the then callback', function () {
|
|
765
|
-
expect(thenCallback.called).toBe(true);
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
it('has called fetch twice', function () {
|
|
769
|
-
expect(fetch.callCount).toBe(2);
|
|
770
|
-
});
|
|
771
|
-
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
});
|
|
777
|
-
|
|
778
|
-
});
|
|
779
|
-
|
|
780
|
-
});
|
|
781
|
-
|
|
782
|
-
describe('when #init.retryOn is a function', function () {
|
|
783
|
-
|
|
784
|
-
var init;
|
|
785
|
-
var retryOn;
|
|
786
|
-
var fetchRetryChain;
|
|
787
|
-
|
|
788
|
-
beforeEach(function () {
|
|
789
|
-
retryOn = sinon.stub();
|
|
790
|
-
init = {
|
|
791
|
-
retryOn: retryOn
|
|
792
|
-
};
|
|
793
|
-
|
|
794
|
-
thenCallback = sinon.spy();
|
|
795
|
-
catchCallback = sinon.spy();
|
|
796
|
-
|
|
797
|
-
fetchRetryChain = fetchRetry('http://someUrl', init)
|
|
798
|
-
.then(thenCallback)
|
|
799
|
-
.catch((catchCallback));
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
describe('when first attempt is rejected due to network error', function () {
|
|
803
|
-
|
|
804
|
-
describe('when #retryOn() returns true', () => {
|
|
805
|
-
|
|
806
|
-
beforeEach(function () {
|
|
807
|
-
retryOn.returns(true);
|
|
808
|
-
deferred1.reject(new Error('first error'));
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
describe('when rejected', function () {
|
|
812
|
-
|
|
813
|
-
it('invokes #retryOn function with an error', function () {
|
|
814
|
-
expect(retryOn.called).toBe(true);
|
|
815
|
-
expect(retryOn.lastCall.args.length).toBe(3);
|
|
816
|
-
expect(retryOn.lastCall.args[0]).toBe(0);
|
|
817
|
-
expect(retryOn.lastCall.args[1] instanceof Error).toBe(true);
|
|
818
|
-
expect(retryOn.lastCall.args[2]).toBe(null);
|
|
819
|
-
});
|
|
820
|
-
|
|
821
|
-
describe('after specified time', function () {
|
|
822
|
-
|
|
823
|
-
beforeEach(function () {
|
|
824
|
-
clock.tick(delay);
|
|
825
|
-
});
|
|
826
|
-
|
|
827
|
-
it('invokes fetch again', function () {
|
|
828
|
-
expect(fetch.callCount).toBe(2);
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
describe('when the second call is unsuccessful', function () {
|
|
832
|
-
|
|
833
|
-
beforeEach(function () {
|
|
834
|
-
deferred2.reject(new Error('second error'));
|
|
835
|
-
clock.tick(delay);
|
|
836
|
-
});
|
|
837
|
-
|
|
838
|
-
describe('when rejected', function () {
|
|
839
|
-
|
|
840
|
-
it('invokes the #retryOn function twice', function () {
|
|
841
|
-
expect(retryOn.callCount).toBe(2);
|
|
842
|
-
expect(retryOn.lastCall.args[0]).toBe(1);
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
});
|
|
846
|
-
|
|
847
|
-
});
|
|
848
|
-
|
|
849
|
-
});
|
|
850
|
-
|
|
851
|
-
});
|
|
852
|
-
|
|
853
|
-
});
|
|
854
|
-
|
|
855
|
-
describe('when #retryOn() returns false', () => {
|
|
856
|
-
|
|
857
|
-
beforeEach(function () {
|
|
858
|
-
retryOn.returns(false);
|
|
859
|
-
deferred1.reject(new Error('first error'));
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
describe('when rejected', function () {
|
|
863
|
-
|
|
864
|
-
it('invokes #retryOn function with an error', function () {
|
|
865
|
-
expect(retryOn.called).toBe(true);
|
|
866
|
-
expect(retryOn.lastCall.args.length).toBe(3);
|
|
867
|
-
expect(retryOn.lastCall.args[0]).toBe(0);
|
|
868
|
-
expect(retryOn.lastCall.args[1] instanceof Error).toBe(true);
|
|
869
|
-
expect(retryOn.lastCall.args[2]).toBe(null);
|
|
870
|
-
});
|
|
871
|
-
|
|
872
|
-
describe('after specified time', function () {
|
|
873
|
-
|
|
874
|
-
beforeEach(function () {
|
|
875
|
-
clock.tick(delay);
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
it('invokes the catch callback', function () {
|
|
879
|
-
expect(catchCallback.called).toBe(true);
|
|
880
|
-
});
|
|
881
|
-
|
|
882
|
-
it('does not call fetch again', function () {
|
|
883
|
-
expect(fetch.callCount).toBe(1);
|
|
884
|
-
});
|
|
885
|
-
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
});
|
|
889
|
-
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
});
|
|
893
|
-
|
|
894
|
-
describe('when first attempt is resolved', function () {
|
|
895
|
-
|
|
896
|
-
describe('when #retryOn() returns true', () => {
|
|
897
|
-
|
|
898
|
-
beforeEach(function () {
|
|
899
|
-
retryOn.returns(true);
|
|
900
|
-
deferred1.resolve({ status: 200 });
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
describe('after specified delay', () => {
|
|
904
|
-
|
|
905
|
-
beforeEach(function () {
|
|
906
|
-
clock.tick(delay);
|
|
907
|
-
});
|
|
908
|
-
|
|
909
|
-
it('calls fetch again', function () {
|
|
910
|
-
expect(fetch.callCount).toBe(2);
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
describe('when second call is resolved', () => {
|
|
914
|
-
|
|
915
|
-
beforeEach(function () {
|
|
916
|
-
deferred2.resolve({ status: 200 });
|
|
917
|
-
clock.tick(delay);
|
|
918
|
-
});
|
|
919
|
-
|
|
920
|
-
it('invokes the #retryOn function with the response', function () {
|
|
921
|
-
expect(retryOn.called).toBe(true);
|
|
922
|
-
expect(retryOn.lastCall.args.length).toBe(3);
|
|
923
|
-
expect(retryOn.lastCall.args[0]).toBe(0);
|
|
924
|
-
expect(retryOn.lastCall.args[1]).toBe(null);
|
|
925
|
-
expect(retryOn.lastCall.args[2]).toEqual({ status: 200 });
|
|
926
|
-
});
|
|
927
|
-
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
});
|
|
931
|
-
|
|
932
|
-
});
|
|
933
|
-
|
|
934
|
-
describe('when #retryOn() returns false', () => {
|
|
935
|
-
|
|
936
|
-
beforeEach(function () {
|
|
937
|
-
retryOn.returns(false);
|
|
938
|
-
deferred1.resolve({ status: 502 });
|
|
939
|
-
});
|
|
940
|
-
|
|
941
|
-
describe('when resolved', () => {
|
|
942
|
-
|
|
943
|
-
it('invokes the then callback', function () {
|
|
944
|
-
expect(thenCallback.called).toBe(true);
|
|
945
|
-
});
|
|
946
|
-
|
|
947
|
-
it('calls fetch 1 time only', function () {
|
|
948
|
-
expect(fetch.callCount).toBe(1);
|
|
949
|
-
});
|
|
950
|
-
|
|
951
|
-
});
|
|
952
|
-
|
|
953
|
-
});
|
|
954
|
-
|
|
955
|
-
});
|
|
956
|
-
|
|
957
|
-
describe('when first attempt is resolved with Promise', function() {
|
|
958
|
-
|
|
959
|
-
describe('when #retryOn() returns Promise with true resolve', () => {
|
|
960
|
-
|
|
961
|
-
beforeEach(function() {
|
|
962
|
-
retryOn.resolves(true);
|
|
963
|
-
deferred1.resolve({ status: 200 });
|
|
964
|
-
});
|
|
965
|
-
|
|
966
|
-
describe('after specified delay', () => {
|
|
967
|
-
|
|
968
|
-
beforeEach(function() {
|
|
969
|
-
clock.tick(delay);
|
|
970
|
-
});
|
|
971
|
-
|
|
972
|
-
it('calls fetch again', function() {
|
|
973
|
-
expect(fetch.callCount).toBe(2);
|
|
974
|
-
});
|
|
975
|
-
|
|
976
|
-
describe('when second call is resolved', () => {
|
|
977
|
-
|
|
978
|
-
beforeEach(function() {
|
|
979
|
-
deferred2.resolve({ status: 200 });
|
|
980
|
-
clock.tick(delay);
|
|
981
|
-
});
|
|
982
|
-
|
|
983
|
-
it('invokes the #retryOn function with the response', function() {
|
|
984
|
-
expect(retryOn.called).toBe(true);
|
|
985
|
-
expect(retryOn.lastCall.args.length).toBe(3);
|
|
986
|
-
expect(retryOn.lastCall.args[0]).toBe(0);
|
|
987
|
-
expect(retryOn.lastCall.args[1]).toBe(null);
|
|
988
|
-
expect(retryOn.lastCall.args[2]).toEqual({ status: 200 });
|
|
989
|
-
});
|
|
990
|
-
|
|
991
|
-
});
|
|
992
|
-
|
|
993
|
-
});
|
|
994
|
-
|
|
995
|
-
});
|
|
996
|
-
|
|
997
|
-
describe('when #retryOn() returns Promise with false resolve', () => {
|
|
998
|
-
|
|
999
|
-
beforeEach(function() {
|
|
1000
|
-
retryOn.resolves(false);
|
|
1001
|
-
deferred1.resolve({ status: 502 });
|
|
1002
|
-
});
|
|
1003
|
-
|
|
1004
|
-
describe('when resolved', () => {
|
|
1005
|
-
|
|
1006
|
-
it('invokes the then callback', function() {
|
|
1007
|
-
expect(thenCallback.called).toBe(true);
|
|
1008
|
-
});
|
|
1009
|
-
|
|
1010
|
-
it('calls fetch 1 time only', function() {
|
|
1011
|
-
expect(fetch.callCount).toBe(1);
|
|
1012
|
-
});
|
|
1013
|
-
|
|
1014
|
-
});
|
|
1015
|
-
|
|
1016
|
-
});
|
|
1017
|
-
|
|
1018
|
-
describe('when #retryOn() throws an error', () => {
|
|
1019
|
-
|
|
1020
|
-
beforeEach(function() {
|
|
1021
|
-
retryOn.throws();
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
describe('when rejected', () => {
|
|
1025
|
-
|
|
1026
|
-
beforeEach(function() {
|
|
1027
|
-
deferred1.reject();
|
|
1028
|
-
});
|
|
1029
|
-
|
|
1030
|
-
it('retryOn called only once', () => {
|
|
1031
|
-
return fetchRetryChain.finally(() => {
|
|
1032
|
-
expect(retryOn.callCount).toBe(1);
|
|
1033
|
-
});
|
|
1034
|
-
});
|
|
1035
|
-
|
|
1036
|
-
it('invokes the catch callback', function() {
|
|
1037
|
-
return fetchRetryChain.finally(() => {
|
|
1038
|
-
expect(catchCallback.called).toBe(true);
|
|
1039
|
-
});
|
|
1040
|
-
});
|
|
1041
|
-
|
|
1042
|
-
it('called fetch', function() {
|
|
1043
|
-
expect(fetch.callCount).toBe(1);
|
|
1044
|
-
});
|
|
1045
|
-
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
|
-
describe('when resolved', () => {
|
|
1049
|
-
|
|
1050
|
-
beforeEach(function() {
|
|
1051
|
-
deferred1.resolve({ status: 200 });
|
|
1052
|
-
});
|
|
1053
|
-
|
|
1054
|
-
it('retryOn called only once', () => {
|
|
1055
|
-
return fetchRetryChain.finally(() => {
|
|
1056
|
-
expect(retryOn.callCount).toBe(1);
|
|
1057
|
-
});
|
|
1058
|
-
});
|
|
1059
|
-
|
|
1060
|
-
it('invokes the catch callback', function() {
|
|
1061
|
-
return fetchRetryChain.finally(() => {
|
|
1062
|
-
expect(catchCallback.called).toBe(true);
|
|
1063
|
-
});
|
|
1064
|
-
});
|
|
1065
|
-
|
|
1066
|
-
it('called fetch', function() {
|
|
1067
|
-
expect(fetch.callCount).toBe(1);
|
|
1068
|
-
});
|
|
1069
|
-
|
|
1070
|
-
});
|
|
1071
|
-
|
|
1072
|
-
});
|
|
1073
|
-
|
|
1074
|
-
describe('when #retryOn() returns a Promise that rejects', () => {
|
|
1075
|
-
|
|
1076
|
-
beforeEach(function() {
|
|
1077
|
-
retryOn.rejects();
|
|
1078
|
-
});
|
|
1079
|
-
|
|
1080
|
-
describe('when rejected', () => {
|
|
1081
|
-
|
|
1082
|
-
beforeEach(function() {
|
|
1083
|
-
deferred1.reject();
|
|
1084
|
-
});
|
|
1085
|
-
|
|
1086
|
-
it('retryOn called only once', () => {
|
|
1087
|
-
return fetchRetryChain.finally(() => {
|
|
1088
|
-
expect(retryOn.callCount).toBe(1);
|
|
1089
|
-
});
|
|
1090
|
-
});
|
|
1091
|
-
|
|
1092
|
-
it('invokes the catch callback', function() {
|
|
1093
|
-
return fetchRetryChain.finally(() => {
|
|
1094
|
-
expect(catchCallback.called).toBe(true);
|
|
1095
|
-
});
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
it('called fetch', function() {
|
|
1099
|
-
expect(fetch.callCount).toBe(1);
|
|
1100
|
-
});
|
|
1101
|
-
|
|
1102
|
-
});
|
|
1103
|
-
describe('when resolved', () => {
|
|
1104
|
-
|
|
1105
|
-
beforeEach(function() {
|
|
1106
|
-
deferred1.resolve({ status: 200 });
|
|
1107
|
-
});
|
|
1108
|
-
|
|
1109
|
-
it('retryOn called only once', () => {
|
|
1110
|
-
return fetchRetryChain.finally(() => {
|
|
1111
|
-
expect(retryOn.callCount).toBe(1);
|
|
1112
|
-
});
|
|
1113
|
-
});
|
|
1114
|
-
|
|
1115
|
-
it('invokes the catch callback', function() {
|
|
1116
|
-
return fetchRetryChain.finally(() => {
|
|
1117
|
-
expect(catchCallback.called).toBe(true);
|
|
1118
|
-
});
|
|
1119
|
-
});
|
|
1120
|
-
|
|
1121
|
-
it('called fetch', function() {
|
|
1122
|
-
expect(fetch.callCount).toBe(1);
|
|
1123
|
-
});
|
|
1124
|
-
|
|
1125
|
-
});
|
|
1126
|
-
|
|
1127
|
-
});
|
|
1128
|
-
|
|
1129
|
-
});
|
|
1130
|
-
|
|
1131
|
-
});
|
|
1132
|
-
|
|
1133
|
-
describe('when #init.retryOn is not an array or function', function () {
|
|
1134
|
-
|
|
1135
|
-
var init;
|
|
1136
|
-
|
|
1137
|
-
describe('when #init.retryOn is not an array or function', () => {
|
|
1138
|
-
|
|
1139
|
-
it('throws exception', () => {
|
|
1140
|
-
expect(function () {
|
|
1141
|
-
init.retryOn = 503;
|
|
1142
|
-
fetchRetry('http://someUrl', init);
|
|
1143
|
-
}).toThrow({
|
|
1144
|
-
name: 'ArgumentError',
|
|
1145
|
-
message: 'retryOn property expects an array or function'
|
|
1146
|
-
});
|
|
1147
|
-
});
|
|
1148
|
-
|
|
1149
|
-
});
|
|
1150
|
-
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
});
|
|
1154
|
-
|
|
1155
|
-
});
|
|
1156
|
-
|
|
1157
|
-
function defer() {
|
|
1158
|
-
var resolve, reject;
|
|
1159
|
-
// eslint-disable-next-line no-undef
|
|
1160
|
-
var promise = new Promise(function () {
|
|
1161
|
-
resolve = arguments[0];
|
|
1162
|
-
reject = arguments[1];
|
|
1163
|
-
});
|
|
1164
|
-
return {
|
|
1165
|
-
resolve: resolve,
|
|
1166
|
-
reject: reject,
|
|
1167
|
-
promise: promise
|
|
1168
|
-
};
|
|
1169
|
-
}
|