From 2ea73196a6ffcc55f0438f19d44d0ac471648cac Mon Sep 17 00:00:00 2001 From: Hugo Arregui Date: Tue, 10 Sep 2024 10:27:57 -0300 Subject: [PATCH] remove http-server dependency --- etc/test-helpers.api.md | 2 +- package.json | 6 ++- src/localFetch.ts | 25 +++++----- yarn.lock | 104 +--------------------------------------- 4 files changed, 17 insertions(+), 120 deletions(-) diff --git a/etc/test-helpers.api.md b/etc/test-helpers.api.md index 56fc653..e7e1338 100644 --- a/etc/test-helpers.api.md +++ b/etc/test-helpers.api.md @@ -7,7 +7,7 @@ /// import { IConfigComponent } from '@well-known-components/interfaces'; -import { IFetchComponent } from '@well-known-components/http-server'; +import { IFetchComponent } from '@well-known-components/interfaces'; import { Lifecycle } from '@well-known-components/interfaces'; import { default as sinon_2 } from 'sinon'; diff --git a/package.json b/package.json index b61bccc..4ea7d30 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,14 @@ }, "prettier": { "printWidth": 120, - "semi": false + "semi": false, + "singleQuote": true, + "trailingComma": "none", + "tabWidth": 2 }, "homepage": "https://github.com/well-known-components/test-helpers#readme", "devDependencies": { "@microsoft/api-extractor": "^7.36.0", - "@well-known-components/http-server": "^2.0.0", "@well-known-components/interfaces": "^1.4.2", "ts-node": "^10.9.1", "typescript": "^5.1.5" diff --git a/src/localFetch.ts b/src/localFetch.ts index 6040ecd..e0bf869 100644 --- a/src/localFetch.ts +++ b/src/localFetch.ts @@ -1,12 +1,11 @@ -import nodeFetch, { RequestInfo, RequestInit } from "node-fetch" +import nodeFetch, { RequestInfo, RequestInit } from 'node-fetch' import * as http from 'http' -import { IFetchComponent } from "@well-known-components/http-server" -import { IConfigComponent } from "@well-known-components/interfaces" +import { IFetchComponent, IConfigComponent } from '@well-known-components/interfaces' // start TCP port for listeners /* istanbul ignore next */ -let lastUsedPort = 19000 + parseInt(process.env.JEST_WORKER_ID || "1") * 1000 +let lastUsedPort = 19000 + parseInt(process.env.JEST_WORKER_ID || '1') * 1000 function getPort() { lastUsedPort += 1 @@ -16,7 +15,7 @@ function getPort() { /** * Default Server config * @public -**/ + **/ export const defaultServerConfig = () => ({ HTTP_SERVER_HOST: '0.0.0.0', HTTP_SERVER_PORT: String(getPort()) @@ -25,24 +24,22 @@ export const defaultServerConfig = () => ({ /** * Local Fetch component for testing local urls * @public -**/ -export async function createLocalFetchCompoment( - configComponent: IConfigComponent -): Promise { + **/ +export async function createLocalFetchCompoment(configComponent: IConfigComponent): Promise { const protocolHostAndProtocol = `http://${await configComponent.requireString( - "HTTP_SERVER_HOST" - )}:${await configComponent.requireNumber("HTTP_SERVER_PORT")}` + 'HTTP_SERVER_HOST' + )}:${await configComponent.requireNumber('HTTP_SERVER_PORT')}` const agent = new http.Agent({ keepAlive: false }) // test fetch, to hit our local server const localFetch: IFetchComponent = { async fetch(url: RequestInfo, initRequest?: RequestInit) { - if (typeof url == "string" && url.startsWith("/")) { + if (typeof url == 'string' && url.startsWith('/')) { return nodeFetch(protocolHostAndProtocol + url, { agent, ...initRequest }) } else { - throw new Error("localFetch only works for local testing-URLs") + throw new Error('localFetch only works for local testing-URLs') } - }, + } } return localFetch } diff --git a/yarn.lock b/yarn.lock index 1ab34e7..9c34b46 100644 --- a/yarn.lock +++ b/yarn.lock @@ -757,11 +757,6 @@ dependencies: "@types/node" "*" -"@types/http-errors@^2.0.1": - version "2.0.1" - resolved "https://registry.yarnpkg.com/@types/http-errors/-/http-errors-2.0.1.tgz#20172f9578b225f6c7da63446f56d4ce108d5a65" - integrity sha512-/K3ds8TRAfBvi5vfjuz8y6+GiAYBZ0x4tXv1Av6CWBWn0IlADc+ZX9pMq7oU0fNQPnBwIZl3rmeLp6SBApbxSQ== - "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1": version "2.0.4" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44" @@ -831,20 +826,6 @@ dependencies: "@types/yargs-parser" "*" -"@well-known-components/http-server@^2.0.0": - version "2.0.0" - resolved "https://registry.yarnpkg.com/@well-known-components/http-server/-/http-server-2.0.0.tgz#85ec93080ae64f962782699db3eeecd597f59405" - integrity sha512-baDP0+MpgqTnKLFFXS41WBbg9QIGCXTEA7BHf6JqW1evrTW10MKEx+rgEvQQlhCA5oXxUdKOD+xNnR3GqzGw9w== - dependencies: - "@types/http-errors" "^2.0.1" - destroy "^1.2.0" - fp-future "^1.0.1" - http-errors "^2.0.0" - mitt "^3.0.0" - node-fetch "^2.6.9" - on-finished "^2.4.1" - path-to-regexp "^6.2.1" - "@well-known-components/interfaces@^1.4.2": version "1.4.3" resolved "https://registry.yarnpkg.com/@well-known-components/interfaces/-/interfaces-1.4.3.tgz#026047966db480bd561a315fdc8116b88bf8d27a" @@ -1222,16 +1203,6 @@ delayed-stream@~1.0.0: resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== -depd@2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df" - integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw== - -destroy@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.2.0.tgz#4803735509ad8be552934c67df614f94e66fa015" - integrity sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg== - detect-newline@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651" @@ -1252,11 +1223,6 @@ diff@^5.2.0: resolved "https://registry.yarnpkg.com/diff/-/diff-5.2.0.tgz#26ded047cd1179b78b9537d5ef725503ce1ae531" integrity sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A== -ee-first@1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" - integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow== - ejs@^3.1.10: version "3.1.10" resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.10.tgz#69ab8358b14e896f80cc39e62087b88500c3ac3b" @@ -1385,11 +1351,6 @@ form-data@^3.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" -fp-future@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/fp-future/-/fp-future-1.0.1.tgz#72e6247814f7a706d84939e5f459c2d7ec42316f" - integrity sha512-2McmZH/KsZqlqHju9+Ox0FC7q7Knve4t6ZeKubbhAz1xpnD7hkCrP8TP5g5QbbD5bA5jBANbXf/ew4x1FjSUrw== - fs-extra@~7.0.1: version "7.0.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" @@ -1478,17 +1439,6 @@ html-escaper@^2.0.0: resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453" integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg== -http-errors@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-2.0.0.tgz#b7774a1486ef73cf7667ac9ae0858c012c57b9d3" - integrity sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ== - dependencies: - depd "2.0.0" - inherits "2.0.4" - setprototypeof "1.2.0" - statuses "2.0.1" - toidentifier "1.0.1" - human-signals@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" @@ -1520,7 +1470,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@2.0.4: +inherits@2: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -2159,11 +2109,6 @@ minimatch@~3.0.3: dependencies: brace-expansion "^1.1.7" -mitt@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.0.tgz#69ef9bd5c80ff6f57473e8d89326d01c414be0bd" - integrity sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ== - ms@2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" @@ -2185,13 +2130,6 @@ nise@^6.0.0: just-extend "^6.2.0" path-to-regexp "^6.2.1" -node-fetch@^2.6.9: - version "2.6.11" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.11.tgz#cde7fc71deef3131ef80a738919f999e6edfff25" - integrity sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w== - dependencies: - whatwg-url "^5.0.0" - node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" @@ -2214,13 +2152,6 @@ npm-run-path@^4.0.1: dependencies: path-key "^3.0.0" -on-finished@^2.4.1: - version "2.4.1" - resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f" - integrity sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg== - dependencies: - ee-first "1.1.1" - once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -2406,11 +2337,6 @@ semver@~7.5.4: dependencies: lru-cache "^6.0.0" -setprototypeof@1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424" - integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw== - shebang-command@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" @@ -2475,11 +2401,6 @@ stack-utils@^2.0.3: dependencies: escape-string-regexp "^2.0.0" -statuses@2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63" - integrity sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ== - string-argv@~0.3.1: version "0.3.2" resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6" @@ -2576,16 +2497,6 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -toidentifier@1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" - integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== - -tr46@~0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" - integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== - ts-jest@^29.1.0: version "29.2.5" resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.2.5.tgz#591a3c108e1f5ebd013d3152142cb5472b399d63" @@ -2686,19 +2597,6 @@ walker@^1.0.8: dependencies: makeerror "1.0.12" -webidl-conversions@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" - integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== - -whatwg-url@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" - integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw== - dependencies: - tr46 "~0.0.3" - webidl-conversions "^3.0.0" - which@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1"