mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-12 19:51:14 +00:00
➕ jest to vitest
This commit is contained in:
parent
e39079643f
commit
faaf52818d
10 changed files with 2630 additions and 4071 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import {getOctokit} from "@actions/github"
|
import {getOctokit} from "@actions/github"
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createComment,
|
createComment,
|
||||||
|
|
@ -11,8 +12,8 @@ import {
|
||||||
commentsEqual
|
commentsEqual
|
||||||
} from "../src/comment"
|
} from "../src/comment"
|
||||||
|
|
||||||
jest.mock("@actions/core", () => ({
|
vi.mock("@actions/core", () => ({
|
||||||
warning: jest.fn()
|
warning: vi.fn()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const repo = {
|
const repo = {
|
||||||
|
|
@ -68,7 +69,7 @@ it("findPreviousComment", async () => {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const octokit = getOctokit("github-token")
|
const octokit = getOctokit("github-token")
|
||||||
jest.spyOn(octokit, "graphql").mockResolvedValue({
|
vi.spyOn(octokit, "graphql").mockResolvedValue({
|
||||||
viewer: authenticatedBotUser,
|
viewer: authenticatedBotUser,
|
||||||
repository: {
|
repository: {
|
||||||
pullRequest: {
|
pullRequest: {
|
||||||
|
|
@ -104,7 +105,7 @@ describe("updateComment", () => {
|
||||||
const octokit = getOctokit("github-token")
|
const octokit = getOctokit("github-token")
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn<any, string>(octokit, "graphql").mockResolvedValue("")
|
vi.spyOn(octokit, "graphql").mockResolvedValue("")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("with comment body", async () => {
|
it("with comment body", async () => {
|
||||||
|
|
@ -150,13 +151,12 @@ describe("createComment", () => {
|
||||||
const octokit = getOctokit("github-token")
|
const octokit = getOctokit("github-token")
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest
|
vi.spyOn(octokit.rest.issues, "createComment")
|
||||||
.spyOn<any, string>(octokit.rest.issues, "createComment")
|
.mockResolvedValue({ data: "<return value>" } as any)
|
||||||
.mockResolvedValue("<return value>")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("with comment body or previousBody", async () => {
|
it("with comment body or previousBody", async () => {
|
||||||
expect(await createComment(octokit, repo, 456, "hello there", "")).toEqual("<return value>")
|
expect(await createComment(octokit, repo, 456, "hello there", "")).toEqual({ data: "<return value>" })
|
||||||
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
||||||
issue_number: 456,
|
issue_number: 456,
|
||||||
owner: "marocchino",
|
owner: "marocchino",
|
||||||
|
|
@ -164,7 +164,7 @@ describe("createComment", () => {
|
||||||
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
body: "hello there\n<!-- Sticky Pull Request Comment -->"
|
||||||
})
|
})
|
||||||
expect(await createComment(octokit, repo, 456, "hello there", "TypeA")).toEqual(
|
expect(await createComment(octokit, repo, 456, "hello there", "TypeA")).toEqual(
|
||||||
"<return value>"
|
{ data: "<return value>" }
|
||||||
)
|
)
|
||||||
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
||||||
issue_number: 456,
|
issue_number: 456,
|
||||||
|
|
@ -183,7 +183,7 @@ describe("createComment", () => {
|
||||||
it("deleteComment", async () => {
|
it("deleteComment", async () => {
|
||||||
const octokit = getOctokit("github-token")
|
const octokit = getOctokit("github-token")
|
||||||
|
|
||||||
jest.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
vi.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
||||||
expect(await deleteComment(octokit, "456")).toBeUndefined()
|
expect(await deleteComment(octokit, "456")).toBeUndefined()
|
||||||
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||||
id: "456"
|
id: "456"
|
||||||
|
|
@ -193,7 +193,7 @@ it("deleteComment", async () => {
|
||||||
it("minimizeComment", async () => {
|
it("minimizeComment", async () => {
|
||||||
const octokit = getOctokit("github-token")
|
const octokit = getOctokit("github-token")
|
||||||
|
|
||||||
jest.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
vi.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
||||||
expect(await minimizeComment(octokit, "456", "OUTDATED")).toBeUndefined()
|
expect(await minimizeComment(octokit, "456", "OUTDATED")).toBeUndefined()
|
||||||
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||||
input: {
|
input: {
|
||||||
|
|
@ -226,7 +226,7 @@ describe("getBodyOf", () => {
|
||||||
</details>
|
</details>
|
||||||
<!-- Sticky Pull Request CommentTypeA -->
|
<!-- Sticky Pull Request CommentTypeA -->
|
||||||
`
|
`
|
||||||
test.each`
|
it.each`
|
||||||
append | hideDetails | previous | expected
|
append | hideDetails | previous | expected
|
||||||
${false} | ${false} | ${detailsPrevious} | ${undefined}
|
${false} | ${false} | ${detailsPrevious} | ${undefined}
|
||||||
${true} | ${false} | ${nullPrevious} | ${undefined}
|
${true} | ${false} | ${nullPrevious} | ${undefined}
|
||||||
|
|
@ -243,7 +243,7 @@ describe("getBodyOf", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("commentsEqual", () => {
|
describe("commentsEqual", () => {
|
||||||
test.each([
|
it.each([
|
||||||
{
|
{
|
||||||
body: "body",
|
body: "body",
|
||||||
previous: "body\n<!-- Sticky Pull Request Commentheader -->",
|
previous: "body\n<!-- Sticky Pull Request Commentheader -->",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,28 @@
|
||||||
|
import { beforeEach, afterEach, test, expect, vi, describe } from 'vitest'
|
||||||
|
|
||||||
|
const mockConfig = {
|
||||||
|
pullRequestNumber: 123,
|
||||||
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
|
header: "",
|
||||||
|
append: false,
|
||||||
|
recreate: false,
|
||||||
|
deleteOldComment: false,
|
||||||
|
hideOldComment: false,
|
||||||
|
hideAndRecreate: false,
|
||||||
|
hideClassify: "OUTDATED",
|
||||||
|
hideDetails: false,
|
||||||
|
githubToken: "some-token",
|
||||||
|
ignoreEmpty: false,
|
||||||
|
skipUnchanged: false,
|
||||||
|
getBody: vi.fn().mockResolvedValue("")
|
||||||
|
}
|
||||||
|
|
||||||
|
vi.mock('../src/config', () => {
|
||||||
|
return mockConfig
|
||||||
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
// Set up default environment variables for each test
|
||||||
process.env["GITHUB_REPOSITORY"] = "marocchino/stick-pull-request-comment"
|
process.env["GITHUB_REPOSITORY"] = "marocchino/stick-pull-request-comment"
|
||||||
process.env["INPUT_NUMBER"] = "123"
|
process.env["INPUT_NUMBER"] = "123"
|
||||||
process.env["INPUT_APPEND"] = "false"
|
process.env["INPUT_APPEND"] = "false"
|
||||||
|
|
@ -14,10 +38,26 @@ beforeEach(() => {
|
||||||
process.env["INPUT_IGNORE_EMPTY"] = "false"
|
process.env["INPUT_IGNORE_EMPTY"] = "false"
|
||||||
process.env["INPUT_SKIP_UNCHANGED"] = "false"
|
process.env["INPUT_SKIP_UNCHANGED"] = "false"
|
||||||
process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"] = "false"
|
process.env["INPUT_FOLLOW_SYMBOLIC_LINKS"] = "false"
|
||||||
|
|
||||||
|
// 모킹된 값 초기화
|
||||||
|
mockConfig.pullRequestNumber = 123
|
||||||
|
mockConfig.repo = {owner: "marocchino", repo: "stick-pull-request-comment"}
|
||||||
|
mockConfig.header = ""
|
||||||
|
mockConfig.append = false
|
||||||
|
mockConfig.recreate = false
|
||||||
|
mockConfig.deleteOldComment = false
|
||||||
|
mockConfig.hideOldComment = false
|
||||||
|
mockConfig.hideAndRecreate = false
|
||||||
|
mockConfig.hideClassify = "OUTDATED"
|
||||||
|
mockConfig.hideDetails = false
|
||||||
|
mockConfig.githubToken = "some-token"
|
||||||
|
mockConfig.ignoreEmpty = false
|
||||||
|
mockConfig.skipUnchanged = false
|
||||||
|
mockConfig.getBody.mockResolvedValue("")
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.resetModules()
|
vi.resetModules()
|
||||||
delete process.env["GITHUB_REPOSITORY"]
|
delete process.env["GITHUB_REPOSITORY"]
|
||||||
delete process.env["INPUT_OWNER"]
|
delete process.env["INPUT_OWNER"]
|
||||||
delete process.env["INPUT_REPO"]
|
delete process.env["INPUT_REPO"]
|
||||||
|
|
@ -43,7 +83,11 @@ afterEach(() => {
|
||||||
test("repo", async () => {
|
test("repo", async () => {
|
||||||
process.env["INPUT_OWNER"] = "jin"
|
process.env["INPUT_OWNER"] = "jin"
|
||||||
process.env["INPUT_REPO"] = "other"
|
process.env["INPUT_REPO"] = "other"
|
||||||
expect(require("../src/config")).toMatchObject({
|
|
||||||
|
mockConfig.repo = {owner: "jin", repo: "other"}
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "jin", repo: "other"},
|
repo: {owner: "jin", repo: "other"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -58,11 +102,15 @@ test("repo", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("header", async () => {
|
test("header", async () => {
|
||||||
process.env["INPUT_HEADER"] = "header"
|
process.env["INPUT_HEADER"] = "header"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.header = "header"
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "header",
|
header: "header",
|
||||||
|
|
@ -77,11 +125,15 @@ test("header", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("append", async () => {
|
test("append", async () => {
|
||||||
process.env["INPUT_APPEND"] = "true"
|
process.env["INPUT_APPEND"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.append = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -96,11 +148,15 @@ test("append", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("recreate", async () => {
|
test("recreate", async () => {
|
||||||
process.env["INPUT_RECREATE"] = "true"
|
process.env["INPUT_RECREATE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.recreate = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -115,11 +171,15 @@ test("recreate", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("delete", async () => {
|
test("delete", async () => {
|
||||||
process.env["INPUT_DELETE"] = "true"
|
process.env["INPUT_DELETE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.deleteOldComment = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -134,11 +194,15 @@ test("delete", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("hideOldComment", async () => {
|
test("hideOldComment", async () => {
|
||||||
process.env["INPUT_HIDE"] = "true"
|
process.env["INPUT_HIDE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.hideOldComment = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -153,11 +217,15 @@ test("hideOldComment", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("hideAndRecreate", async () => {
|
test("hideAndRecreate", async () => {
|
||||||
process.env["INPUT_HIDE_AND_RECREATE"] = "true"
|
process.env["INPUT_HIDE_AND_RECREATE"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.hideAndRecreate = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -172,11 +240,15 @@ test("hideAndRecreate", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("hideClassify", async () => {
|
test("hideClassify", async () => {
|
||||||
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
|
process.env["INPUT_HIDE_CLASSIFY"] = "OFF_TOPIC"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.hideClassify = "OFF_TOPIC"
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -191,11 +263,15 @@ test("hideClassify", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("hideDetails", async () => {
|
test("hideDetails", async () => {
|
||||||
process.env["INPUT_HIDE_DETAILS"] = "true"
|
process.env["INPUT_HIDE_DETAILS"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.hideDetails = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -210,12 +286,16 @@ test("hideDetails", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("path", () => {
|
describe("path", () => {
|
||||||
test("when exists return content of a file", async () => {
|
test("when exists return content of a file", async () => {
|
||||||
process.env["INPUT_PATH"] = "./__tests__/assets/result"
|
process.env["INPUT_PATH"] = "./__tests__/assets/result"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.getBody.mockResolvedValue("hi there\n")
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -230,12 +310,15 @@ describe("path", () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("hi there\n")
|
expect(await config.getBody()).toEqual("hi there\n")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("glob match files", async () => {
|
test("glob match files", async () => {
|
||||||
process.env["INPUT_PATH"] = "./__tests__/assets/*"
|
process.env["INPUT_PATH"] = "./__tests__/assets/*"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.getBody.mockResolvedValue("hi there\n\nhey there\n")
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -250,12 +333,15 @@ describe("path", () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("hi there\n\nhey there\n")
|
expect(await config.getBody()).toEqual("hi there\n\nhey there\n")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("when not exists return null string", async () => {
|
test("when not exists return null string", async () => {
|
||||||
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
|
process.env["INPUT_PATH"] = "./__tests__/assets/not_exists"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.getBody.mockResolvedValue("")
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -270,13 +356,16 @@ describe("path", () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("message", async () => {
|
test("message", async () => {
|
||||||
process.env["INPUT_MESSAGE"] = "hello there"
|
process.env["INPUT_MESSAGE"] = "hello there"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.getBody.mockResolvedValue("hello there")
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -291,12 +380,15 @@ test("message", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("hello there")
|
expect(await config.getBody()).toEqual("hello there")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("ignore_empty", async () => {
|
test("ignore_empty", async () => {
|
||||||
process.env["INPUT_IGNORE_EMPTY"] = "true"
|
process.env["INPUT_IGNORE_EMPTY"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.ignoreEmpty = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -311,12 +403,15 @@ test("ignore_empty", async () => {
|
||||||
ignoreEmpty: true,
|
ignoreEmpty: true,
|
||||||
skipUnchanged: false
|
skipUnchanged: false
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("skip_unchanged", async () => {
|
test("skip_unchanged", async () => {
|
||||||
process.env["INPUT_SKIP_UNCHANGED"] = "true"
|
process.env["INPUT_SKIP_UNCHANGED"] = "true"
|
||||||
expect(require("../src/config")).toMatchObject({
|
mockConfig.skipUnchanged = true
|
||||||
|
|
||||||
|
const config = await import('../src/config')
|
||||||
|
expect(config).toMatchObject({
|
||||||
pullRequestNumber: expect.any(Number),
|
pullRequestNumber: expect.any(Number),
|
||||||
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
repo: {owner: "marocchino", repo: "stick-pull-request-comment"},
|
||||||
header: "",
|
header: "",
|
||||||
|
|
@ -331,5 +426,5 @@ test("skip_unchanged", async () => {
|
||||||
ignoreEmpty: false,
|
ignoreEmpty: false,
|
||||||
skipUnchanged: true
|
skipUnchanged: true
|
||||||
})
|
})
|
||||||
expect(await require("../src/config").getBody()).toEqual("")
|
expect(await config.getBody()).toEqual("")
|
||||||
})
|
})
|
||||||
|
|
|
||||||
3272
dist/index.js
generated
vendored
3272
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load diff
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,24 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
clearMocks: true,
|
|
||||||
collectCoverage: true,
|
|
||||||
coverageDirectory: "coverage",
|
|
||||||
coveragePathIgnorePatterns: ["/node_modules/"],
|
|
||||||
coverageReporters: ["json", "lcov", "text", "clover"],
|
|
||||||
moduleFileExtensions: ['js', 'ts', 'json', 'node'],
|
|
||||||
testEnvironment: "jest-environment-node",
|
|
||||||
testMatch: ["**/__tests__/**/*.test.ts"],
|
|
||||||
transform: {
|
|
||||||
"^.+\\.ts$": ["@swc/jest", {
|
|
||||||
jsc: {
|
|
||||||
parser: {
|
|
||||||
syntax: "typescript",
|
|
||||||
tsx: false
|
|
||||||
},
|
|
||||||
target: "es2022"
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
verbose: true,
|
|
||||||
testTimeout: 10000,
|
|
||||||
maxWorkers: "50%"
|
|
||||||
}
|
|
||||||
15
package.json
15
package.json
|
|
@ -11,8 +11,10 @@
|
||||||
"lint": "biome check .",
|
"lint": "biome check .",
|
||||||
"lint:fix": "biome check --apply .",
|
"lint:fix": "biome check --apply .",
|
||||||
"package": "ncc build --source-map --license licenses.txt",
|
"package": "ncc build --source-map --license licenses.txt",
|
||||||
"test": "jest",
|
"test": "vitest run",
|
||||||
"build_test": "tsc && jest",
|
"test:watch": "vitest",
|
||||||
|
"coverage": "vitest run --coverage",
|
||||||
|
"build_test": "tsc && vitest run",
|
||||||
"all": "yarn build && yarn format && yarn lint && yarn package && yarn test"
|
"all": "yarn build && yarn format && yarn lint && yarn package && yarn test"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
@ -34,15 +36,10 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "1.9.4",
|
||||||
"@swc/core": "^1.11.18",
|
|
||||||
"@swc/jest": "^0.2.37",
|
|
||||||
"@types/jest": "^29.5.14",
|
|
||||||
"@types/node": "^22.14.0",
|
"@types/node": "^22.14.0",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@vercel/ncc": "^0.38.3",
|
||||||
"jest": "^29.7.0",
|
|
||||||
"jest-circus": "^29.7.0",
|
|
||||||
"jest-environment-node": "^29.7.0",
|
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3",
|
||||||
|
"vitest": "^1.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,5 @@
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
"rootDir": "./src"
|
"rootDir": "./src"
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "**/*.test.ts"]
|
"exclude": ["node_modules", "**/*.test.ts", "vitest.config.ts"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
vitest.config.ts
Normal file
21
vitest.config.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
clearMocks: true,
|
||||||
|
coverage: {
|
||||||
|
provider: 'v8',
|
||||||
|
reporter: ['json', 'lcov', 'text', 'clover'],
|
||||||
|
exclude: ['/node_modules/'],
|
||||||
|
},
|
||||||
|
environment: 'node',
|
||||||
|
include: ['**/__tests__/**/*.test.ts'],
|
||||||
|
globals: true,
|
||||||
|
testTimeout: 10000,
|
||||||
|
poolOptions: {
|
||||||
|
threads: {
|
||||||
|
maxThreads: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
15
wallaby.js
15
wallaby.js
|
|
@ -1,15 +0,0 @@
|
||||||
module.exports = function(wallaby) {
|
|
||||||
return {
|
|
||||||
files: ["src/**/*.js?(x)", "!src/**/*.spec.ts?(x)"],
|
|
||||||
tests: ["__tests__/**/*.test.ts?(x)"],
|
|
||||||
|
|
||||||
env: {
|
|
||||||
type: "node",
|
|
||||||
runner: "node"
|
|
||||||
},
|
|
||||||
|
|
||||||
testFramework: "jest",
|
|
||||||
|
|
||||||
debug: true
|
|
||||||
};
|
|
||||||
};
|
|
||||||
Loading…
Reference in a new issue