Skip to content

Commit 08acbc4

Browse files
authored
chore: replace jest with vite (#700)
* chore: replace jest with vite * also lint vite.config.js * remove artifact
1 parent 9ab60c9 commit 08acbc4

File tree

10 files changed

+1261
-4945
lines changed

10 files changed

+1261
-4945
lines changed

cypress.json

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

package-lock.json

Lines changed: 1184 additions & 4892 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"scripts": {
1111
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1212
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
13-
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
13+
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json vite.config.js",
1414
"pretest": "npm run -s lint",
15-
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage"
15+
"test": "vitest run --coverage"
1616
},
1717
"repository": "github:octokit/request.js",
1818
"keywords": [
@@ -32,47 +32,15 @@
3232
"devDependencies": {
3333
"@octokit/auth-app": "^7.0.0",
3434
"@octokit/tsconfig": "^3.0.0",
35-
"@sinonjs/fake-timers": "^11.2.2",
36-
"@types/jest": "^29.0.0",
3735
"@types/node": "^20.0.0",
38-
"@types/sinonjs__fake-timers": "^8.1.5",
36+
"@vitest/coverage-v8": "^1.6.0",
3937
"esbuild": "^0.21.0",
4038
"fetch-mock": "^10.0.0",
4139
"glob": "^10.2.4",
42-
"jest": "^29.0.0",
4340
"prettier": "3.3.2",
4441
"semantic-release-plugin-update-version-in-files": "^1.0.0",
45-
"ts-jest": "^29.0.0",
46-
"typescript": "^5.0.0"
47-
},
48-
"jest": {
49-
"extensionsToTreatAsEsm": [
50-
".ts"
51-
],
52-
"transform": {
53-
"^.+\\.(ts|tsx)$": [
54-
"ts-jest",
55-
{
56-
"tsconfig": "test/tsconfig.test.json",
57-
"useESM": true
58-
}
59-
]
60-
},
61-
"coverageThreshold": {
62-
"global": {
63-
"statements": 100,
64-
"branches": 100,
65-
"functions": 100,
66-
"lines": 100
67-
}
68-
},
69-
"modulePathIgnorePatterns": [
70-
"<rootDir>/pkg"
71-
],
72-
"testEnvironment": "node",
73-
"moduleNameMapper": {
74-
"^(.+)\\.jsx?$": "$1"
75-
}
42+
"typescript": "^5.0.0",
43+
"vitest": "^1.6.0"
7644
},
7745
"release": {
7846
"branches": [

scripts/build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function main() {
5454
delete pkg.scripts;
5555
delete pkg.prettier;
5656
delete pkg.release;
57-
delete pkg.jest;
57+
5858
await writeFile(
5959
"pkg/package.json",
6060
JSON.stringify(

src/fetch-wrapper.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,12 @@ function toErrorMessage(data: any) {
185185

186186
let suffix: string;
187187

188-
// istanbul ignore else - just in case
189188
if ("documentation_url" in data) {
190189
suffix = ` - ${data.documentation_url}`;
191190
} else {
192191
suffix = "";
193192
}
194193

195-
// istanbul ignore else - just in case
196194
if ("message" in data) {
197195
if (Array.isArray(data.errors)) {
198196
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}${suffix}`;
@@ -201,6 +199,5 @@ function toErrorMessage(data: any) {
201199
return `${data.message}${suffix}`;
202200
}
203201

204-
// istanbul ignore next - just in case
205202
return `Unknown error: ${JSON.stringify(data)}`;
206203
}

test/defaults.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fetchMock from "fetch-mock";
22

3+
import { describe, it, expect } from "vitest";
34
import { request } from "../src/index.ts";
45

56
describe("endpoint.defaults()", () => {

test/is-plain-object.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, it, expect } from "vitest";
12
import { isPlainObject } from "../src/is-plain-object.ts";
23

34
describe("isPlainObject", () => {

test/request.test.ts

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ import fs from "node:fs";
22
import stream from "node:stream";
33
import { ReadableStream } from "node:stream/web";
44

5+
import { describe, it, expect, vi } from "vitest";
56
import { getUserAgent } from "universal-user-agent";
67
import fetchMock from "fetch-mock";
78
import { createAppAuth } from "@octokit/auth-app";
8-
import fakeTimers from "@sinonjs/fake-timers";
99
import type {
1010
EndpointOptions,
1111
RequestInterface,
1212
ResponseHeaders,
1313
} from "@octokit/types";
1414

1515
import { request } from "../src/index.ts";
16-
import { jest } from "@jest/globals";
1716

1817
const userAgent = `octokit-request.js/0.0.0-development ${getUserAgent()}`;
1918
const __filename = new URL(import.meta.url);
@@ -73,7 +72,7 @@ describe("request()", () => {
7372
});
7473

7574
it("README authentication example", async () => {
76-
const clock = fakeTimers.install({
75+
const clock = vi.useFakeTimers({
7776
now: 0,
7877
toFake: ["Date"],
7978
});
@@ -158,7 +157,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
158157
title: "Hello from the engine room",
159158
});
160159
expect(mock.done()).toBe(true);
161-
clock.reset();
160+
vi.useRealTimers();
162161
});
163162

164163
it("Request with body", () => {
@@ -808,7 +807,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
808807
},
809808
})
810809
.then(() => {
811-
fail("This should return error.");
810+
throw new Error("This should return error.");
812811
})
813812
.catch((error) => {
814813
expect(error).toHaveProperty(
@@ -840,7 +839,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
840839
},
841840
);
842841

843-
const warn = jest.fn();
842+
const warn = vi.fn();
844843

845844
return request("GET /teams/{team_id}", {
846845
headers: {
@@ -878,7 +877,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
878877
},
879878
);
880879

881-
const warn = jest.fn();
880+
const warn = vi.fn();
882881

883882
return request("GET /teams/{team_id}", {
884883
headers: {
@@ -1121,4 +1120,52 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
11211120
},
11221121
});
11231122
});
1123+
1124+
it("invalid error responses should result in errors with a message field describing the error as an unknown error", function () {
1125+
const mock = fetchMock.sandbox().mock(
1126+
"https://request-errors-test.com/repos/gr2m/sandbox/branches/gr2m-patch-1/protection",
1127+
{
1128+
status: 400,
1129+
body: {},
1130+
},
1131+
{
1132+
method: "PUT",
1133+
headers: {
1134+
accept: "application/vnd.github.v3+json",
1135+
authorization: "token secret123",
1136+
},
1137+
},
1138+
);
1139+
1140+
return request("PUT /repos/{owner}/{repo}/branches/{branch}/protection", {
1141+
baseUrl: "https://request-errors-test.com",
1142+
headers: {
1143+
authorization: "token secret123",
1144+
},
1145+
owner: "gr2m",
1146+
repo: "sandbox",
1147+
branch: "gr2m-patch-1",
1148+
required_status_checks: { strict: true, contexts: ["wip"] },
1149+
enforce_admins: true,
1150+
required_pull_request_reviews: {
1151+
required_approving_review_count: 1,
1152+
dismiss_stale_reviews: true,
1153+
require_code_owner_reviews: true,
1154+
dismissal_restrictions: { users: [], teams: [] },
1155+
},
1156+
restrictions: { users: [], teams: [] },
1157+
request: {
1158+
fetch: mock,
1159+
},
1160+
})
1161+
.then(() => {
1162+
throw new Error("This should return error.");
1163+
})
1164+
.catch((error) => {
1165+
expect(error).toHaveProperty(
1166+
"message",
1167+
`Unknown error: ${JSON.stringify({})}`,
1168+
);
1169+
});
1170+
});
11241171
});

test/tsconfig.test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"compilerOptions": {
44
"emitDeclarationOnly": false,
55
"noEmit": true,
6-
"allowImportingTsExtensions": true
6+
"allowImportingTsExtensions": true,
7+
"types": ["vitest/globals"]
78
},
89
"include": ["src/**/*"]
910
}

vite.config.js

Lines changed: 13 additions & 0 deletions
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)