Skip to content

Commit

Permalink
chore: replace jest with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Jul 13, 2024
1 parent 6e3332f commit 596988e
Show file tree
Hide file tree
Showing 9 changed files with 4,292 additions and 9,532 deletions.
13,671 changes: 4,222 additions & 9,449 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 @@ -12,7 +12,7 @@
"lint": "prettier --check '{src,test,scripts}/**/*' '!scripts/generated/*' README.md package.json",
"lint:fix": "prettier --write '{src,test,scripts}/**/*' '!scripts/generated/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"test": "vitest run --coverage",
"test:ts": "npx tsc --noEmit --declaration --noUnusedLocals --allowImportingTsExtensions test/validate-typescript.ts",
"update-endpoints": "npm-run-all update-endpoints:*",
"update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json",
Expand All @@ -37,43 +37,17 @@
"@octokit/plugin-rest-endpoint-methods": "^13.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/fetch-mock": "^7.3.1",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
"@vitest/coverage-v8": "^2.0.2",
"esbuild": "^0.23.0",
"fetch-mock": "npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1",
"github-openapi-graphql-query": "^4.0.0",
"glob": "^11.0.0",
"jest": "^29.0.0",
"npm-run-all2": "^6.0.0",
"prettier": "3.3.2",
"semantic-release-plugin-update-version-in-files": "^1.0.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
101 changes: 48 additions & 53 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Octokit } from "@octokit/core";
import * as OctokitTypes from "@octokit/types";
import type { Octokit } from "@octokit/core";
import type {
EndpointOptions,
GetResponseTypeFromEndpointMethod,
OctokitResponse,
RequestInterface,
RequestParameters,
Route,
} from "@octokit/types";

export type {
EndpointOptions,
Expand Down Expand Up @@ -55,7 +62,7 @@ type NormalizeResponse<T> = T & { data: GetResultsType<T> };
type DataType<T> = "data" extends keyof T ? T["data"] : unknown;

export interface MapFunction<
T = OctokitTypes.OctokitResponse<PaginationResults<unknown>>,
T = OctokitResponse<PaginationResults<unknown>>,
M = unknown[],
> {
(response: T, done: () => void): M;
Expand All @@ -73,16 +80,16 @@ export interface PaginateInterface {
* @param {function} mapFn Optional method to map each response to a custom array
*/
<T, M>(
options: OctokitTypes.EndpointOptions,
mapFn: MapFunction<OctokitTypes.OctokitResponse<PaginationResults<T>>, M[]>,
options: EndpointOptions,
mapFn: MapFunction<OctokitResponse<PaginationResults<T>>, M[]>,
): Promise<PaginationResults<M>>;

/**
* Paginate a request using endpoint options
*
* @param {object} options Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<T>(options: OctokitTypes.EndpointOptions): Promise<PaginationResults<T>>;
<T>(options: EndpointOptions): Promise<PaginationResults<T>>;

// Using route string as first parameter

Expand Down Expand Up @@ -136,11 +143,11 @@ export interface PaginateInterface {
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
* @param {object} parameters? URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<T, R extends OctokitTypes.Route = OctokitTypes.Route>(
<T, R extends Route = Route>(
route: R,
parameters?: R extends keyof PaginatingEndpoints
? PaginatingEndpoints[R]["parameters"]
: OctokitTypes.RequestParameters,
: RequestParameters,
): Promise<T[]>;

// Using request method as first parameter
Expand All @@ -151,10 +158,10 @@ export interface PaginateInterface {
* @param {string} request Request method (`octokit.request` or `@octokit/request`)
* @param {function} mapFn? Optional method to map each response to a custom array
*/
<R extends OctokitTypes.RequestInterface, M extends unknown[]>(
<R extends RequestInterface, M extends unknown[]>(
request: R,
mapFn: MapFunction<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>,
NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>,
M
>,
): Promise<M>;
Expand All @@ -166,11 +173,11 @@ export interface PaginateInterface {
* @param {object} parameters URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
* @param {function} mapFn? Optional method to map each response to a custom array
*/
<R extends OctokitTypes.RequestInterface, M extends unknown[]>(
<R extends RequestInterface, M extends unknown[]>(
request: R,
parameters: Parameters<R>[0],
mapFn: MapFunction<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>,
NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>,
M
>,
): Promise<M>;
Expand All @@ -181,12 +188,10 @@ export interface PaginateInterface {
* @param {string} request Request method (`octokit.request` or `@octokit/request`)
* @param {object} parameters? URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<R extends OctokitTypes.RequestInterface>(
<R extends RequestInterface>(
request: R,
parameters?: Parameters<R>[0],
): Promise<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>["data"]
>;
): Promise<NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>["data"]>;

iterator: {
// Using object as first parameter
Expand All @@ -198,10 +203,8 @@ export interface PaginateInterface {
* @param {object} options Must set `method` and `url`. Plus URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<T>(
options: OctokitTypes.EndpointOptions,
): AsyncIterableIterator<
OctokitTypes.OctokitResponse<PaginationResults<T>>
>;
options: EndpointOptions,
): AsyncIterableIterator<OctokitResponse<PaginationResults<T>>>;

// Using route string as first parameter

Expand All @@ -216,7 +219,7 @@ export interface PaginateInterface {
route: R,
parameters?: PaginatingEndpoints[R]["parameters"],
): AsyncIterableIterator<
OctokitTypes.OctokitResponse<DataType<PaginatingEndpoints[R]["response"]>>
OctokitResponse<DataType<PaginatingEndpoints[R]["response"]>>
>;

/**
Expand All @@ -226,14 +229,12 @@ export interface PaginateInterface {
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<T, R extends OctokitTypes.Route = OctokitTypes.Route>(
<T, R extends Route = Route>(
route: R,
parameters?: R extends keyof PaginatingEndpoints
? PaginatingEndpoints[R]["parameters"]
: OctokitTypes.RequestParameters,
): AsyncIterableIterator<
OctokitTypes.OctokitResponse<PaginationResults<T>>
>;
: RequestParameters,
): AsyncIterableIterator<OctokitResponse<PaginationResults<T>>>;

// Using request method as first parameter

Expand All @@ -244,11 +245,11 @@ export interface PaginateInterface {
* @param {string} request `@octokit/request` or `octokit.request` method
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<R extends OctokitTypes.RequestInterface>(
<R extends RequestInterface>(
request: R,
parameters?: Parameters<R>[0],
): AsyncIterableIterator<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>
NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>
>;
};
}
Expand All @@ -267,8 +268,8 @@ export interface ComposePaginateInterface {
*/
<T, M>(
octokit: Octokit,
options: OctokitTypes.EndpointOptions,
mapFn: MapFunction<OctokitTypes.OctokitResponse<PaginationResults<T>>, M[]>,
options: EndpointOptions,
mapFn: MapFunction<OctokitResponse<PaginationResults<T>>, M[]>,
): Promise<PaginationResults<M>>;

/**
Expand All @@ -279,7 +280,7 @@ export interface ComposePaginateInterface {
*/
<T>(
octokit: Octokit,
options: OctokitTypes.EndpointOptions,
options: EndpointOptions,
): Promise<PaginationResults<T>>;

// Using route string as first parameter
Expand Down Expand Up @@ -341,12 +342,12 @@ export interface ComposePaginateInterface {
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
* @param {object} parameters? URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<T, R extends OctokitTypes.Route = OctokitTypes.Route>(
<T, R extends Route = Route>(
octokit: Octokit,
route: R,
parameters?: R extends keyof PaginatingEndpoints
? PaginatingEndpoints[R]["parameters"]
: OctokitTypes.RequestParameters,
: RequestParameters,
): Promise<T[]>;

// Using request method as first parameter
Expand All @@ -358,11 +359,11 @@ export interface ComposePaginateInterface {
* @param {string} request Request method (`octokit.request` or `@octokit/request`)
* @param {function} mapFn? Optional method to map each response to a custom array
*/
<R extends OctokitTypes.RequestInterface, M extends unknown[]>(
<R extends RequestInterface, M extends unknown[]>(
octokit: Octokit,
request: R,
mapFn: MapFunction<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>,
NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>,
M
>,
): Promise<M>;
Expand All @@ -375,12 +376,12 @@ export interface ComposePaginateInterface {
* @param {object} parameters URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
* @param {function} mapFn? Optional method to map each response to a custom array
*/
<R extends OctokitTypes.RequestInterface, M extends unknown[]>(
<R extends RequestInterface, M extends unknown[]>(
octokit: Octokit,
request: R,
parameters: Parameters<R>[0],
mapFn: MapFunction<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>,
NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>,
M
>,
): Promise<M>;
Expand All @@ -392,13 +393,11 @@ export interface ComposePaginateInterface {
* @param {string} request Request method (`octokit.request` or `@octokit/request`)
* @param {object} parameters? URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<R extends OctokitTypes.RequestInterface>(
<R extends RequestInterface>(
octokit: Octokit,
request: R,
parameters?: Parameters<R>[0],
): Promise<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>["data"]
>;
): Promise<NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>["data"]>;

iterator: {
// Using object as first parameter
Expand All @@ -413,10 +412,8 @@ export interface ComposePaginateInterface {
*/
<T>(
octokit: Octokit,
options: OctokitTypes.EndpointOptions,
): AsyncIterableIterator<
OctokitTypes.OctokitResponse<PaginationResults<T>>
>;
options: EndpointOptions,
): AsyncIterableIterator<OctokitResponse<PaginationResults<T>>>;

// Using route string as first parameter

Expand All @@ -434,7 +431,7 @@ export interface ComposePaginateInterface {
route: R,
parameters?: PaginatingEndpoints[R]["parameters"],
): AsyncIterableIterator<
OctokitTypes.OctokitResponse<DataType<PaginatingEndpoints[R]["response"]>>
OctokitResponse<DataType<PaginatingEndpoints[R]["response"]>>
>;

/**
Expand All @@ -446,15 +443,13 @@ export interface ComposePaginateInterface {
* @param {string} route Request method + URL. Example: `'GET /orgs/{org}'`
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<T, R extends OctokitTypes.Route = OctokitTypes.Route>(
<T, R extends Route = Route>(
octokit: Octokit,
route: R,
parameters?: R extends keyof PaginatingEndpoints
? PaginatingEndpoints[R]["parameters"]
: OctokitTypes.RequestParameters,
): AsyncIterableIterator<
OctokitTypes.OctokitResponse<PaginationResults<T>>
>;
: RequestParameters,
): AsyncIterableIterator<OctokitResponse<PaginationResults<T>>>;

// Using request method as first parameter

Expand All @@ -467,12 +462,12 @@ export interface ComposePaginateInterface {
* @param {string} request `@octokit/request` or `octokit.request` method
* @param {object} [parameters] URL, query or body parameters, as well as `headers`, `mediaType.format`, `request`, or `baseUrl`.
*/
<R extends OctokitTypes.RequestInterface>(
<R extends RequestInterface>(
octokit: Octokit,
request: R,
parameters?: Parameters<R>[0],
): AsyncIterableIterator<
NormalizeResponse<OctokitTypes.GetResponseTypeFromEndpointMethod<R>>
NormalizeResponse<GetResponseTypeFromEndpointMethod<R>>
>;
};
}
1 change: 1 addition & 0 deletions test/compose-paginate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { test, expect } from "vitest";
import fetchMock from "fetch-mock";
import { Octokit } from "@octokit/core";

Expand Down
1 change: 1 addition & 0 deletions test/issues.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, test, expect } from "vitest";
import fetchMock from "fetch-mock";
import { Octokit } from "@octokit/core";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
Expand Down
1 change: 1 addition & 0 deletions test/paginate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from "vitest";
import fetchMock from "fetch-mock";
import { Octokit } from "@octokit/core";
import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
Expand Down
1 change: 1 addition & 0 deletions test/paginating-endpoints.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect } from "vitest";
import { paginatingEndpoints, isPaginatingEndpoint } from "../src/index.ts";

describe("paginating endpoints", () => {
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 { Octokit } from "@octokit/core";

import {
Expand Down
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,
},
},
},
});

0 comments on commit 596988e

Please sign in to comment.