From b8dd8c812bb17774fb6db4ca7e528461ae8137b0 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2020 17:10:42 -0500 Subject: [PATCH] test: Update got to the latest version and fill in missing coverage (#1825) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(package): update got to version 10.0.0 * chore(package): update lockfile package-lock.json * Bump got again and run npm install * query -> searchParams * encoding -> responseType * `{body: …}` no longer implies `.post()` * auth -> username + password * query -> searchParams * Error now has a `response` property * Couple other fixes * Restore 100% coverage * Update lockfile * refactor(test): use Mocha DSL for allow unmocked (#1894) * refactor(test): use Mocha DSL for allow unmocked * Fix format * baseUrl -> prefixUrl * Update json’s for breaking changes * update usage of prefixUrl. There was a subtle, and I think unnecessary, change in Got 10.x where using `prefixUrl` means the input, when making a request, can no longer have a leading slash. The prefix value can optionally have a trailing slash. https://github.com/sindresorhus/got#prefixurl Co-authored-by: Paul Melnikow Co-authored-by: Matt R. Wilson --- package-lock.json | 239 +++++++++++++++++++---------- package.json | 2 +- tests/test_allow_unmocked.js | 16 +- tests/test_allow_unmocked_https.js | 8 +- tests/test_basic_auth.js | 8 +- tests/test_body_match.js | 3 +- tests/test_define.js | 19 ++- tests/test_intercept.js | 24 +-- tests/test_query.js | 2 +- tests/test_recorder.js | 55 ++++++- tests/test_reply_function_async.js | 4 +- tests/test_reply_function_sync.js | 12 +- tests/test_scope.js | 8 +- 13 files changed, 263 insertions(+), 137 deletions(-) diff --git a/package-lock.json b/package-lock.json index c34101603..8fe258988 100644 --- a/package-lock.json +++ b/package-lock.json @@ -691,9 +691,9 @@ } }, "@sindresorhus/is": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", - "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-1.2.0.tgz", + "integrity": "sha512-mwhXGkRV5dlvQc4EgPDxDxO6WuMBVymGFd1CA+2Y+z5dG9MNspoQ+AWjl/Ld1MnpCL8AKbosZlDVohqcIwuWsw==", "dev": true }, "@sinonjs/commons": { @@ -742,12 +742,12 @@ "dev": true }, "@szmarczak/http-timer": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", - "integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.5.tgz", + "integrity": "sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ==", "dev": true, "requires": { - "defer-to-connect": "^1.0.1" + "defer-to-connect": "^2.0.0" } }, "@tootallnate/once": { @@ -756,12 +756,39 @@ "integrity": "sha512-KYyTT/T6ALPkIRd2Ge080X/BsXvy9O0hcWTtMWkPvwAwF99+vn6Dv4GzrFT/Nn1LePr+FFDbRXXlqmsy9lw2zA==", "dev": true }, + "@types/cacheable-request": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.1.tgz", + "integrity": "sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ==", + "dev": true, + "requires": { + "@types/http-cache-semantics": "*", + "@types/keyv": "*", + "@types/node": "*", + "@types/responselike": "*" + } + }, "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/http-cache-semantics": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz", + "integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A==", + "dev": true + }, + "@types/keyv": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz", + "integrity": "sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/node": { "version": "13.7.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz", @@ -786,6 +813,15 @@ "integrity": "sha512-MoF2IC9oGSgArJwlxdst4XsvWuoYfNUWtBw0kpnCi6K05kV+Ecl7siEeJ40tgCbI9uqEMGQL/NlPMRv6KVkY5Q==", "dev": true }, + "@types/responselike": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", + "integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/retry": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", @@ -1167,19 +1203,28 @@ "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", "dev": true }, + "cacheable-lookup": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-2.0.0.tgz", + "integrity": "sha512-s2piO6LvA7xnL1AR03wuEdSx3BZT3tIJpZ56/lcJwzO/6DTJZlTs7X3lrvPxk6d1PlDe6PrVe2TjlUIZNFglAQ==", + "dev": true, + "requires": { + "keyv": "^4.0.0" + } + }, "cacheable-request": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", - "integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.1.tgz", + "integrity": "sha512-lt0mJ6YAnsrBErpTMWeu5kl/tg9xMAWjavYTN6VQXM1A/teBITuNcccXsCxF0tDQQJf9DfAaX5O4e0zp0KlfZw==", "dev": true, "requires": { "clone-response": "^1.0.2", "get-stream": "^5.1.0", "http-cache-semantics": "^4.0.0", - "keyv": "^3.0.0", + "keyv": "^4.0.0", "lowercase-keys": "^2.0.0", "normalize-url": "^4.1.0", - "responselike": "^1.0.2" + "responselike": "^2.0.0" }, "dependencies": { "get-stream": { @@ -1190,12 +1235,6 @@ "requires": { "pump": "^3.0.0" } - }, - "lowercase-keys": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", - "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", - "dev": true } } }, @@ -1385,6 +1424,14 @@ "dev": true, "requires": { "mimic-response": "^1.0.0" + }, + "dependencies": { + "mimic-response": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", + "dev": true + } } }, "code-point-at": { @@ -1416,7 +1463,7 @@ }, "colors": { "version": "1.0.3", - "resolved": "http://registry.npmjs.org/colors/-/colors-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=", "dev": true }, @@ -1732,12 +1779,12 @@ } }, "decompress-response": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", - "integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-5.0.0.tgz", + "integrity": "sha512-TLZWWybuxWgoW7Lykv+gq9xvzOsUjQ9tF09Tj6NSTYGMTCHNXzrPnD6Hi+TgZq19PyTAGH4Ll/NIM/eTGglnMw==", "dev": true, "requires": { - "mimic-response": "^1.0.0" + "mimic-response": "^2.0.0" } }, "deep-eql": { @@ -1779,9 +1826,9 @@ } }, "defer-to-connect": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz", - "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.0.tgz", + "integrity": "sha512-bYL2d05vOSf1JEZNx5vSAtPuBMkX8K9EUutg7zlKvTqKXHt7RhWJFbmd7qakVuf13i+IkGmp6FwSsONOf6VYIg==", "dev": true }, "define-properties": { @@ -2947,22 +2994,43 @@ } }, "got": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", - "integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", + "version": "10.5.5", + "resolved": "https://registry.npmjs.org/got/-/got-10.5.5.tgz", + "integrity": "sha512-B13HHkCkTA7KxyxTrFoZfrurBX1fZxjMTKpmIfoVzh0Xfs9aZV7xEfI6EKuERQOIPbomh5LE4xDkfK6o2VXksw==", "dev": true, "requires": { - "@sindresorhus/is": "^0.14.0", - "@szmarczak/http-timer": "^1.1.2", - "cacheable-request": "^6.0.0", - "decompress-response": "^3.3.0", + "@sindresorhus/is": "^1.0.0", + "@szmarczak/http-timer": "^4.0.0", + "@types/cacheable-request": "^6.0.1", + "cacheable-lookup": "^2.0.0", + "cacheable-request": "^7.0.1", + "decompress-response": "^5.0.0", "duplexer3": "^0.1.4", - "get-stream": "^4.1.0", - "lowercase-keys": "^1.0.1", - "mimic-response": "^1.0.1", - "p-cancelable": "^1.0.0", - "to-readable-stream": "^1.0.0", - "url-parse-lax": "^3.0.0" + "get-stream": "^5.0.0", + "lowercase-keys": "^2.0.0", + "mimic-response": "^2.0.0", + "p-cancelable": "^2.0.0", + "p-event": "^4.0.0", + "responselike": "^2.0.0", + "to-readable-stream": "^2.0.0", + "type-fest": "^0.9.0" + }, + "dependencies": { + "get-stream": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", + "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", + "dev": true, + "requires": { + "pump": "^3.0.0" + } + }, + "type-fest": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.9.0.tgz", + "integrity": "sha512-j55pzONIdg7rdtJTRZPKIbV0FosUqYdhHK1aAYJIrUvejv1VVyBokrILE8KQDT4emW/1Ev9tx+yZG+AxuSBMmA==", + "dev": true + } } }, "graceful-fs": { @@ -3094,9 +3162,9 @@ "dev": true }, "http-cache-semantics": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz", - "integrity": "sha512-TcIMG3qeVLgDr1TEd2XvHaTnMPwYQUQMIBLy+5pLSDKYFc7UIqj39w8EGzZkaxoLv/l2K8HaI0t5AVA+YYgUew==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", + "integrity": "sha512-Z2EICWNJou7Tr9Bd2M2UqDJq3A9F2ePG9w3lIpjoyuSyXFP9QbniJVu3XQYytuw5ebmG7dXSXO9PgAjJG8DDKA==", "dev": true }, "http-proxy-agent": { @@ -3373,7 +3441,7 @@ }, "is-obj": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", "dev": true }, @@ -3687,9 +3755,9 @@ "dev": true }, "json-buffer": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", - "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", "dev": true }, "json-parse-better-errors": { @@ -3772,12 +3840,12 @@ "dev": true }, "keyv": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", - "integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.0.tgz", + "integrity": "sha512-U7ioE8AimvRVLfw4LffyOIRhL2xVgmE8T22L6i0BucSnBUyv4w+I7VN/zVZwRKHOI6ZRUcdMdWHQ8KSUvGpEog==", "dev": true, "requires": { - "json-buffer": "3.0.0" + "json-buffer": "3.0.1" } }, "lcid": { @@ -3939,9 +4007,9 @@ } }, "lowercase-keys": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", - "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", + "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", "dev": true }, "lru-cache": { @@ -4292,15 +4360,15 @@ "dev": true }, "mimic-response": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.0.0.tgz", + "integrity": "sha512-8ilDoEapqA4uQ3TwS0jakGONKXVJqpy+RpM+3b7pLdOjghCrEiGp9SRkFbUHAmZW9vdnrENWHjaweIoTIJExSQ==", "dev": true }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { "brace-expansion": "^1.1.7" @@ -8607,7 +8675,7 @@ }, "os-tmpdir": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true }, @@ -8627,9 +8695,9 @@ } }, "p-cancelable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", - "integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz", + "integrity": "sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg==", "dev": true }, "p-defer": { @@ -8644,6 +8712,15 @@ "integrity": "sha512-ZuRs1miPT4HrjFa+9fRfOFXxGJfORgelKV9f9nNOWw2gl6gVsRaVDOQP0+MI0G0wGKns1Yacsu0GjOFbTK0JFQ==", "dev": true }, + "p-event": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-event/-/p-event-4.1.0.tgz", + "integrity": "sha512-4vAd06GCsgflX4wHN1JqrMzBh/8QZ4j+rzp0cd2scXRwuBEv+QR3wrVA5aLhWDLw4y2WgDKvzWF3CCLmVM1UgA==", + "dev": true, + "requires": { + "p-timeout": "^2.0.1" + } + }, "p-filter": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/p-filter/-/p-filter-2.1.0.tgz", @@ -8716,6 +8793,15 @@ "retry": "^0.12.0" } }, + "p-timeout": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-2.0.1.tgz", + "integrity": "sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA==", + "dev": true, + "requires": { + "p-finally": "^1.0.0" + } + }, "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", @@ -8990,12 +9076,6 @@ "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, - "prepend-http": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", - "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=", - "dev": true - }, "prettier": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.0.tgz", @@ -9322,12 +9402,12 @@ "dev": true }, "responselike": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", - "integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz", + "integrity": "sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw==", "dev": true, "requires": { - "lowercase-keys": "^1.0.0" + "lowercase-keys": "^2.0.0" } }, "restore-cursor": { @@ -12058,7 +12138,7 @@ }, "through": { "version": "2.3.8", - "resolved": "http://registry.npmjs.org/through/-/through-2.3.8.tgz", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=", "dev": true }, @@ -12087,9 +12167,9 @@ "dev": true }, "to-readable-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", - "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-2.1.0.tgz", + "integrity": "sha512-o3Qa6DGg1CEXshSdvWNX2sN4QHqg03SPq7U6jPXRahlQdl5dK8oXjkU/2/sGrnOZKeGV1zLSO8qPwyKklPPE7w==", "dev": true }, "to-regex-range": { @@ -12350,15 +12430,6 @@ "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==", "dev": true }, - "url-parse-lax": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", - "integrity": "sha1-FrXK/Afb42dsGxmZF3gj1lA6yww=", - "dev": true, - "requires": { - "prepend-http": "^2.0.0" - } - }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 389755ffa..00993342f 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "eslint-plugin-node": "^11.0.0", "eslint-plugin-promise": "^4.1.1", "eslint-plugin-standard": "^4.0.0", - "got": "^9.6.0", + "got": "^10.5.2", "@sinonjs/fake-timers": "^6.0.0", "mocha": "^7.0.1", "npm-run-all": "^4.1.5", diff --git a/tests/test_allow_unmocked.js b/tests/test_allow_unmocked.js index 71ec163b3..8416adc90 100644 --- a/tests/test_allow_unmocked.js +++ b/tests/test_allow_unmocked.js @@ -76,18 +76,18 @@ describe('allowUnmocked option', () => { .reply(304, 'served from our mock') .get('/wont/get/here') .reply(304, 'served from our mock') - const client = got.extend({ baseUrl: url, throwHttpErrors: false }) + const client = got.extend({ prefixUrl: url, throwHttpErrors: false }) - const response1 = await client(`${url}/abc`) + const response1 = await client('abc') expect(response1.statusCode).to.equal(304) expect(response1.body).to.equal('served from our mock') expect(scope.isDone()).to.equal(false) - const response2 = await client(`${url}/not/available`) + const response2 = await client('not/available') expect(response2.statusCode).to.equal(404) expect(scope.isDone()).to.equal(false) - const response3 = await client(`${url}/`) + const response3 = await client('') expect(response3.statusCode).to.equal(200) expect(response3.body).to.equal('server served a response') expect(scope.isDone()).to.equal(false) @@ -105,8 +105,8 @@ describe('allowUnmocked option', () => { .reply(200, '{"message":"mocked response"}') const { body, statusCode } = await got.post(url, { - json: true, - body: { some: 'data' }, + json: { some: 'data' }, + responseType: 'json', }) expect(statusCode).to.equal(200) expect(body).to.deep.equal({ message: 'server response' }) @@ -124,8 +124,8 @@ describe('allowUnmocked option', () => { .reply(404, '{"message":"server response"}') const { body, statusCode } = await got.post(`${url}/post`, { - json: true, - body: { some: 'data' }, + json: { some: 'data' }, + responseType: 'json', }) expect(statusCode).to.equal(200) expect(body).to.deep.equal({ message: 'server response' }) diff --git a/tests/test_allow_unmocked_https.js b/tests/test_allow_unmocked_https.js index c49e09faf..5b914dab2 100644 --- a/tests/test_allow_unmocked_https.js +++ b/tests/test_allow_unmocked_https.js @@ -52,7 +52,7 @@ describe('allowUnmocked option (https)', () => { const { port } = server.address() const url = `https://localhost:${port}` const client = got.extend({ - baseUrl: url, + prefixUrl: url, ca: ssl.ca, throwHttpErrors: false, }) @@ -63,15 +63,15 @@ describe('allowUnmocked option (https)', () => { .get('/wont/get/here') .reply(500) - const response1 = await client('/abc') + const response1 = await client('abc') expect(response1.statusCode).to.equal(200) expect(response1.body).to.equal('mocked response') expect(scope.isDone()).to.equal(false) - const response2 = await client('/does/not/exist') + const response2 = await client('does/not/exist') expect(response2.statusCode).to.equal(404) expect(scope.isDone()).to.equal(false) - const response3 = await client('/') + const response3 = await client('') expect(response3.statusCode).to.equal(200) expect(response3.body).to.equal('server response') diff --git a/tests/test_basic_auth.js b/tests/test_basic_auth.js index 7bf6b0563..2d6aab951 100644 --- a/tests/test_basic_auth.js +++ b/tests/test_basic_auth.js @@ -18,7 +18,8 @@ test('basic auth with username and password', async t => { await t.test('succeeds when it matches', async tt => { const response = await got('http://example.test/test', { - auth: 'foo:bar', + username: 'foo', + password: 'bar', }) tt.equal(response.statusCode, 200) tt.equal(response.body, 'Here is the content') @@ -42,7 +43,10 @@ test('basic auth with username only', async t => { }) await t.test('succeeds when it matches', async tt => { - const response = await got('http://example.test/test', { auth: 'foo:' }) + const response = await got('http://example.test/test', { + username: 'foo', + password: '', + }) tt.equal(response.statusCode, 200) tt.equal(response.body, 'Here is the content') }) diff --git a/tests/test_body_match.js b/tests/test_body_match.js index 0f00f313b..1fb37a207 100644 --- a/tests/test_body_match.js +++ b/tests/test_body_match.js @@ -27,8 +27,7 @@ test('match form body reagardless of field ordering', async t => { .reply(200, 'Heyyyy!') const { body } = await got.post('http://example.test/', { - form: true, - body: { bar: 'foo', foo: 'bar' }, + form: { bar: 'foo', foo: 'bar' }, }) t.equal(body, 'Heyyyy!') diff --git a/tests/test_define.js b/tests/test_define.js index 9560e4ecb..7b345e33d 100644 --- a/tests/test_define.js +++ b/tests/test_define.js @@ -23,10 +23,13 @@ test('define() is backward compatible', async t => { ]) ) - await assertRejects(got('http://example.test:12345/'), ({ statusCode }) => { - t.is(statusCode, 500) - return true - }) + await assertRejects( + got('http://example.test:12345/'), + ({ response: { statusCode } }) => { + t.is(statusCode, 500) + return true + } + ) }) test('define() throws when reply is not a numeric string', t => { @@ -150,19 +153,19 @@ test('define() works with non-JSON responses', async t => { ) const { statusCode, body } = await got.post('http://example.test/', { - encoding: false, body: exampleBody, + responseType: 'buffer', }) t.equal(statusCode, 200) - // TODO: because `{ encoding: false }` is passed to `got`, `body` should be - // a buffer, but it's a string. Is this a bug in nock or got? - t.equal(body, exampleResponseBody) + t.type(body, Buffer) + t.equal(body.toString(), exampleResponseBody) }) // TODO: There seems to be a bug here. When testing via `got` with // `{ encoding: false }` the body that comes back should be a buffer, but is // not. It's difficult to get this test to pass after porting it. +// I think this bug has been fixed in Got v10, so this should be unblocked. test('define() works with binary buffers', t => { const exampleBody = '8001' const exampleResponse = '8001' diff --git a/tests/test_intercept.js b/tests/test_intercept.js index 84f346da3..3038679d8 100644 --- a/tests/test_intercept.js +++ b/tests/test_intercept.js @@ -43,7 +43,7 @@ test('get gets mocked', async t => { .reply(200, 'Hello World!') const { statusCode, body } = await got('http://example.test/', { - encoding: null, + responseType: 'buffer', }) t.equal(statusCode, 200) @@ -58,7 +58,7 @@ test('get gets mocked with relative base path', async t => { .reply(200, 'Hello World!') const { statusCode, body } = await got('http://example.test/abc/def', { - encoding: null, + responseType: 'buffer', }) t.equal(statusCode, 200) @@ -73,7 +73,7 @@ test('post', async t => { .reply(201, 'OK!') const { statusCode, body } = await got.post('http://example.test/form', { - encoding: null, + responseType: 'buffer', }) t.equal(statusCode, 201) @@ -88,7 +88,7 @@ test('post with empty response body', async t => { .reply() const { statusCode, body } = await got.post('http://example.test/form', { - encoding: null, + responseType: 'buffer', }) t.equal(statusCode, 200) @@ -137,7 +137,7 @@ test('post with regexp as spec', async t => { .post('/echo', /key=v.?l/g) .reply(200, (uri, body) => ['OK', uri, body].join(' ')) - const { body } = await got('http://example.test/echo', { body: input }) + const { body } = await got.post('http://example.test/echo', { body: input }) t.equal(body, 'OK /echo key=val') scope.done() @@ -148,7 +148,9 @@ test('post with function as spec', async t => { .post('/echo', body => body === 'key=val') .reply(200, (uri, body) => ['OK', uri, body].join(' ')) - const { body } = await got('http://example.test/echo', { body: 'key=val' }) + const { body } = await got.post('http://example.test/echo', { + body: 'key=val', + }) t.equal(body, 'OK /echo key=val') scope.done() @@ -161,7 +163,7 @@ test('post with chaining on call', async t => { .post('/echo', input) .reply(200, (uri, body) => ['OK', uri, body].join(' ')) - const { body } = await got('http://example.test/echo', { body: input }) + const { body } = await got.post('http://example.test/echo', { body: input }) t.equal(body, 'OK /echo key=val') scope.done() @@ -212,11 +214,11 @@ test('body data is differentiating', async t => { .post('/', 'def') .reply(200, 'Hey 2') - const response1 = await got('http://example.test/', { body: 'abc' }) + const response1 = await got.post('http://example.test/', { body: 'abc' }) t.equal(response1.statusCode, 200) t.equal(response1.body, 'Hey 1') - const response2 = await got('http://example.test/', { body: 'def' }) + const response2 = await got.post('http://example.test/', { body: 'def' }) t.equal(response2.statusCode, 200) t.equal(response2.body, 'Hey 2') @@ -263,7 +265,7 @@ test('on interceptor, filter path with function', async t => { .reply(200, 'Hello World!') const { statusCode } = await got('http://example.test/', { - query: { a: '1', b: '2' }, + searchParams: { a: '1', b: '2' }, }) t.equal(statusCode, 200) @@ -402,7 +404,7 @@ test('can use https', async t => { .reply() const { statusCode } = await got('https://example.test/', { - encoding: null, + responseType: 'buffer', }) t.equal(statusCode, 200) diff --git a/tests/test_query.js b/tests/test_query.js index 9f5272651..0df73cd41 100644 --- a/tests/test_query.js +++ b/tests/test_query.js @@ -130,7 +130,7 @@ describe('`query()`', () => { .reply() const { statusCode } = await got('http://example.test/', { - query: { 'foo&bar': 'hello&world' }, + searchParams: { 'foo&bar': 'hello&world' }, }) expect(statusCode).to.equal(200) diff --git a/tests/test_recorder.js b/tests/test_recorder.js index 57ffb4093..326b6c7c2 100644 --- a/tests/test_recorder.js +++ b/tests/test_recorder.js @@ -433,7 +433,7 @@ it('records nonstandard ports', done => { }) }) -it('req.end accepts and calls a callback when recording', done => { +it('`req.end()` accepts and calls a callback when recording', done => { const onEnd = sinon.spy() server = http.createServer((request, response) => { @@ -469,6 +469,51 @@ it('req.end accepts and calls a callback when recording', done => { }) }) +// https://nodejs.org/api/http.html#http_request_end_data_encoding_callback +it('when recording, when `req.end()` is called with only data and a callback, the callback is invoked and the data is sent', done => { + const onEnd = sinon.spy() + + let requestBody = '' + server = http.createServer((request, response) => { + request.on('data', data => { + requestBody += data + }) + request.on('end', () => { + response.writeHead(200) + response.end() + }) + }) + + nock.restore() + nock.recorder.clear() + expect(nock.recorder.play()).to.be.empty() + + server.listen(() => { + nock.recorder.rec({ dont_print: true }) + + const req = http.request( + { + hostname: 'localhost', + port: server.address().port, + path: '/', + method: 'POST', + }, + res => { + expect(onEnd).to.have.been.calledOnce() + expect(res.statusCode).to.equal(200) + + res.on('end', () => { + expect(requestBody).to.equal('foobar') + done() + }) + res.resume() + } + ) + + req.end('foobar', onEnd) + }) +}) + it('rec() throws when reinvoked with already recorder requests', () => { nock.restore() nock.recorder.clear() @@ -943,7 +988,7 @@ it('records query parameters', async () => { }) await got(`http://localhost:${server.address().port}`, { - query: { q: 'test search' }, + searchParams: { q: 'test search' }, }) nock.restore() @@ -970,7 +1015,7 @@ it('encodes the query parameters when not outputting objects', async () => { }) await got(`http://localhost:${server.address().port}`, { - query: { q: 'test search++' }, + searchParams: { q: 'test search++' }, }) nock.restore() @@ -1054,7 +1099,7 @@ it('outputs query string parameters using query()', async () => { nock.recorder.rec(true) await got(`http://localhost:${server.address().port}/`, { - query: { param1: 1, param2: 2 }, + searchParams: { param1: 1, param2: 2 }, }) const recorded = nock.recorder.play() @@ -1079,7 +1124,7 @@ it('outputs query string arrays correctly', async () => { nock.recorder.rec(true) await got(`http://localhost:${server.address().port}/`, { - query: new URLSearchParams([ + searchParams: new URLSearchParams([ ['foo', 'bar'], ['foo', 'baz'], ]), diff --git a/tests/test_reply_function_async.js b/tests/test_reply_function_async.js index 1e4467f31..6a2fb34a1 100644 --- a/tests/test_reply_function_async.js +++ b/tests/test_reply_function_async.js @@ -21,7 +21,9 @@ describe('asynchronous `reply()` function', () => { callback(null, 'Hello World!') ) - const { body } = await got('http://example.test/', { encoding: null }) + const { body } = await got('http://example.test/', { + responseType: 'buffer', + }) expect(body).to.be.an.instanceOf(Buffer) expect(body.toString('utf8')).to.equal('Hello World!') diff --git a/tests/test_reply_function_sync.js b/tests/test_reply_function_sync.js index 8eea0d9b5..317b70ec7 100644 --- a/tests/test_reply_function_sync.js +++ b/tests/test_reply_function_sync.js @@ -124,7 +124,7 @@ describe('synchronous `reply()` function', () => { got.post('http://example.test/endpoint', { body: exampleRequestBody, }), - ({ statusCode, body }) => { + ({ response: { statusCode, body } }) => { expect(statusCode).to.equal(404) expect(body).to.equal(exampleResponseBody) return true @@ -149,10 +149,10 @@ describe('synchronous `reply()` function', () => { }) await assertRejects( - got('http://example.test/endpoint', { + got.post('http://example.test/endpoint', { body: exampleRequestBody, }), - ({ statusCode, body }) => { + ({ response: { statusCode, body } }) => { expect(statusCode).to.equal(404) expect(body).to.equal('') return true @@ -178,7 +178,7 @@ describe('synchronous `reply()` function', () => { .and.to.deep.equal(JSON.parse(exampleRequestBody)) }) - const { statusCode } = await got('http://example.test/', { + const { statusCode } = await got.post('http://example.test/', { headers: { 'Content-Type': 'application/json' }, body: exampleRequestBody, }) @@ -201,7 +201,7 @@ describe('synchronous `reply()` function', () => { .and.to.to.deep.equal(JSON.parse(exampleRequestBody)) }) - const { statusCode } = await got('http://example.test/', { + const { statusCode } = await got.post('http://example.test/', { // Providing the field value as an array is probably a bug on the callers behalf, // but it is still allowed by Node headers: { 'Content-Type': ['application/json', 'charset=utf8'] }, @@ -272,7 +272,7 @@ describe('synchronous `reply()` function', () => { await assertRejects( got('http://example.test/'), - ({ statusCode, body }) => { + ({ response: { statusCode, body } }) => { expect(statusCode).to.equal(401) expect(body).to.equal(exampleResponse) return true diff --git a/tests/test_scope.js b/tests/test_scope.js index a51d702ff..c35975c69 100644 --- a/tests/test_scope.js +++ b/tests/test_scope.js @@ -134,7 +134,7 @@ describe('filteringPath()', function() { .reply() const { statusCode } = await got('http://example.test/', { - query: { a: '1', b: '2' }, + searchParams: { a: '1', b: '2' }, }) expect(statusCode).to.equal(200) @@ -148,7 +148,7 @@ describe('filteringPath()', function() { .reply() const { statusCode } = await got('http://example.test/', { - query: { a: '1', b: '2' }, + searchParams: { a: '1', b: '2' }, }) expect(statusCode).to.equal(200) @@ -176,7 +176,7 @@ describe('filteringRequestBody()', () => { .post('/', 'mamma tua') .reply() - const { statusCode } = await got('http://example.test/', { + const { statusCode } = await got.post('http://example.test/', { body: 'mamma mia', }) @@ -191,7 +191,7 @@ describe('filteringRequestBody()', () => { .post('/', 'mamma nostra') .reply(200, 'Hello World!') - const { statusCode } = await got('http://example.test/', { + const { statusCode } = await got.post('http://example.test/', { body: 'mamma mia', })