Skip to content

Commit 4b0785f

Browse files
committed
refactor to shallow copy
1 parent cfcc6bb commit 4b0785f

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

packages/core/src/test/shared/utilities/pathFind.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ describe('pathFind', function () {
4646
let previousEnv: NodeJS.ProcessEnv
4747

4848
beforeEach(function () {
49-
previousEnv = testutil.readEnv()
49+
previousEnv = testutil.copyEnv()
5050
})
5151

5252
afterEach(function () {
53-
testutil.setEnv(previousEnv)
53+
process.env = previousEnv
5454
})
5555

5656
it('first tries ssh in $PATH (Non-Windows)', async function () {
@@ -61,7 +61,7 @@ describe('pathFind', function () {
6161
const workspace = await testutil.createTestWorkspaceFolder()
6262
const fakeSshPath = path.join(workspace.uri.fsPath, `ssh`)
6363

64-
testutil.setEnv(testutil.envWithNewPath(workspace.uri.fsPath))
64+
process.env = testutil.envWithNewPath(workspace.uri.fsPath)
6565
const firstResult = await findSshPath(false)
6666

6767
await testutil.createExecutableFile(fakeSshPath, '')
@@ -80,7 +80,7 @@ describe('pathFind', function () {
8080
const workspace = await testutil.createTestWorkspaceFolder()
8181
const fakeSshPath = path.join(workspace.uri.fsPath, `ssh`)
8282

83-
testutil.setEnv(testutil.envWithNewPath(workspace.uri.fsPath))
83+
process.env = testutil.envWithNewPath(workspace.uri.fsPath)
8484

8585
await testutil.createExecutableFile(fakeSshPath, '')
8686

@@ -99,7 +99,7 @@ describe('pathFind', function () {
9999
// We move the ssh to a temp directory temporarily to test if cache works.
100100
const fakeSshPath = path.join(workspace.uri.fsPath, `ssh`)
101101

102-
testutil.setEnv(testutil.envWithNewPath(workspace.uri.fsPath))
102+
process.env = testutil.envWithNewPath(workspace.uri.fsPath)
103103

104104
await testutil.createExecutableFile(fakeSshPath, '')
105105

packages/core/src/test/shared/utilities/testUtils.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import assert from 'assert'
6-
import { createExecutableFile, createTestWorkspaceFolder, envWithNewPath, readEnv, setEnv } from '../../testUtil'
6+
import { createExecutableFile, createTestWorkspaceFolder, envWithNewPath, copyEnv } from '../../testUtil'
77
import path from 'path'
88
import { fs } from '../../../shared'
99
import { isWin } from '../../../shared/vscode/env'
@@ -18,13 +18,13 @@ describe('envWithNewPath', function () {
1818

1919
describe('setEnv', function () {
2020
it('modifies the node environment variables', function () {
21-
const originalEnv = readEnv()
21+
const originalEnv = copyEnv()
2222
const fakePath = 'fakePath'
23-
setEnv(envWithNewPath('fakePath'))
24-
assert.strictEqual(readEnv().PATH, fakePath)
23+
process.env = envWithNewPath('fakePath')
24+
assert.strictEqual(copyEnv().PATH, fakePath)
2525

26-
setEnv(originalEnv)
27-
assert.deepStrictEqual(readEnv(), originalEnv)
26+
process.env = originalEnv
27+
assert.deepStrictEqual(copyEnv(), originalEnv)
2828
})
2929
})
3030

packages/core/src/test/testUtil.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,7 @@ export function getFetchStubWithResponse(response: Partial<Response>) {
615615
return stub(request, 'fetch').returns({ response: new Promise((res, _) => res(response)) } as any)
616616
}
617617

618-
export function setEnv(newEnv: NodeJS.ProcessEnv): void {
619-
process.env = newEnv
620-
}
621-
622-
export function readEnv(): NodeJS.ProcessEnv {
618+
export function copyEnv(): NodeJS.ProcessEnv {
623619
return { ...process.env }
624620
}
625621

0 commit comments

Comments
 (0)