* 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)
| 66 | * @param {string} [testName] - The name of the test (auto computed if not provided) |
| 67 | */ |
| 68 | function 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 | |
| 107 | describe('Proxy Helper', function () { |
| 108 | describe('No proxy variables', function () { |