Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/eventHandlers/FunctionEnvironmentReloadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class FunctionEnvironmentReloadHandler extends EventHandler<
logCategory: LogCategory.System,
});

process.env = Object.assign({}, msg.environmentVariables);
// reset existing env vars
Object.keys(process.env).map((key) => delete process.env[key]);
// set new env vars
Object.assign(process.env, msg.environmentVariables);

// Change current working directory
if (msg.functionAppDirectory) {
channel.log({
Expand Down
27 changes: 25 additions & 2 deletions test/eventHandlers/FunctionEnvironmentReloadHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ describe('FunctionEnvironmentReloadHandler', () => {
// Reset `process.env` after this test suite so it doesn't affect other tests
let originalEnv: NodeJS.ProcessEnv;
before(() => {
originalEnv = process.env;
originalEnv = { ...process.env };
({ stream, channel } = beforeEventHandlerSuite());
});

after(() => {
process.env = originalEnv;
Object.assign(process.env, originalEnv);
});

afterEach(async () => {
Expand All @@ -103,6 +103,29 @@ describe('FunctionEnvironmentReloadHandler', () => {
expect(process.env.PlaceholderVariable).to.be.undefined;
});

if (process.platform === 'win32') {
it('preserves case insensitivity of environment variables on Windows', async () => {
process.env.PlaceholderVariable = 'TRUE';
stream.addTestMessage({
requestId: 'id',
functionEnvironmentReloadRequest: {
environmentVariables: {
hello: 'world',
SystemDrive: 'Q:',
},
functionAppDirectory: null,
},
});
await stream.assertCalledWith(Msg.reloadEnvVarsLog(2), Msg.reloadSuccess);
expect(process.env.hello).to.equal('world');
expect(process.env.HeLlO).to.equal('world');
expect(process.env.SystemDrive).to.equal('Q:');
expect(process.env.systemdrive).to.equal('Q:');
expect(process.env.PlaceholderVariable).to.be.undefined;
expect(process.env.placeholdervariable).to.be.undefined;
});
}

it('reloading environment variables removes existing environment variables', async () => {
process.env.PlaceholderVariable = 'TRUE';
process.env.NODE_ENV = 'Debug';
Expand Down