| 54 | ]; |
| 55 | |
| 56 | function run(test) { |
| 57 | const env = test.env; |
| 58 | const expected = test.expected; |
| 59 | |
| 60 | const opts = { |
| 61 | terminal: true, |
| 62 | input: new stream.Readable({ read() {} }), |
| 63 | output: new stream.Writable({ write() {} }) |
| 64 | }; |
| 65 | |
| 66 | Object.assign(process.env, env); |
| 67 | |
| 68 | return new Promise((resolve) => { |
| 69 | REPL.createInternalRepl(process.env, opts, common.mustSucceed((repl) => { |
| 70 | assert.strictEqual(repl.terminal, expected.terminal, |
| 71 | `Expected ${inspect(expected)} with ${inspect(env)}`); |
| 72 | assert.strictEqual(repl.useColors, expected.useColors, |
| 73 | `Expected ${inspect(expected)} with ${inspect(env)}`); |
| 74 | assert.strictEqual(repl.replMode, expected.replMode || REPL_MODE_SLOPPY, |
| 75 | `Expected ${inspect(expected)} with ${inspect(env)}`); |
| 76 | for (const key of Object.keys(env)) { |
| 77 | delete process.env[key]; |
| 78 | } |
| 79 | repl.close(); |
| 80 | resolve(); |
| 81 | })); |
| 82 | }); |
| 83 | } |
| 84 | |
| 85 | describe('REPL environment variables', { concurrency: 1 }, () => { |
| 86 | tests.forEach((testCase) => test(inspect(testCase.env), () => run(testCase))); |