Skip to content

Commit

Permalink
test: special order not needed for mocking this import.
Browse files Browse the repository at this point in the history
  • Loading branch information
Codex- committed Dec 11, 2022
1 parent 82da489 commit 22791a3
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/loader.spec.ts
Expand Up @@ -12,26 +12,27 @@ import {
SpyInstance,
vi,
} from "vitest";
import * as tsnode from "ts-node";

import { TypeScriptLoader } from "./loader";
import { TypeScriptCompileError } from "./typescript-compile-error";

vi.mock("ts-node", async () => {
const tsnode = await vi.importActual<typeof import("ts-node")>("ts-node");
const actualTsnode = await vi.importActual<typeof import("ts-node")>(
"ts-node"
);

let writableTsNode: any = {};
Object.keys(tsnode).forEach((key) =>
const writableTsNode: any = {};
Object.keys(actualTsnode).forEach((key) =>
Object.defineProperty(writableTsNode, key, {
value: (tsnode as any)[key],
value: (actualTsnode as any)[key],
writable: true,
})
);

return writableTsNode;
});

import * as tsnode from "ts-node";

import { TypeScriptLoader } from "./loader";
import { TypeScriptCompileError } from "./typescript-compile-error";

describe("TypeScriptLoader", () => {
const fixturesPath = path.resolve(__dirname, "__fixtures__");
const tsNodeSpy = vi.spyOn(tsnode, "register");
Expand Down

0 comments on commit 22791a3

Please sign in to comment.