Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e1cba97

Browse filesBrowse files
ShogunPandatargos
authored andcommitted
src: fix test local edge case
PR-URL: #52702 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent a42b93b commit e1cba97
Copy full SHA for e1cba97

File tree

Expand file treeCollapse file tree

1 file changed

+17
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-3
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-process-load-env-file.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-process-load-env-file.js
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const common = require('../common');
44
const fixtures = require('../../test/common/fixtures');
55
const assert = require('node:assert');
66
const { describe, it } = require('node:test');
7+
const { join } = require('node:path');
78

89
const basicValidEnvFilePath = fixtures.path('dotenv/basic-valid.env');
910
const validEnvFilePath = fixtures.path('dotenv/valid.env');
@@ -48,10 +49,23 @@ describe('process.loadEnvFile()', () => {
4849
}, { code: 'ENOENT', syscall: 'open', path: missingEnvFile });
4950
});
5051

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.
5157
it('should throw when `.env` does not exist', async () => {
52-
assert.throws(() => {
53-
process.loadEnvFile();
54-
}, { code: 'ENOENT', syscall: 'open', path: '.env' });
58+
const originalCwd = process.cwd();
59+
60+
try {
61+
process.chdir(join(originalCwd, 'lib'));
62+
63+
assert.throws(() => {
64+
process.loadEnvFile();
65+
}, { code: 'ENOENT', syscall: 'open', path: '.env' });
66+
} finally {
67+
process.chdir(originalCwd);
68+
}
5569
});
5670

5771
it('should check for permissions', async () => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.