Skip to content

Commit

Permalink
Merge pull request #772 from gemini-testing/users/shadowusr/TRIVIAL.f…
Browse files Browse the repository at this point in the history
…ix-ts-tests

test: fix launching tests on typescript
  • Loading branch information
shadowusr authored Jul 4, 2023
2 parents a1135e3 + cdfc623 commit 12f57f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

module.exports = {
recursive: true,
extension: [".js", ".ts"],
require: ["./test/setup", "./test/assert-ext", "./test/ts-node"],
};
16 changes: 6 additions & 10 deletions test/src/utils/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
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;
const REGISTER_INSTANCE = Symbol("tsNodeTesting");

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,
Expand All @@ -24,7 +21,6 @@ describe("utils/typescript", () => {

afterEach(() => {
_.set(process, REGISTER_INSTANCE, undefined);
_.set(global, "process", processBackup);
_.set(process, "env", processEnvBackup);
});

Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
});
Expand Down

0 comments on commit 12f57f4

Please sign in to comment.