diff --git a/.mocharc.js b/.mocharc.js index 2d42f6515..896c1f327 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -2,5 +2,6 @@ module.exports = { recursive: true, + extension: [".js", ".ts"], require: ["./test/setup", "./test/assert-ext", "./test/ts-node"], }; diff --git a/test/src/utils/typescript.ts b/test/src/utils/typescript.ts index 576a4e682..282505ef8 100644 --- a/test/src/utils/typescript.ts +++ b/test/src/utils/typescript.ts @@ -1,11 +1,9 @@ import proxyquire from "proxyquire"; import sinon, { type SinonStub } from "sinon"; import _ from "lodash"; -import * as process from "process"; describe("utils/typescript", () => { - const processBackup = _.assign({}, process); - const processEnvBackup = _.assign({}, process.env); + const processEnvBackup = _.clone(process.env); let ts: typeof import("src/utils/typescript"); let registerStub: SinonStub; @@ -13,8 +11,7 @@ describe("utils/typescript", () => { beforeEach(() => { registerStub = sinon.stub(); - ts = require("src/utils/typescript"); - ts = proxyquire("src/utils/typescript", { + ts = proxyquire.noCallThru().load("src/utils/typescript", { "ts-node": { register: registerStub, REGISTER_INSTANCE, @@ -24,7 +21,6 @@ describe("utils/typescript", () => { afterEach(() => { _.set(process, REGISTER_INSTANCE, undefined); - _.set(global, "process", processBackup); _.set(process, "env", processEnvBackup); }); @@ -53,7 +49,7 @@ describe("utils/typescript", () => { }); it("should use swc if it is installed", () => { - ts = proxyquire("src/utils/typescript", { + ts = proxyquire.noCallThru().load("src/utils/typescript", { "ts-node": { register: registerStub, }, @@ -71,7 +67,7 @@ describe("utils/typescript", () => { }); it("should not use swc if not installed", () => { - ts = proxyquire("src/utils/typescript", { + ts = proxyquire.noCallThru().load("src/utils/typescript", { "ts-node": { register: registerStub, }, @@ -83,13 +79,13 @@ describe("utils/typescript", () => { assert.calledOnceWith( registerStub, sinon.match({ - swc: undefined, + swc: false, }), ); }); it("should not throw if nothing is installed", () => { - ts = proxyquire("src/utils/typescript", { + ts = proxyquire.noCallThru().load("src/utils/typescript", { "ts-node": null, "@swc/core": null, });