Skip to content

Commit 5a681c3

Browse files
authored
chore: use vitest (#450)
1 parent 462e351 commit 5a681c3

25 files changed

+2994
-4989
lines changed

package-lock.json

+2,949-4,949
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-34
Original file line numberDiff line numberDiff line change
@@ -45,58 +45,28 @@
4545
"@octokit/fixtures-server": "^8.1.0",
4646
"@octokit/request": "^9.1.1",
4747
"@octokit/tsconfig": "^3.0.0",
48-
"@types/jest": "^29.5.11",
4948
"@types/node": "^20.11.5",
49+
"@vitest/coverage-v8": "^2.0.3",
5050
"esbuild": "^0.23.0",
5151
"fetch-mock": "^10.0.0",
5252
"glob": "^11.0.0",
53-
"jest": "^29.7.0",
5453
"nock": "^13.5.0",
5554
"prettier": "^3.2.4",
5655
"semantic-release-plugin-update-version-in-files": "^1.1.0",
57-
"ts-jest": "^29.1.1",
5856
"typescript": "^5.3.3",
59-
"undici": "^6.4.0"
57+
"undici": "^6.4.0",
58+
"vitest": "^2.0.3"
6059
},
6160
"scripts": {
6261
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
63-
"coverage": "nyc report --reporter=html && open coverage/index.html",
6462
"lint": "prettier --check \"{src,test}/**/*.{js,json,ts}\" \"docs/*.js\" docs/package.json \"docs/src/**/*\" *.md package.json",
6563
"lint:fix": "prettier --write \"{src,test}/**/*.{js,json,ts}\" \"docs/*.js\" docs/package.json \"docs/src/**/*\" *.md package.json",
6664
"start-fixtures-server": "octokit-fixtures-server",
6765
"pretest": "npm run -s lint",
68-
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
66+
"test": "vitest run --coverage",
6967
"test:typescript": "npx tsc --noEmit --declaration --allowImportingTsExtensions --moduleResolution node16 --module node16 --noUnusedLocals test/typescript-validate.ts"
7068
},
7169
"license": "MIT",
72-
"jest": {
73-
"extensionsToTreatAsEsm": [
74-
".ts"
75-
],
76-
"transform": {
77-
"^.+\\.(ts|tsx)$": [
78-
"ts-jest",
79-
{
80-
"tsconfig": "test/tsconfig.test.json",
81-
"useESM": true
82-
}
83-
]
84-
},
85-
"testPathIgnorePatterns": [
86-
"/docs/"
87-
],
88-
"coverageThreshold": {
89-
"global": {
90-
"statements": 100,
91-
"branches": 100,
92-
"functions": 100,
93-
"lines": 100
94-
}
95-
},
96-
"moduleNameMapper": {
97-
"^(.+)\\.jsx?$": "$1"
98-
}
99-
},
10070
"release": {
10171
"branches": [
10272
"+([0-9]).x",

test/integration/smoke.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { describe, it, expect, vi } from "vitest";
12
import fetchMock from "fetch-mock";
2-
import { jest } from "@jest/globals";
33

44
import { Octokit } from "../../src/index.ts";
55

@@ -64,10 +64,10 @@ describe("Smoke tests", () => {
6464
.getOnce("path:/", { status: 404, body: {} }, { overwriteRoutes: false });
6565

6666
const consoleStub = {
67-
debug: jest.fn(),
68-
info: jest.fn(),
69-
warn: jest.fn(),
70-
error: jest.fn(),
67+
debug: vi.fn(),
68+
info: vi.fn(),
69+
warn: vi.fn(),
70+
error: vi.fn(),
7171
};
7272

7373
const octokit = new Octokit({

test/issues/881-redirect-url.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from "vitest";
12
import fetchMock from "fetch-mock";
23

34
import { Octokit } from "../../src/index.ts";

test/scenarios/add-and-remove-repository-collaborator.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { loadFixture, fixtureToInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/add-labels-to-issue.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/branch-protection.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/create-file.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/create-status.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/errors.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {
@@ -23,7 +24,7 @@ describe("api.github.com", () => {
2324
.catch((error) => {
2425
expect(error.message).toMatch(
2526
new RegExp(
26-
`Validation Failed: {\\"resource\\":\\"Label\\",\\"code\\":\\"invalid\\",\\"field\\":\\"color\\"} - http://localhost:3000/docs.github.com/[a-z0-9]{10,11}/rest/reference/issues#create-a-label`,
27+
`Validation Failed: {\\"resource\\":\\"Label\\",\\"code\\":\\"invalid\\",\\"field\\":\\"color\\"} - http://localhost:3000/docs\\.github\\.com/[a-z0-9]{10,12}/rest/reference/issues#create-a-label`,
2728
),
2829
);
2930
expect(error.response.data.errors).toEqual([

test/scenarios/get-archive.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe.skip("api.github.com", () => {

test/scenarios/get-content.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe.skip("api.github.com", () => {

test/scenarios/get-organization.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/get-repository.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/labels.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/lock-issue.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/mark-notifications-as-read.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/markdown.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/paginate-issues-async-await.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
// this file is not run directly but instead required in paginate-issues-test.js
23
// for Node v10 and higher only
34

@@ -28,6 +29,7 @@ describe("api.github.com", () => {
2829
// @ts-ignore TODO: *.endpoint.merge on endpoint methods should always return .url property
2930
octokit.rest.issues.listForRepo.endpoint.merge(options),
3031
)) {
32+
// @ts-ignore
3133
results.push(...result.data);
3234
}
3335
expect(results.length).toEqual(13);

test/scenarios/paginate-issues.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
type IteratorResult = {

test/scenarios/project-cards.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/release-assets.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/rename-repository.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

test/scenarios/search-issues.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, beforeEach, it, expect } from "vitest";
12
import { getInstance, type OctokitType } from "../util.ts";
23

34
describe("api.github.com", () => {

vite.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from "vite";
2+
3+
export default defineConfig({
4+
test: {
5+
coverage: {
6+
include: ["src/**/*.ts"],
7+
reporter: ["html"],
8+
thresholds: {
9+
100: true,
10+
},
11+
},
12+
},
13+
});

0 commit comments

Comments
 (0)