Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace jest with vitest #275

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,628 changes: 3,853 additions & 6,775 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 4 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage"
"test": "vitest run --coverage"
},
"repository": "https://github.com/octokit/oauth-methods.js",
"keywords": [
Expand All @@ -28,42 +28,16 @@
},
"devDependencies": {
"@octokit/tsconfig": "^3.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"@vitest/coverage-v8": "^2.0.2",
"esbuild": "^0.23.0",
"fetch-mock": "npm:@gr2m/[email protected]",
"glob": "^11.0.0",
"jest": "^29.0.0",
"prettier": "3.3.2",
"semantic-release": "^24.0.0",
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"ts-jest": "^29.0.0",
"typescript": "^5.0.0"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
"coverageThreshold": {
"global": {
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
"typescript": "^5.0.0",
"vitest": "^2.0.2"
},
"release": {
"branches": [
Expand Down
6 changes: 2 additions & 4 deletions src/check-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ export async function checkToken(
export async function checkToken(
options: CheckTokenOAuthAppOptions | CheckTokenGitHubAppOptions,
): Promise<any> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const response = await request("POST /applications/{client_id}/token", {
headers: {
Expand Down
6 changes: 2 additions & 4 deletions src/create-device-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ export type CreateDeviceCodeDeviceTokenResponse = OctokitResponse<{
export async function createDeviceCode(
options: CreateDeviceCodeOAuthAppOptions | CreateDeviceCodeGitHubAppOptions,
): Promise<CreateDeviceCodeDeviceTokenResponse> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const parameters: Record<string, unknown> = {
client_id: options.clientId,
Expand Down
6 changes: 2 additions & 4 deletions src/delete-authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ export async function deleteAuthorization(
| DeleteAuthorizationOAuthAppOptions
| DeleteAuthorizationGitHubAppOptions,
): Promise<any> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const auth = btoa(`${options.clientId}:${options.clientSecret}`);
return request(
Expand Down
6 changes: 2 additions & 4 deletions src/delete-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ export async function deleteToken(
export async function deleteToken(
options: DeleteTokenOAuthAppOptions | DeleteTokenGitHubAppOptions,
): Promise<any> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const auth = btoa(`${options.clientId}:${options.clientSecret}`);
return request(
Expand Down
6 changes: 2 additions & 4 deletions src/exchange-device-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ export async function exchangeDeviceCode(
| ExchangeDeviceCodeOAuthAppOptionsWithoutClientSecret
| ExchangeDeviceCodeGitHubAppOptionsWithoutClientSecret,
): Promise<any> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const response = await oauthRequest(
request,
Expand Down
6 changes: 2 additions & 4 deletions src/exchange-web-flow-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ export async function exchangeWebFlowCode(
| ExchangeWebFlowCodeOAuthAppOptions
| ExchangeWebFlowCodeGitHubAppOptions,
): Promise<any> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const response = await oauthRequest(
request,
Expand Down
6 changes: 2 additions & 4 deletions src/refresh-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ export type RefreshTokenResponse =
export async function refreshToken(
options: RefreshTokenOptions,
): Promise<RefreshTokenResponse> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const response = await oauthRequest(
request,
Expand Down
6 changes: 2 additions & 4 deletions src/reset-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ export async function resetToken(
export async function resetToken(
options: ResetTokenOAuthAppOptions | ResetTokenGitHubAppOptions,
): Promise<any> {
const request =
options.request ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = options.request || defaultRequest;

const auth = btoa(`${options.clientId}:${options.clientSecret}`);
const response = await request(
Expand Down
6 changes: 2 additions & 4 deletions src/scope-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ export async function scopeToken(
...requestOptions
} = options;

const request =
optionsRequest ||
/* istanbul ignore next: we always pass a custom request in tests */
defaultRequest;
/* v8 ignore next 1: we always pass a custom request in tests */
const request = optionsRequest || defaultRequest;

const response = await request(
"POST /applications/{client_id}/token/scoped",
Expand Down
1 change: 1 addition & 0 deletions test/check-token.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { checkToken } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/create-device-code.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { createDeviceCode } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/delete-authorization.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { deleteAuthorization } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/delete-token.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { deleteToken } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/exchange-device-code.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { exchangeDeviceCode } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/exchange-web-flow-code.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { exchangeWebFlowCode } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/get-web-flow-authorization-url.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { request } from "@octokit/request";
import { describe, it, expect } from "vitest";
import { getWebFlowAuthorizationUrl } from "../src/index.js";

describe("getWebFlowAuthorizationUrl()", () => {
Expand Down
1 change: 1 addition & 0 deletions test/refresh-token.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { refreshToken } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/reset-token.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { resetToken } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/scope-token.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fetchMock from "fetch-mock";
import { describe, it, expect } from "vitest";
import { request } from "@octokit/request";
import { scopeToken } from "../src/index.js";

Expand Down
1 change: 1 addition & 0 deletions test/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from "vitest";
import {
getWebFlowAuthorizationUrl,
exchangeWebFlowCode,
Expand Down
8 changes: 0 additions & 8 deletions test/tsconfig.test.json

This file was deleted.

13 changes: 13 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from "vite";

export default defineConfig({
test: {
coverage: {
include: ["src/**/*.ts"],
reporter: ["html"],
thresholds: {
100: true,
},
},
},
});