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

maint: modernize devDependencies #314

Closed
wants to merge 2 commits into from
Closed
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
5,918 changes: 1,818 additions & 4,100 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 5 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
@@ -12,7 +12,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/auth-oauth-user.js",
"keywords": [
@@ -33,53 +33,18 @@
"devDependencies": {
"@octokit/core": "^6.1.3",
"@octokit/tsconfig": "^4.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^22.0.0",
"@vitest/coverage-v8": "^2.1.8",
"esbuild": "^0.25.0",
"fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1",
"fetch-mock": "^11.0.0",
"glob": "^11.0.0",
"jest": "^29.0.0",
"mockdate": "^3.0.4",
"prettier": "3.4.2",
"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.1.8"
},
"release": {
"branches": [
"+([0-9]).x",
"main",
"next",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
4 changes: 2 additions & 2 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ export async function auth(
| GitHubAppAuthentication
| GitHubAppAuthenticationWithExpiration;
} catch (error: any) {
// istanbul ignore else
/* v8 ignore next 5 */
if (error.status === 404) {
error.message = "[@octokit/auth-oauth-user] Token is invalid";

@@ -143,7 +143,7 @@ export async function auth(
request: state.request,
});
} catch (error: any) {
// istanbul ignore if
/* v8 ignore next */
if (error.status !== 404) throw error;
}

6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as OctokitTypes from "@octokit/types";
import * as DeviceTypes from "@octokit/auth-oauth-device";
import * as OAuthMethodsTypes from "@octokit/oauth-methods";
import type * as OctokitTypes from "@octokit/types";
import type * as DeviceTypes from "@octokit/auth-oauth-device";
import type * as OAuthMethodsTypes from "@octokit/oauth-methods";

export type ClientType = "oauth-app" | "github-app";

33 changes: 26 additions & 7 deletions test/octokit.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { describe, expect, it, test } from "vitest";
import { Octokit } from "@octokit/core";
import fetchMock, { type MockMatcherFunction } from "fetch-mock";
import fetchMock from "fetch-mock";

import { createOAuthUserAuth } from "../src/index.js";

describe("Octokit + OAuth web flow", () => {
it("README example", async () => {
const matchCreateTokenRequest: MockMatcherFunction = (url, options) => {
const matchCreateTokenRequest: fetchMock.MockMatcherFunction = (
url,
options,
) => {
expect(url).toEqual("https://github.com/login/oauth/access_token");
expect(options.headers).toEqual(
expect.objectContaining({
@@ -17,7 +21,10 @@ describe("Octokit + OAuth web flow", () => {
return true;
};

const matchGetUserRequest: MockMatcherFunction = (url, options) => {
const matchGetUserRequest: fetchMock.MockMatcherFunction = (
url,
options,
) => {
expect(url).toEqual("https://api.github.com/user");
expect(options.headers).toEqual(
expect.objectContaining({
@@ -61,7 +68,10 @@ describe("Octokit + OAuth web flow", () => {
});

it("GitHub App auth", async () => {
const matchCreateTokenRequest: MockMatcherFunction = (url, options) => {
const matchCreateTokenRequest: fetchMock.MockMatcherFunction = (
url,
options,
) => {
expect(url).toEqual("https://github.com/login/oauth/access_token");
expect(options.headers).toEqual(
expect.objectContaining({
@@ -73,7 +83,10 @@ describe("Octokit + OAuth web flow", () => {
return true;
};

const matchGetUserRequest: MockMatcherFunction = (url, options) => {
const matchGetUserRequest: fetchMock.MockMatcherFunction = (
url,
options,
) => {
expect(url).toEqual("https://api.github.com/user");
expect(options.headers).toEqual(
expect.objectContaining({
@@ -119,7 +132,10 @@ describe("Octokit + OAuth web flow", () => {
});

test("Sets clientId/clientSecret as Basic auth for /authentication/{clientId}/* requests", async () => {
const matchCheckTokenRequest: MockMatcherFunction = (url, options) => {
const matchCheckTokenRequest: fetchMock.MockMatcherFunction = (
url,
options,
) => {
expect(url).toEqual(
"https://api.github.com/applications/1234567890abcdef1234/token",
);
@@ -166,7 +182,10 @@ test("Sets clientId/clientSecret as Basic auth for /authentication/{clientId}/*
});

test("Sets no auth for OAuth Web flow requests", async () => {
const matchCreateTokenRequest: MockMatcherFunction = (url, options) => {
const matchCreateTokenRequest: fetchMock.MockMatcherFunction = (
url,
options,
) => {
expect(url).toEqual("https://github.com/login/oauth/access_token");
// @ts-ignore
expect(options.headers.authorization).toBeUndefined();
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, expect, it } from "vitest";
import { createOAuthUserAuth, requiresBasicAuth } from "../src/index.js";

describe("Smoke test", () => {
6 changes: 3 additions & 3 deletions test/standalone.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it, test, vi } from "vitest";
import fetchMock from "fetch-mock";
import MockDate from "mockdate";
import { request } from "@octokit/request";
import { jest } from "@jest/globals";

import { createOAuthUserAuth } from "../src/index.js";

@@ -187,7 +187,7 @@ describe("OAuth device flow", () => {
user_code: "usercode123",
verification_uri: "https://github.com/login/device",
expires_in: 900,
// use low number because jest.useFakeTimers() & jest.runAllTimers() didn't work for me
// use low number because vi.useFakeTimers() & vi.runAllTimers() didn't work for me
interval: 0.005,
},
{
@@ -223,7 +223,7 @@ describe("OAuth device flow", () => {
},
);

const onVerification = jest.fn();
const onVerification = vi.fn();
const auth = createOAuthUserAuth({
clientId: "1234567890abcdef1234",
clientSecret: "secret",
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,
},
},
},
});