Skip to content

Commit 0a4429b

Browse files
wenytang-mstecton
authored andcommitted
test: fix unit test case (#14285)
* test: update test case * test: fix test cases * test: fix test cases
1 parent 07eb349 commit 0a4429b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/fx-core/tests/component/driver/script/scriptDriver.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,29 +352,30 @@ describe("getStderrHandler", () => {
352352

353353
describe("defaultShell", () => {
354354
const sandbox = sinon.createSandbox();
355-
let restoreEnv: RestoreFn = () => {};
356355
afterEach(() => {
357356
sandbox.restore();
358-
restoreEnv();
359357
});
360358
it("SHELL", async () => {
361-
restoreEnv = mockedEnv({ SHELL: "/bin/bash" });
359+
sandbox.stub(process, "env").value({ SHELL: "/bin/bash" });
362360
const result = await defaultShell();
363361
assert.equal(result, "/bin/bash");
364362
});
365363
it("darwin - /bin/zsh", async () => {
364+
sandbox.stub(process, "env").value({});
366365
sandbox.stub(process, "platform").value("darwin");
367366
sandbox.stub(fs, "pathExists").resolves(true);
368367
const result = await defaultShell();
369368
assert.equal(result, "/bin/zsh");
370369
});
371370
it("darwin - /bin/bash", async () => {
371+
sandbox.stub(process, "env").value({});
372372
sandbox.stub(process, "platform").value("darwin");
373373
sandbox.stub(fs, "pathExists").onFirstCall().resolves(false).onSecondCall().resolves(true);
374374
const result = await defaultShell();
375375
assert.equal(result, "/bin/bash");
376376
});
377377
it("darwin - undefined", async () => {
378+
sandbox.stub(process, "env").value({});
378379
sandbox.stub(process, "platform").value("darwin");
379380
sandbox.stub(fs, "pathExists").resolves(false);
380381
const result = await defaultShell();
@@ -383,25 +384,27 @@ describe("defaultShell", () => {
383384

384385
it("win32 - ComSpec", async () => {
385386
sandbox.stub(process, "platform").value("win32");
386-
restoreEnv = mockedEnv({ ComSpec: "cmd.exe" });
387+
sandbox.stub(process, "env").value({ ComSpec: "cmd.exe" });
387388
const result = await defaultShell();
388389
assert.equal(result, "cmd.exe");
389390
});
390391
it("win32 - cmd.exe", async () => {
391392
sandbox.stub(process, "platform").value("win32");
392-
restoreEnv = mockedEnv({ ComSpec: undefined });
393+
sandbox.stub(process, "env").value({});
393394
const result = await defaultShell();
394395
assert.equal(result, "cmd.exe");
395396
});
396397

397398
it("other OS - /bin/sh", async () => {
399+
sandbox.stub(process, "env").value({});
398400
sandbox.stub(process, "platform").value("other");
399401
sandbox.stub(fs, "pathExists").resolves(true);
400402
const result = await defaultShell();
401403
assert.equal(result, "/bin/sh");
402404
});
403405

404406
it("other OS - undefined", async () => {
407+
sandbox.stub(process, "env").value({});
405408
sandbox.stub(process, "platform").value("other");
406409
sandbox.stub(fs, "pathExists").resolves(false);
407410
const result = await defaultShell();

0 commit comments

Comments
 (0)