@@ -4,6 +4,7 @@ const common = require('../common');
4
4
const fixtures = require ( '../../test/common/fixtures' ) ;
5
5
const assert = require ( 'node:assert' ) ;
6
6
const { describe, it } = require ( 'node:test' ) ;
7
+ const { join } = require ( 'node:path' ) ;
7
8
8
9
const basicValidEnvFilePath = fixtures . path ( 'dotenv/basic-valid.env' ) ;
9
10
const validEnvFilePath = fixtures . path ( 'dotenv/valid.env' ) ;
@@ -48,10 +49,20 @@ describe('process.loadEnvFile()', () => {
48
49
} , { code : 'ENOENT' , syscall : 'open' , path : missingEnvFile } ) ;
49
50
} ) ;
50
51
52
+ // The whole chdir flow here is to address a case where a developer
53
+ // has a .env in the worktree which is probably in the global .gitignore.
54
+ // In that case this test would fail. To avoid confusion, chdir to lib will
55
+ // make this way less likely to happen. Probably a temporary directory would
56
+ // be the best choice but given how edge this case is this is fine.
51
57
it ( 'should throw when `.env` does not exist' , async ( ) => {
58
+ const originalCwd = process . cwd ( ) ;
59
+ process . chdir ( join ( originalCwd , 'lib' ) ) ;
60
+
52
61
assert . throws ( ( ) => {
53
62
process . loadEnvFile ( ) ;
54
63
} , { code : 'ENOENT' , syscall : 'open' , path : '.env' } ) ;
64
+
65
+ process . chdir ( originalCwd ) ;
55
66
} ) ;
56
67
57
68
it ( 'should check for permissions' , async ( ) => {
0 commit comments