|
2 | 2 |
|
3 | 3 | const common = require('../common'); |
4 | 4 | const assert = require('node:assert'); |
| 5 | +const path = require('node:path'); |
| 6 | +const fs = require('node:fs'); |
5 | 7 | const { describe, it } = require('node:test'); |
6 | 8 |
|
7 | 9 | if (process.config.variables.node_without_node_options) { |
8 | 10 | common.skip('missing NODE_OPTIONS support'); |
9 | 11 | } |
10 | 12 |
|
| 13 | +const tmpdir = require('../common/tmpdir'); |
| 14 | +const testDir = tmpdir.path; |
| 15 | +tmpdir.refresh(); |
| 16 | + |
11 | 17 | const relativePath = '../fixtures/dotenv/node-options.env'; |
12 | 18 |
|
13 | 19 | describe('.env supports NODE_OPTIONS', () => { |
@@ -70,4 +76,23 @@ describe('.env supports NODE_OPTIONS', () => { |
70 | 76 | assert.strictEqual(child.code, 0); |
71 | 77 | }); |
72 | 78 |
|
| 79 | + it('should merge env variables with .env file', async () => { |
| 80 | + const filePath = path.join(testDir, 'should-write.txt'); |
| 81 | + const code = ` |
| 82 | + const path = require('path'); |
| 83 | + require('fs').writeFileSync('${filePath}', 'hello', 'utf-8') |
| 84 | + `.trim(); |
| 85 | + const child = await common.spawnPromisified( |
| 86 | + process.execPath, |
| 87 | + [ `--env-file=${relativePath}`, '--eval', code ], |
| 88 | + { cwd: __dirname, env: { ...process.env, NODE_OPTIONS: '--allow-fs-write=*' } }, |
| 89 | + ); |
| 90 | + assert.strictEqual(child.stderr, ''); |
| 91 | + assert.strictEqual(child.stdout, ''); |
| 92 | + assert.strictEqual(child.code, 0); |
| 93 | + assert(fs.existsSync(filePath)); |
| 94 | + fs.unlinkSync(filePath); |
| 95 | + assert(!fs.existsSync(filePath)); |
| 96 | + }); |
| 97 | + |
73 | 98 | }); |
0 commit comments