@continuedev/fetch 1.0.6 → 1.0.10

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.
@@ -0,0 +1,102 @@
1
+ import { jest } from "@jest/globals";
2
+ import { getProxyFromEnv, shouldBypassProxy } from "./util.js";
3
+
4
+ // Reset environment variables after each test
5
+ afterEach(() => {
6
+ jest.resetModules();
7
+ process.env = {};
8
+ });
9
+
10
+ // Tests for getProxyFromEnv
11
+ test("getProxyFromEnv returns undefined when no proxy is set", () => {
12
+ expect(getProxyFromEnv("http:")).toBeUndefined();
13
+ expect(getProxyFromEnv("https:")).toBeUndefined();
14
+ });
15
+
16
+ test("getProxyFromEnv returns HTTP_PROXY for http protocol", () => {
17
+ process.env.HTTP_PROXY = "http://proxy.example.com";
18
+ expect(getProxyFromEnv("http:")).toBe("http://proxy.example.com");
19
+ });
20
+
21
+ test("getProxyFromEnv returns lowercase http_proxy for http protocol", () => {
22
+ process.env.http_proxy = "http://proxy.example.com";
23
+ expect(getProxyFromEnv("http:")).toBe("http://proxy.example.com");
24
+ });
25
+
26
+ test("getProxyFromEnv prefers HTTP_PROXY over http_proxy for http protocol", () => {
27
+ process.env.HTTP_PROXY = "http://upper.example.com";
28
+ process.env.http_proxy = "http://lower.example.com";
29
+ expect(getProxyFromEnv("http:")).toBe("http://upper.example.com");
30
+ });
31
+
32
+ test("getProxyFromEnv returns HTTPS_PROXY for https protocol", () => {
33
+ process.env.HTTPS_PROXY = "https://secure.example.com";
34
+ expect(getProxyFromEnv("https:")).toBe("https://secure.example.com");
35
+ });
36
+
37
+ test("getProxyFromEnv returns lowercase https_proxy for https protocol", () => {
38
+ process.env.https_proxy = "https://secure.example.com";
39
+ expect(getProxyFromEnv("https:")).toBe("https://secure.example.com");
40
+ });
41
+
42
+ test("getProxyFromEnv falls back to HTTP_PROXY for https protocol when HTTPS_PROXY is not set", () => {
43
+ process.env.HTTP_PROXY = "http://fallback.example.com";
44
+ expect(getProxyFromEnv("https:")).toBe("http://fallback.example.com");
45
+ });
46
+
47
+ test("getProxyFromEnv prefers HTTPS_PROXY over other env vars for https protocol", () => {
48
+ process.env.HTTPS_PROXY = "https://preferred.example.com";
49
+ process.env.https_proxy = "https://notused1.example.com";
50
+ process.env.HTTP_PROXY = "http://notused2.example.com";
51
+ process.env.http_proxy = "http://notused3.example.com";
52
+ expect(getProxyFromEnv("https:")).toBe("https://preferred.example.com");
53
+ });
54
+
55
+ // Tests for shouldBypassProxy
56
+ test("shouldBypassProxy returns false when NO_PROXY is not set", () => {
57
+ expect(shouldBypassProxy("example.com")).toBe(false);
58
+ });
59
+
60
+ test("shouldBypassProxy returns true for exact hostname match", () => {
61
+ process.env.NO_PROXY = "example.com,another.com";
62
+ expect(shouldBypassProxy("example.com")).toBe(true);
63
+ });
64
+
65
+ test("shouldBypassProxy returns false when hostname doesn't match any NO_PROXY entry", () => {
66
+ process.env.NO_PROXY = "example.com,another.com";
67
+ expect(shouldBypassProxy("different.com")).toBe(false);
68
+ });
69
+
70
+ test("shouldBypassProxy handles lowercase no_proxy", () => {
71
+ process.env.no_proxy = "example.com";
72
+ expect(shouldBypassProxy("example.com")).toBe(true);
73
+ });
74
+
75
+ test("shouldBypassProxy works with wildcard domains", () => {
76
+ process.env.NO_PROXY = "*.example.com";
77
+ expect(shouldBypassProxy("sub.example.com")).toBe(true);
78
+ expect(shouldBypassProxy("example.com")).toBe(false);
79
+ expect(shouldBypassProxy("different.com")).toBe(false);
80
+ });
81
+
82
+ test("shouldBypassProxy works with domain suffix", () => {
83
+ process.env.NO_PROXY = ".example.com";
84
+ expect(shouldBypassProxy("sub.example.com")).toBe(true);
85
+ expect(shouldBypassProxy("example.com")).toBe(true);
86
+ expect(shouldBypassProxy("different.com")).toBe(false);
87
+ });
88
+
89
+ test("shouldBypassProxy handles multiple entries with different patterns", () => {
90
+ process.env.NO_PROXY = "internal.local,*.example.com,.test.com";
91
+ expect(shouldBypassProxy("internal.local")).toBe(true);
92
+ expect(shouldBypassProxy("sub.example.com")).toBe(true);
93
+ expect(shouldBypassProxy("sub.test.com")).toBe(true);
94
+ expect(shouldBypassProxy("test.com")).toBe(true);
95
+ expect(shouldBypassProxy("example.org")).toBe(false);
96
+ });
97
+
98
+ test("shouldBypassProxy ignores whitespace in NO_PROXY", () => {
99
+ process.env.NO_PROXY = " example.com , *.test.org ";
100
+ expect(shouldBypassProxy("example.com")).toBe(true);
101
+ expect(shouldBypassProxy("subdomain.test.org")).toBe(true);
102
+ });
package/src/util.ts ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Gets the proxy settings from environment variables
3
+ * @param protocol The URL protocol (http: or https:)
4
+ * @returns The proxy URL if available, otherwise undefined
5
+ */
6
+ export function getProxyFromEnv(protocol: string): string | undefined {
7
+ if (protocol === "https:") {
8
+ return (
9
+ process.env.HTTPS_PROXY ||
10
+ process.env.https_proxy ||
11
+ process.env.HTTP_PROXY ||
12
+ process.env.http_proxy
13
+ );
14
+ } else {
15
+ return process.env.HTTP_PROXY || process.env.http_proxy;
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Checks if a hostname should bypass proxy based on NO_PROXY environment variable
21
+ * @param hostname The hostname to check
22
+ * @returns True if the hostname should bypass proxy
23
+ */
24
+ export function shouldBypassProxy(hostname: string): boolean {
25
+ const noProxy = process.env.NO_PROXY || process.env.no_proxy;
26
+ if (!noProxy) return false;
27
+
28
+ const noProxyItems = noProxy.split(",").map((item) => item.trim());
29
+
30
+ return noProxyItems.some((item) => {
31
+ // Exact match
32
+ if (item === hostname) return true;
33
+
34
+ // Wildcard domain match (*.example.com)
35
+ if (item.startsWith("*.") && hostname.endsWith(item.substring(1)))
36
+ return true;
37
+
38
+ // Domain suffix match (.example.com)
39
+ if (item.startsWith(".") && hostname.endsWith(item.slice(1))) return true;
40
+
41
+ return false;
42
+ });
43
+ }
package/tsconfig.json CHANGED
@@ -14,10 +14,10 @@
14
14
  "resolveJsonModule": true,
15
15
  "isolatedModules": true,
16
16
  "noEmitOnError": false,
17
- "types": ["node"],
17
+ "types": ["node", "jest"],
18
18
  "outDir": "dist",
19
19
  "declaration": true
20
20
  // "sourceMap": true
21
21
  },
22
- "include": ["src/**/*"]
22
+ "include": ["src/**/*", "jest.globals.d.ts"]
23
23
  }
package/jest.config.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * For a detailed explanation regarding each configuration property, visit:
3
- * https://jestjs.io/docs/configuration
4
- */
5
- import type { Config } from 'jest';
6
- declare const config: Config;
7
- export default config;
package/jest.config.js DELETED
@@ -1,143 +0,0 @@
1
- /**
2
- * For a detailed explanation regarding each configuration property, visit:
3
- * https://jestjs.io/docs/configuration
4
- */
5
- const config = {
6
- // All imported modules in your tests should be mocked automatically
7
- // automock: false,
8
- // Stop running tests after `n` failures
9
- // bail: 0,
10
- // The directory where Jest should store its cached dependency information
11
- // cacheDirectory: "/private/var/folders/n_/c3r8w0s95xl271j98y2lzhz80000gn/T/jest_dx",
12
- // Automatically clear mock calls, instances, contexts and results before every test
13
- clearMocks: true,
14
- // Indicates whether the coverage information should be collected while executing the test
15
- collectCoverage: true,
16
- // An array of glob patterns indicating a set of files for which coverage information should be collected
17
- // collectCoverageFrom: undefined,
18
- // The directory where Jest should output its coverage files
19
- coverageDirectory: "coverage",
20
- // An array of regexp pattern strings used to skip coverage collection
21
- // coveragePathIgnorePatterns: [
22
- // "/node_modules/"
23
- // ],
24
- // Indicates which provider should be used to instrument code for coverage
25
- coverageProvider: "v8",
26
- // A list of reporter names that Jest uses when writing coverage reports
27
- // coverageReporters: [
28
- // "json",
29
- // "text",
30
- // "lcov",
31
- // "clover"
32
- // ],
33
- // An object that configures minimum threshold enforcement for coverage results
34
- // coverageThreshold: undefined,
35
- // A path to a custom dependency extractor
36
- // dependencyExtractor: undefined,
37
- // Make calling deprecated APIs throw helpful error messages
38
- // errorOnDeprecated: false,
39
- // The default configuration for fake timers
40
- // fakeTimers: {
41
- // "enableGlobally": false
42
- // },
43
- // Force coverage collection from ignored files using an array of glob patterns
44
- // forceCoverageMatch: [],
45
- // A path to a module which exports an async function that is triggered once before all test suites
46
- // globalSetup: undefined,
47
- // A path to a module which exports an async function that is triggered once after all test suites
48
- // globalTeardown: undefined,
49
- // A set of global variables that need to be available in all test environments
50
- // globals: {},
51
- // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
52
- // maxWorkers: "50%",
53
- // An array of directory names to be searched recursively up from the requiring module's location
54
- // moduleDirectories: [
55
- // "node_modules"
56
- // ],
57
- // An array of file extensions your modules use
58
- // moduleFileExtensions: [
59
- // "js",
60
- // "mjs",
61
- // "cjs",
62
- // "jsx",
63
- // "ts",
64
- // "tsx",
65
- // "json",
66
- // "node"
67
- // ],
68
- // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
69
- // moduleNameMapper: {},
70
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
71
- // modulePathIgnorePatterns: [],
72
- // Activates notifications for test results
73
- // notify: false,
74
- // An enum that specifies notification mode. Requires { notify: true }
75
- // notifyMode: "failure-change",
76
- // A preset that is used as a base for Jest's configuration
77
- // preset: undefined,
78
- // Run tests from one or more projects
79
- // projects: undefined,
80
- // Use this configuration option to add custom reporters to Jest
81
- // reporters: undefined,
82
- // Automatically reset mock state before every test
83
- // resetMocks: false,
84
- // Reset the module registry before running each individual test
85
- // resetModules: false,
86
- // A path to a custom resolver
87
- // resolver: undefined,
88
- // Automatically restore mock state and implementation before every test
89
- // restoreMocks: false,
90
- // The root directory that Jest should scan for tests and modules within
91
- // rootDir: undefined,
92
- // A list of paths to directories that Jest should use to search for files in
93
- // roots: [
94
- // "<rootDir>"
95
- // ],
96
- // Allows you to use a custom runner instead of Jest's default test runner
97
- // runner: "jest-runner",
98
- // The paths to modules that run some code to configure or set up the testing environment before each test
99
- // setupFiles: [],
100
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
101
- // setupFilesAfterEnv: [],
102
- // The number of seconds after which a test is considered as slow and reported as such in the results.
103
- // slowTestThreshold: 5,
104
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
105
- // snapshotSerializers: [],
106
- // The test environment that will be used for testing
107
- // testEnvironment: "jest-environment-node",
108
- // Options that will be passed to the testEnvironment
109
- // testEnvironmentOptions: {},
110
- // Adds a location field to test results
111
- // testLocationInResults: false,
112
- // The glob patterns Jest uses to detect test files
113
- // testMatch: [
114
- // "**/__tests__/**/*.[jt]s?(x)",
115
- // "**/?(*.)+(spec|test).[tj]s?(x)"
116
- // ],
117
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
118
- // testPathIgnorePatterns: [
119
- // "/node_modules/"
120
- // ],
121
- // The regexp pattern or array of patterns that Jest uses to detect test files
122
- // testRegex: [],
123
- // This option allows the use of a custom results processor
124
- // testResultsProcessor: undefined,
125
- // This option allows use of a custom test runner
126
- // testRunner: "jest-circus/runner",
127
- // A map from regular expressions to paths to transformers
128
- // transform: undefined,
129
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
130
- // transformIgnorePatterns: [
131
- // "/node_modules/",
132
- // "\\.pnp\\.[^\\/]+$"
133
- // ],
134
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
135
- // unmockedModulePathPatterns: undefined,
136
- // Indicates whether each individual test should be reported during the run
137
- // verbose: undefined,
138
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
139
- // watchPathIgnorePatterns: [],
140
- // Whether to use watchman for file crawling
141
- // watchman: true,
142
- };
143
- export default config;
package/jest.config.ts DELETED
@@ -1,199 +0,0 @@
1
- /**
2
- * For a detailed explanation regarding each configuration property, visit:
3
- * https://jestjs.io/docs/configuration
4
- */
5
-
6
- import type {Config} from 'jest';
7
-
8
- const config: Config = {
9
- // All imported modules in your tests should be mocked automatically
10
- // automock: false,
11
-
12
- // Stop running tests after `n` failures
13
- // bail: 0,
14
-
15
- // The directory where Jest should store its cached dependency information
16
- // cacheDirectory: "/private/var/folders/n_/c3r8w0s95xl271j98y2lzhz80000gn/T/jest_dx",
17
-
18
- // Automatically clear mock calls, instances, contexts and results before every test
19
- clearMocks: true,
20
-
21
- // Indicates whether the coverage information should be collected while executing the test
22
- collectCoverage: true,
23
-
24
- // An array of glob patterns indicating a set of files for which coverage information should be collected
25
- // collectCoverageFrom: undefined,
26
-
27
- // The directory where Jest should output its coverage files
28
- coverageDirectory: "coverage",
29
-
30
- // An array of regexp pattern strings used to skip coverage collection
31
- // coveragePathIgnorePatterns: [
32
- // "/node_modules/"
33
- // ],
34
-
35
- // Indicates which provider should be used to instrument code for coverage
36
- coverageProvider: "v8",
37
-
38
- // A list of reporter names that Jest uses when writing coverage reports
39
- // coverageReporters: [
40
- // "json",
41
- // "text",
42
- // "lcov",
43
- // "clover"
44
- // ],
45
-
46
- // An object that configures minimum threshold enforcement for coverage results
47
- // coverageThreshold: undefined,
48
-
49
- // A path to a custom dependency extractor
50
- // dependencyExtractor: undefined,
51
-
52
- // Make calling deprecated APIs throw helpful error messages
53
- // errorOnDeprecated: false,
54
-
55
- // The default configuration for fake timers
56
- // fakeTimers: {
57
- // "enableGlobally": false
58
- // },
59
-
60
- // Force coverage collection from ignored files using an array of glob patterns
61
- // forceCoverageMatch: [],
62
-
63
- // A path to a module which exports an async function that is triggered once before all test suites
64
- // globalSetup: undefined,
65
-
66
- // A path to a module which exports an async function that is triggered once after all test suites
67
- // globalTeardown: undefined,
68
-
69
- // A set of global variables that need to be available in all test environments
70
- // globals: {},
71
-
72
- // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
73
- // maxWorkers: "50%",
74
-
75
- // An array of directory names to be searched recursively up from the requiring module's location
76
- // moduleDirectories: [
77
- // "node_modules"
78
- // ],
79
-
80
- // An array of file extensions your modules use
81
- // moduleFileExtensions: [
82
- // "js",
83
- // "mjs",
84
- // "cjs",
85
- // "jsx",
86
- // "ts",
87
- // "tsx",
88
- // "json",
89
- // "node"
90
- // ],
91
-
92
- // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
93
- // moduleNameMapper: {},
94
-
95
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
96
- // modulePathIgnorePatterns: [],
97
-
98
- // Activates notifications for test results
99
- // notify: false,
100
-
101
- // An enum that specifies notification mode. Requires { notify: true }
102
- // notifyMode: "failure-change",
103
-
104
- // A preset that is used as a base for Jest's configuration
105
- // preset: undefined,
106
-
107
- // Run tests from one or more projects
108
- // projects: undefined,
109
-
110
- // Use this configuration option to add custom reporters to Jest
111
- // reporters: undefined,
112
-
113
- // Automatically reset mock state before every test
114
- // resetMocks: false,
115
-
116
- // Reset the module registry before running each individual test
117
- // resetModules: false,
118
-
119
- // A path to a custom resolver
120
- // resolver: undefined,
121
-
122
- // Automatically restore mock state and implementation before every test
123
- // restoreMocks: false,
124
-
125
- // The root directory that Jest should scan for tests and modules within
126
- // rootDir: undefined,
127
-
128
- // A list of paths to directories that Jest should use to search for files in
129
- // roots: [
130
- // "<rootDir>"
131
- // ],
132
-
133
- // Allows you to use a custom runner instead of Jest's default test runner
134
- // runner: "jest-runner",
135
-
136
- // The paths to modules that run some code to configure or set up the testing environment before each test
137
- // setupFiles: [],
138
-
139
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
140
- // setupFilesAfterEnv: [],
141
-
142
- // The number of seconds after which a test is considered as slow and reported as such in the results.
143
- // slowTestThreshold: 5,
144
-
145
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
146
- // snapshotSerializers: [],
147
-
148
- // The test environment that will be used for testing
149
- // testEnvironment: "jest-environment-node",
150
-
151
- // Options that will be passed to the testEnvironment
152
- // testEnvironmentOptions: {},
153
-
154
- // Adds a location field to test results
155
- // testLocationInResults: false,
156
-
157
- // The glob patterns Jest uses to detect test files
158
- // testMatch: [
159
- // "**/__tests__/**/*.[jt]s?(x)",
160
- // "**/?(*.)+(spec|test).[tj]s?(x)"
161
- // ],
162
-
163
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
164
- // testPathIgnorePatterns: [
165
- // "/node_modules/"
166
- // ],
167
-
168
- // The regexp pattern or array of patterns that Jest uses to detect test files
169
- // testRegex: [],
170
-
171
- // This option allows the use of a custom results processor
172
- // testResultsProcessor: undefined,
173
-
174
- // This option allows use of a custom test runner
175
- // testRunner: "jest-circus/runner",
176
-
177
- // A map from regular expressions to paths to transformers
178
- // transform: undefined,
179
-
180
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
181
- // transformIgnorePatterns: [
182
- // "/node_modules/",
183
- // "\\.pnp\\.[^\\/]+$"
184
- // ],
185
-
186
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
187
- // unmockedModulePathPatterns: undefined,
188
-
189
- // Indicates whether each individual test should be reported during the run
190
- // verbose: undefined,
191
-
192
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
193
- // watchPathIgnorePatterns: [],
194
-
195
- // Whether to use watchman for file crawling
196
- // watchman: true,
197
- };
198
-
199
- export default config;