Skip to content

Commit 20d91d5

Browse files
committed
move jest to vitest
1 parent f89d4db commit 20d91d5

File tree

7 files changed

+40
-35
lines changed

7 files changed

+40
-35
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ check:
3434
## test-unit: run unit tests
3535
.PHONY: test-unit
3636
test-unit:
37-
npx jest --verbose --detectOpenHandles --config jest.config.js test/unit
37+
npx vitest --dir test/unit --run --reporter verbose --config vitest.config.ts
3838

3939
## test-integration: run integration tests
4040
.PHONY: test-integration
4141
test-integration:
42-
npx jest --verbose --detectOpenHandles --config jest.config.js test/integration --forceExit
42+
npx vitest --dir test/integration --run --reporter verbose --config vitest.config.ts
4343

4444
## test: run all tests
4545
.PHONY: test

jest.config.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/integration/HttpsCheckHook.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { readFileSync } from "fs";
33
import { UnstructuredClient } from "../../src";
44
import { PartitionResponse } from "../../src/sdk/models/operations";
55
import { PartitionParameters, Strategy } from "../../src/sdk/models/shared";
6+
import { describe, it, expect} from 'vitest';
67

78
const localServer = "http://localhost:8000"
89

test/integration/SplitPdfHook.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { readFileSync } from "fs";
33
import { UnstructuredClient } from "../../src";
44
import { PartitionResponse } from "../../src/sdk/models/operations";
55
import { PartitionParameters, Strategy } from "../../src/sdk/models/shared";
6+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
67

78
const localServer = "http://localhost:8000";
89

910
describe("SplitPdfHook integration tests check splitted file is same as not splitted", () => {
1011
const FAKE_API_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
11-
const consoleInfoSpy = jest.spyOn(console, "info");
12-
const consoleWarnSpy = jest.spyOn(console, "warn");
13-
const consoleErrorSpy = jest.spyOn(console, "error");
12+
const consoleInfoSpy = vi.spyOn(console, "info");
13+
const consoleWarnSpy = vi.spyOn(console, "warn");
14+
const consoleErrorSpy = vi.spyOn(console, "error");
1415

1516
let client = new UnstructuredClient({
1617
serverURL: localServer,
@@ -273,9 +274,9 @@ describe("SplitPdfHook integration tests check splitted file is same as not spli
273274

274275
describe("SplitPdfHook integration tests page range parameter", () => {
275276
const FAKE_API_KEY = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
276-
const consoleInfoSpy = jest.spyOn(console, "info");
277-
const consoleWarnSpy = jest.spyOn(console, "warn");
278-
const consoleErrorSpy = jest.spyOn(console, "error");
277+
const consoleInfoSpy = vi.spyOn(console, "info");
278+
const consoleWarnSpy = vi.spyOn(console, "warn");
279+
const consoleErrorSpy = vi.spyOn(console, "error");
279280

280281
let client = new UnstructuredClient({
281282
serverURL: localServer,

test/unit/HttpsCheckHook.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { HttpsCheckHook } from "../../src/hooks/custom/HttpsCheckHook";
22
import { HTTPClient } from "../../src/lib/http";
3+
import { describe, it, expect, vi, afterEach } from 'vitest';
34

45
describe("HttpsCheckHook", () => {
5-
const consoleSpy = jest.spyOn(global.console, "warn");
6+
const consoleSpy = vi.spyOn(global.console, "warn");
67

78
afterEach(() => {
89
consoleSpy.mockClear();

test/unit/utils/pdf.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { PDFDocument } from "pdf-lib";
22
import { readFileSync } from "node:fs";
3+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
34

45
import {
56
loadPdf,
@@ -20,14 +21,14 @@ describe("Pdf utility functions", () => {
2021
});
2122

2223
afterEach(() => {
23-
jest.clearAllMocks();
24+
vi.clearAllMocks();
2425
});
2526

2627
describe("pdfPagesToBlob", () => {
2728
it("should convert range of pages to a Blob object", async () => {
28-
const copyMock = jest.spyOn(PDFDocument.prototype, "copyPages");
29-
const saveMock = jest.spyOn(PDFDocument.prototype, "save");
30-
const addMock = jest.spyOn(PDFDocument.prototype, "addPage");
29+
const copyMock = vi.spyOn(PDFDocument.prototype, "copyPages");
30+
const saveMock = vi.spyOn(PDFDocument.prototype, "save");
31+
const addMock = vi.spyOn(PDFDocument.prototype, "addPage");
3132

3233
// Call the method
3334
const result = await pdfPagesToBlob(pdf, 4, 8);
@@ -106,7 +107,7 @@ describe("Pdf utility functions", () => {
106107
it("should return true, null, and 0 if the file is not a PDF", async () => {
107108
const file = {
108109
name: "document.txt",
109-
content: jest.fn().mockResolvedValue(new ArrayBuffer(0)),
110+
content: vi.fn().mockResolvedValue(new ArrayBuffer(0)),
110111
};
111112

112113
const result = await loadPdf(file as any);
@@ -118,7 +119,7 @@ describe("Pdf utility functions", () => {
118119
it("should return true, null, and 0 if the file is not a PDF without basing on file extension", async () => {
119120
const file = {
120121
name: "uuid1234",
121-
content: jest.fn().mockResolvedValue(new ArrayBuffer(0)),
122+
content: vi.fn().mockResolvedValue(new ArrayBuffer(0)),
122123
};
123124

124125
const result = await loadPdf(file as any);
@@ -131,7 +132,7 @@ describe("Pdf utility functions", () => {
131132
it("should return true, null, and 0 if there is an error while loading the PDF", async () => {
132133
const file = {
133134
name: "document.pdf",
134-
arrayBuffer: jest.fn().mockRejectedValue(new ArrayBuffer(0)),
135+
arrayBuffer: vi.fn().mockRejectedValue(new ArrayBuffer(0)),
135136
};
136137

137138
const result = await loadPdf(file as any);
@@ -147,7 +148,7 @@ describe("Pdf utility functions", () => {
147148
arrayBuffer: () => file.buffer,
148149
};
149150

150-
const loadMock = jest.spyOn(PDFDocument, "load");
151+
const loadMock = vi.spyOn(PDFDocument, "load");
151152

152153
const [error, _, pages] = await loadPdf(f as any);
153154

@@ -164,8 +165,8 @@ describe("Pdf utility functions", () => {
164165
arrayBuffer: () => file.buffer,
165166
};
166167

167-
jest.clearAllMocks(); // Reset Mocks Between Tests
168-
const loadMock = jest.spyOn(PDFDocument, "load");
168+
vi.clearAllMocks(); // Reset Mocks Between Tests
169+
const loadMock = vi.spyOn(PDFDocument, "load");
169170

170171
const [error, _, pages] = await loadPdf(f as any);
171172

vitest.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// <reference types="vitest" />
2+
3+
import { defineConfig } from 'vitest/config'
4+
5+
export default defineConfig({
6+
esbuild: {
7+
// Transpile all files with ESBuild to remove comments from code coverage.
8+
// Required for `test.coverage.ignoreEmptyLines` to work:
9+
include: ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.ts', '**/*.tsx'],
10+
},
11+
test: {
12+
coverage: {
13+
provider: 'v8',
14+
ignoreEmptyLines: true,
15+
},
16+
},
17+
})

0 commit comments

Comments
 (0)