Skip to content

Commit 406ec25

Browse files
authored
build: switch to vitest (#293)
1 parent 5f90159 commit 406ec25

11 files changed

+1864
-5313
lines changed

package-lock.json

Lines changed: 1831 additions & 5265 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
1313
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
1414
"pretest": "npm run -s lint",
15-
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage"
15+
"test": "vitest run --coverage",
16+
"test:ui": "vitest --ui --coverage"
1617
},
1718
"repository": "https://github.com/octokit/plugin-create-or-update-text-file.js",
1819
"keywords": [
@@ -27,45 +28,20 @@
2728
"devDependencies": {
2829
"@octokit/core": "^6.0.1",
2930
"@octokit/tsconfig": "^3.0.0",
30-
"@types/jest": "^29.5.2",
3131
"@types/node": "^20.0.0",
32+
"@vitest/coverage-v8": "^2.1.2",
33+
"@vitest/ui": "^2.1.2",
3234
"esbuild": "^0.24.0",
3335
"fetch-mock": "npm:@gr2m/[email protected]",
3436
"glob": "^11.0.0",
35-
"jest": "^29.5.0",
3637
"prettier": "3.3.3",
3738
"semantic-release-plugin-update-version-in-files": "^1.1.0",
38-
"ts-jest": "^29.0.0",
39-
"typescript": "^5.0.0"
39+
"typescript": "^5.0.0",
40+
"vitest": "^2.1.2"
4041
},
4142
"peerDependencies": {
4243
"@octokit/core": ">=6"
4344
},
44-
"jest": {
45-
"extensionsToTreatAsEsm": [
46-
".ts"
47-
],
48-
"transform": {
49-
"^.+\\.(ts|tsx)$": [
50-
"ts-jest",
51-
{
52-
"tsconfig": "test/tsconfig.test.json",
53-
"useESM": true
54-
}
55-
]
56-
},
57-
"coverageThreshold": {
58-
"global": {
59-
"statements": 100,
60-
"branches": 100,
61-
"functions": 100,
62-
"lines": 100
63-
}
64-
},
65-
"moduleNameMapper": {
66-
"^(.+)\\.jsx?$": "$1"
67-
}
68-
},
6945
"release": {
7046
"branches": [
7147
"+([0-9]).x",

src/compose-create-or-update-text-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Octokit } from "@octokit/core";
1+
import type { Octokit } from "@octokit/core";
22

33
import { getFileContents } from "./get-file-content.js";
44
import type {

src/get-file-content.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RequestError } from "@octokit/request-error";
2-
import { Octokit } from "@octokit/core";
2+
import type { Octokit } from "@octokit/core";
33
import { base64ToUtf8 } from "./utils.js";
44

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

6161
return {
@@ -98,11 +98,10 @@ export async function getFileContents(
9898
content: base64ToUtf8(data.content),
9999
sha: data.sha,
100100
};
101+
/* v8 ignore start */
101102
} catch (error: any) {
102-
/* istanbul ignore next */
103103
if (error.message !== "URI malformed") throw error;
104104

105-
/* istanbul ignore next error is only thrown in browsers, not node. */
106105
throw new RequestError(
107106
`[@octokit/plugin-create-or-update-text-file] ${requestOptions.url} is a binary file, only text files are supported`,
108107
403,
@@ -111,4 +110,5 @@ export async function getFileContents(
111110
},
112111
);
113112
}
113+
/* v8 ignore stop */
114114
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Octokit } from "@octokit/core";
1+
import type { Octokit } from "@octokit/core";
22

33
import { composeCreateOrUpdateTextFile } from "./compose-create-or-update-text-file.js";
44
import { VERSION } from "./version.js";

src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* istanbul ignore file */
2-
1+
/* v8 ignore start */
32
// universal implementation of nodeUtf8ToBase64/nodeBase64ToUtf8 methods for browsers, Node, and Deno.
43
//
54
// - good docs on base64
@@ -55,3 +54,5 @@ function browserBase64ToUtf8(data: string) {
5554

5655
export const utf8ToBase64 = isNode ? nodeUtf8ToBase64 : browserUtf8ToBase64;
5756
export const base64ToUtf8 = isNode ? nodeBase64ToUtf8 : browserBase64ToUtf8;
57+
58+
/* v8 ignore stop */

test/create-or-update-text-file.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Octokit } from "@octokit/core";
33

44
import { createOrUpdateTextFile } from "../src";
55
import { utf8ToBase64 } from "../src/utils";
6+
import { describe, it, expect } from "vitest";
67

78
const MyOctokit = Octokit.plugin(createOrUpdateTextFile).defaults({
89
userAgent: "test",

test/errors.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Octokit } from "@octokit/core";
33

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

6+
import { describe, test, expect } from "vitest";
7+
68
const MyOctokit = Octokit.plugin(createOrUpdateTextFile).defaults({
79
userAgent: "test",
810
});

test/smoke.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createOrUpdateTextFile, composeCreateOrUpdateTextFile } from "../src";
2+
import { describe, it, expect } from "vitest";
23

34
describe("createOrUpdateTextFile", () => {
45
it("is a function", () => {

test/tsconfig.test.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)