Skip to content

Commit

Permalink
build: switch to vitest (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscard0m authored Oct 3, 2024
1 parent 5f90159 commit 406ec25
Show file tree
Hide file tree
Showing 11 changed files with 1,864 additions and 5,313 deletions.
7,096 changes: 1,831 additions & 5,265 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 6 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*' 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:ui": "vitest --ui --coverage"
},
"repository": "https://github.com/octokit/plugin-create-or-update-text-file.js",
"keywords": [
Expand All @@ -27,45 +28,20 @@
"devDependencies": {
"@octokit/core": "^6.0.1",
"@octokit/tsconfig": "^3.0.0",
"@types/jest": "^29.5.2",
"@types/node": "^20.0.0",
"@vitest/coverage-v8": "^2.1.2",
"@vitest/ui": "^2.1.2",
"esbuild": "^0.24.0",
"fetch-mock": "npm:@gr2m/[email protected]",
"glob": "^11.0.0",
"jest": "^29.5.0",
"prettier": "3.3.3",
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"ts-jest": "^29.0.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"vitest": "^2.1.2"
},
"peerDependencies": {
"@octokit/core": ">=6"
},
"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"
}
},
"release": {
"branches": [
"+([0-9]).x",
Expand Down
2 changes: 1 addition & 1 deletion src/compose-create-or-update-text-file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Octokit } from "@octokit/core";
import type { Octokit } from "@octokit/core";

import { getFileContents } from "./get-file-content.js";
import type {
Expand Down
8 changes: 4 additions & 4 deletions src/get-file-content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RequestError } from "@octokit/request-error";
import { Octokit } from "@octokit/core";
import type { Octokit } from "@octokit/core";
import { base64ToUtf8 } from "./utils.js";

type Options = {
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function getFileContents(
const { data } = await octokit
.request(route, getContentsParameters)
.catch((error: RequestError) => {
/* istanbul ignore if */
/* v8 ignore next */
if (error.status !== 404) throw error;

return {
Expand Down Expand Up @@ -98,11 +98,10 @@ export async function getFileContents(
content: base64ToUtf8(data.content),
sha: data.sha,
};
/* v8 ignore start */
} catch (error: any) {
/* istanbul ignore next */
if (error.message !== "URI malformed") throw error;

/* istanbul ignore next error is only thrown in browsers, not node. */
throw new RequestError(
`[@octokit/plugin-create-or-update-text-file] ${requestOptions.url} is a binary file, only text files are supported`,
403,
Expand All @@ -111,4 +110,5 @@ export async function getFileContents(
},
);
}
/* v8 ignore stop */
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Octokit } from "@octokit/core";
import type { Octokit } from "@octokit/core";

import { composeCreateOrUpdateTextFile } from "./compose-create-or-update-text-file.js";
import { VERSION } from "./version.js";
Expand Down
5 changes: 3 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* istanbul ignore file */

/* v8 ignore start */
// universal implementation of nodeUtf8ToBase64/nodeBase64ToUtf8 methods for browsers, Node, and Deno.
//
// - good docs on base64
Expand Down Expand Up @@ -55,3 +54,5 @@ function browserBase64ToUtf8(data: string) {

export const utf8ToBase64 = isNode ? nodeUtf8ToBase64 : browserUtf8ToBase64;
export const base64ToUtf8 = isNode ? nodeBase64ToUtf8 : browserBase64ToUtf8;

/* v8 ignore stop */
1 change: 1 addition & 0 deletions test/create-or-update-text-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Octokit } from "@octokit/core";

import { createOrUpdateTextFile } from "../src";
import { utf8ToBase64 } from "../src/utils";
import { describe, it, expect } from "vitest";

const MyOctokit = Octokit.plugin(createOrUpdateTextFile).defaults({
userAgent: "test",
Expand Down
2 changes: 2 additions & 0 deletions test/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Octokit } from "@octokit/core";

import { createOrUpdateTextFile } from "../src";

import { describe, test, expect } from "vitest";

const MyOctokit = Octokit.plugin(createOrUpdateTextFile).defaults({
userAgent: "test",
});
Expand Down
1 change: 1 addition & 0 deletions test/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createOrUpdateTextFile, composeCreateOrUpdateTextFile } from "../src";
import { describe, it, expect } from "vitest";

describe("createOrUpdateTextFile", () => {
it("is a function", () => {
Expand Down
10 changes: 0 additions & 10 deletions test/tsconfig.test.json

This file was deleted.

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

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

0 comments on commit 406ec25

Please sign in to comment.