Skip to content

Commit 18b20e7

Browse files
authored
Merge pull request #83 from Codex-/revert_to_jest
Revert to jest
2 parents 893579d + 42773a3 commit 18b20e7

File tree

10 files changed

+12835
-8087
lines changed

10 files changed

+12835
-8087
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"ignorePatterns": [
88
"lib/__fixtures__/**/*.ts",
99
"esbuild.config.mjs",
10-
"vite.config.ts",
10+
"jest.config.ts",
1111
"coverage",
1212
"dist",
1313
"smoke-tests"

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: build
22
on:
3-
pull_request:
43
push:
54

65
jobs:

jest.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Config } from "@jest/types";
2+
3+
const config: Config.InitialOptions = {
4+
collectCoverageFrom: [
5+
"<rootDir>/lib/**/*",
6+
"!<rootDir>/lib/__fixtures__/**/*",
7+
],
8+
moduleFileExtensions: ["ts", "js"],
9+
transform: {
10+
"^.+\\.ts$": "@swc/jest",
11+
},
12+
testEnvironment: "node",
13+
testRegex: "\\.spec\\.[jt]s$",
14+
};
15+
16+
export default config;

lib/index.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from "node:path";
2+
23
import { cosmiconfig, cosmiconfigSync } from "cosmiconfig";
3-
import { describe, expect, it } from "vitest";
4+
45
import { TypeScriptLoader } from ".";
56

67
describe("TypeScriptLoader", () => {
@@ -37,7 +38,7 @@ describe("TypeScriptLoader", () => {
3738

3839
try {
3940
await cfg.load(path.resolve(fixturesPath, "invalid.fixture.ts"));
40-
throw new Error("Should fail to load invalid TS");
41+
fail("Should fail to load invalid TS");
4142
} catch (error: any) {
4243
expect(error?.name).toStrictEqual("TypeScriptCompileError");
4344
}

lib/loader.spec.ts

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,15 @@
11
import fs from "node:fs";
22
import path from "node:path";
3+
34
import { Loader } from "cosmiconfig";
4-
import {
5-
afterAll,
6-
afterEach,
7-
beforeAll,
8-
beforeEach,
9-
describe,
10-
expect,
11-
it,
12-
SpyInstance,
13-
vi,
14-
} from "vitest";
155
import * as tsnode from "ts-node";
166

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

20-
vi.mock("ts-node", async () => {
21-
const actualTsnode = await vi.importActual<typeof import("ts-node")>(
22-
"ts-node"
23-
);
24-
25-
const writableTsNode: any = {};
26-
Object.keys(actualTsnode).forEach((key) =>
27-
Object.defineProperty(writableTsNode, key, {
28-
value: (actualTsnode as any)[key],
29-
writable: true,
30-
})
31-
);
32-
33-
return writableTsNode;
34-
});
35-
3610
describe("TypeScriptLoader", () => {
3711
const fixturesPath = path.resolve(__dirname, "__fixtures__");
38-
const tsNodeSpy = vi.spyOn(tsnode, "register");
12+
const tsNodeSpy = jest.spyOn(tsnode, "register");
3913

4014
let loader: Loader;
4115

@@ -47,10 +21,6 @@ describe("TypeScriptLoader", () => {
4721
loader = TypeScriptLoader();
4822
});
4923

50-
afterAll(() => {
51-
vi.restoreAllMocks();
52-
});
53-
5424
it("should parse a valid TS file", () => {
5525
const filePath = path.resolve(fixturesPath, "valid.fixture.ts");
5626
loader(filePath, readFixtureContent(filePath));
@@ -72,7 +42,7 @@ describe("TypeScriptLoader", () => {
7242
try {
7343
const filePath = path.resolve(fixturesPath, "invalid.fixture.ts");
7444
loader(filePath, readFixtureContent(filePath));
75-
throw new Error(
45+
fail(
7646
"Error should be thrown upon failing to transpile an invalid TS file."
7747
);
7848
} catch (error: unknown) {
@@ -83,10 +53,10 @@ describe("TypeScriptLoader", () => {
8353
describe("ts-node", () => {
8454
const unknownError = "Test Error";
8555

86-
let stub: SpyInstance<[service: tsnode.Service], tsnode.Service>;
56+
let stub: jest.SpyInstance<tsnode.Service, [service: tsnode.Service]>;
8757

8858
beforeEach(() => {
89-
stub = vi.spyOn(tsnode, "register").mockImplementation(
59+
stub = jest.spyOn(tsnode, "register").mockImplementation(
9060
() =>
9161
({
9262
compile: (): string => {
@@ -105,7 +75,7 @@ describe("TypeScriptLoader", () => {
10575
it("rethrows an error if it is not an instance of Error", () => {
10676
try {
10777
loader("filePath", "readFixtureContent(filePath)");
108-
throw new Error(
78+
fail(
10979
"Error should be thrown upon failing to transpile an invalid TS file."
11080
);
11181
} catch (error: unknown) {

lib/loader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Loader } from "cosmiconfig";
22
import { register, RegisterOptions } from "ts-node";
3+
34
import { TypeScriptCompileError } from "./typescript-compile-error";
45

56
export function TypeScriptLoader(options?: RegisterOptions): Loader {

lib/typescript-compile-error.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { describe, expect, it } from "vitest";
21
import { TypeScriptCompileError } from "./typescript-compile-error";
32

43
describe("TypeScriptCompileError", () => {

0 commit comments

Comments
 (0)