MCPcopy
hub / github.com/node-red/node-red / testProxyUrl

Function testProxyUrl

test/nodes/core/network/lib/proxyHelper_spec.js:68–105  ·  view source on GitHub ↗

* Defines a test case that checks whether getProxyForUrl(input) === expected. * @param {object} env - The environment variables to use for the test * @param {*} expected - The expected result * @param {*} input - The input to test * @param {import('../../../../../packages/node_modules/@node-red/

(env, expected, input, options, testName)

Source from the content-addressed store, hash-verified

66 * @param {string} [testName] - The name of the test (auto computed if not provided)
67 */
68function testProxyUrl(env, expected, input, options, testName) {
69 assert(typeof env === 'object' && env !== null);
70 // Copy object to make sure that the in param does not get modified between
71 // the call of this function and the use of it below.
72 env = JSON.parse(JSON.stringify(env));
73
74 const title = testName || 'Proxy for URL ' + JSON.stringify(input) + ' === ' + JSON.stringify(expected);
75
76 // Save call stack for later use.
77 let stack = {};
78 Error.captureStackTrace(stack, testProxyUrl);
79 // Only use the last stack frame because that shows where this function is
80 // called, and that is sufficient for our purpose. No need to flood the logs
81 // with an uninteresting stack trace.
82 stack = stack.stack.split('\n', 2)[1];
83
84 it(title, function () {
85 let actual;
86 // runWithEnv(env, function () {
87 // actual = getProxyForUrl(input, options);
88 // });
89 options = options || {};
90 options.env = options.env || env || process.env;
91 actual = getProxyForUrl(input, options);
92 if (expected === actual) {
93 return; // Good!
94 }
95 try {
96 assert.strictEqual(expected, actual); // Create a formatted error message.
97 // Should not happen because previously we determined expected !== actual.
98 throw new Error('assert.strictEqual passed. This is impossible!');
99 } catch (e) {
100 // Use the original stack trace, so we can see a helpful line number.
101 e.stack = e.message + stack;
102 throw e;
103 }
104 });
105}
106
107describe('Proxy Helper', function () {
108 describe('No proxy variables', function () {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected