Skip to content

Commit

Permalink
chore: use vitest (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Jul 16, 2024
1 parent 462e351 commit 5a681c3
Show file tree
Hide file tree
Showing 25 changed files with 2,994 additions and 4,989 deletions.
7,898 changes: 2,949 additions & 4,949 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 4 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,58 +45,28 @@
"@octokit/fixtures-server": "^8.1.0",
"@octokit/request": "^9.1.1",
"@octokit/tsconfig": "^3.0.0",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.5",
"@vitest/coverage-v8": "^2.0.3",
"esbuild": "^0.23.0",
"fetch-mock": "^10.0.0",
"glob": "^11.0.0",
"jest": "^29.7.0",
"nock": "^13.5.0",
"prettier": "^3.2.4",
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3",
"undici": "^6.4.0"
"undici": "^6.4.0",
"vitest": "^2.0.3"
},
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"coverage": "nyc report --reporter=html && open coverage/index.html",
"lint": "prettier --check \"{src,test}/**/*.{js,json,ts}\" \"docs/*.js\" docs/package.json \"docs/src/**/*\" *.md package.json",
"lint:fix": "prettier --write \"{src,test}/**/*.{js,json,ts}\" \"docs/*.js\" docs/package.json \"docs/src/**/*\" *.md package.json",
"start-fixtures-server": "octokit-fixtures-server",
"pretest": "npm run -s lint",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"test": "vitest run --coverage",
"test:typescript": "npx tsc --noEmit --declaration --allowImportingTsExtensions --moduleResolution node16 --module node16 --noUnusedLocals test/typescript-validate.ts"
},
"license": "MIT",
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
"testPathIgnorePatterns": [
"/docs/"
],
"coverageThreshold": {
"global": {
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
"branches": [
"+([0-9]).x",
Expand Down
10 changes: 5 additions & 5 deletions test/integration/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from "vitest";
import fetchMock from "fetch-mock";
import { jest } from "@jest/globals";

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

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

const consoleStub = {
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
debug: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
error: vi.fn(),
};

const octokit = new Octokit({
Expand Down
1 change: 1 addition & 0 deletions test/issues/881-redirect-url.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 "../../src/index.ts";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { loadFixture, fixtureToInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/add-labels-to-issue.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/branch-protection.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/create-file.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/create-status.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
3 changes: 2 additions & 1 deletion test/scenarios/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand All @@ -23,7 +24,7 @@ describe("api.github.com", () => {
.catch((error) => {
expect(error.message).toMatch(
new RegExp(
`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`,
`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`,
),
);
expect(error.response.data.errors).toEqual([
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/get-archive.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe.skip("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/get-content.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe.skip("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/get-organization.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/get-repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/labels.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/lock-issue.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/mark-notifications-as-read.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/markdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
2 changes: 2 additions & 0 deletions test/scenarios/paginate-issues-async-await.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
// this file is not run directly but instead required in paginate-issues-test.js
// for Node v10 and higher only

Expand Down Expand Up @@ -28,6 +29,7 @@ describe("api.github.com", () => {
// @ts-ignore TODO: *.endpoint.merge on endpoint methods should always return .url property
octokit.rest.issues.listForRepo.endpoint.merge(options),
)) {
// @ts-ignore
results.push(...result.data);
}
expect(results.length).toEqual(13);
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/paginate-issues.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

type IteratorResult = {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/project-cards.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/release-assets.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/rename-repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/search-issues.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, beforeEach, it, expect } from "vitest";
import { getInstance, type OctokitType } from "../util.ts";

describe("api.github.com", () => {
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 5a681c3

Please sign in to comment.