Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __generated__/gql/gql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions __generated__/gql/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

187 changes: 181 additions & 6 deletions __tests__/common/github/comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import {
addComment,
MutationAddComment,
MutationUpdateComment,
QueryPullRequestComments,
QueryPullRequestNodeId,
QueryPullRequestNodeIdByBranch
} from '@/common/github/comment.js'
Expand All @@ -27,7 +29,7 @@
})

afterEach(async () => {
mockApi.mockAgent.assertNoPendingInterceptors()

Check failure on line 32 in __tests__/common/github/comment.test.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/common/github/comment.test.ts > addComment > hide-wrangler-output > should hide wrangler output when hideWranglerOutput is true

UndiciError: 1 interceptor is pending: ┌─────────┬────────┬──────────────────────────┬────────────┬─────────────┬────────────┬─────────────┬───────────┐ │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │ ├─────────┼────────┼──────────────────────────┼────────────┼─────────────┼────────────┼─────────────┼───────────┤ │ 0 │ 'POST' │ 'https://api.github.com' │ '/graphql' │ 200 │ '❌' │ 0 │ 1 │ └─────────┴────────┴──────────────────────────┴────────────┴─────────────┴────────────┴─────────────┴───────────┘ ❯ MockAgent.assertNoPendingInterceptors node_modules/.pnpm/undici@7.24.4/node_modules/undici/lib/mock/mock-agent.js:224:11 ❯ __tests__/common/github/comment.test.ts:32:23 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'UND_ERR' }

Check failure on line 32 in __tests__/common/github/comment.test.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/common/github/comment.test.ts > addComment > comment-mode: update > should create new comment when no existing comment found in update mode

UndiciError: 2 interceptors are pending: ┌─────────┬────────┬──────────────────────────┬────────────┬─────────────┬────────────┬─────────────┬───────────┐ │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │ ├─────────┼────────┼──────────────────────────┼────────────┼─────────────┼────────────┼─────────────┼───────────┤ │ 0 │ 'POST' │ 'https://api.github.com' │ '/graphql' │ 200 │ '❌' │ 0 │ 1 │ │ 1 │ 'POST' │ 'https://api.github.com' │ '/graphql' │ 200 │ '❌' │ 0 │ 1 │ └─────────┴────────┴──────────────────────────┴────────────┴─────────────┴────────────┴─────────────┴───────────┘ ❯ MockAgent.assertNoPendingInterceptors node_modules/.pnpm/undici@7.24.4/node_modules/undici/lib/mock/mock-agent.js:224:11 ❯ __tests__/common/github/comment.test.ts:32:23 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'UND_ERR' }

Check failure on line 32 in __tests__/common/github/comment.test.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/common/github/comment.test.ts > addComment > comment-mode: update > should update existing comment when comment-mode is update

UndiciError: 2 interceptors are pending: ┌─────────┬────────┬──────────────────────────┬────────────┬─────────────┬────────────┬─────────────┬───────────┐ │ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │ ├─────────┼────────┼──────────────────────────┼────────────┼─────────────┼────────────┼─────────────┼───────────┤ │ 0 │ 'POST' │ 'https://api.github.com' │ '/graphql' │ 200 │ '❌' │ 0 │ 1 │ │ 1 │ 'POST' │ 'https://api.github.com' │ '/graphql' │ 200 │ '❌' │ 0 │ 1 │ └─────────┴────────┴──────────────────────────┴────────────┴─────────────┴────────────┴─────────────┴───────────┘ ❯ MockAgent.assertNoPendingInterceptors node_modules/.pnpm/undici@7.24.4/node_modules/undici/lib/mock/mock-agent.js:224:11 ❯ __tests__/common/github/comment.test.ts:32:23 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'UND_ERR' }
await mockApi.mockAgent.close()
})

Expand All @@ -40,7 +42,7 @@
query: MutationAddComment,
variables: {
subjectId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
body: '## Cloudflare Pages Deployment\n**Event Name:** pull_request\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
body: '<!-- cloudflare-pages-deployment-comment -->\n## Cloudflare Pages Deployment\n**Event Name:** pull_request\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
}
},
{
Expand Down Expand Up @@ -133,7 +135,7 @@
query: MutationAddComment,
variables: {
subjectId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
body: '## Cloudflare Pages Deployment\n**Event Name:** workflow_run\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** 3484a3fb816e0859fd6e1cea078d76385ff50625\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
body: '<!-- cloudflare-pages-deployment-comment -->\n## Cloudflare Pages Deployment\n**Event Name:** workflow_run\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** 3484a3fb816e0859fd6e1cea078d76385ff50625\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
}
},
{
Expand Down Expand Up @@ -217,7 +219,9 @@
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: '123',
wranglerVersion: 'mock-wrangler-version'
wranglerVersion: 'mock-wrangler-version',
commentMode: 'new',
hideWranglerOutput: false
})

vi.spyOn(Context, 'useContextEvent').mockReturnValue({
Expand Down Expand Up @@ -266,7 +270,7 @@
query: MutationAddComment,
variables: {
subjectId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
body: '## Cloudflare Pages Deployment\n**Event Name:** workflow_dispatch\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
body: '<!-- cloudflare-pages-deployment-comment -->\n## Cloudflare Pages Deployment\n**Event Name:** workflow_dispatch\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
}
},
{
Expand Down Expand Up @@ -295,7 +299,9 @@
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: 'abc',
wranglerVersion: 'mock-wrangler-version'
wranglerVersion: 'mock-wrangler-version',
commentMode: 'new',
hideWranglerOutput: false
})

await expect(addComment(mockData, 'success')).rejects.toThrow(
Expand Down Expand Up @@ -354,7 +360,7 @@
query: MutationAddComment,
variables: {
subjectId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
body: '## Cloudflare Pages Deployment\n**Event Name:** workflow_dispatch\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
body: '<!-- cloudflare-pages-deployment-comment -->\n## Cloudflare Pages Deployment\n**Event Name:** workflow_dispatch\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
}
},
{
Expand Down Expand Up @@ -448,4 +454,173 @@
}
)
})

describe('comment-mode: update', () => {
test('should update existing comment when comment-mode is update', async () => {
expect.assertions(1)

vi.spyOn(CommonInputs, 'useCommonInputs').mockReturnValue({
cloudflareApiToken: 'mock-cloudflare-api-token',
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: undefined,
wranglerVersion: 'mock-wrangler-version',
commentMode: 'update',
hideWranglerOutput: false
})

// Mock finding existing comment
mockApi.interceptGithub(
{
query: QueryPullRequestComments,
variables: {
prNodeId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
first: 50
}
},
{
data: {
node: {
comments: {
nodes: [
{
id: 'existing-comment-id',
body: '<!-- cloudflare-pages-deployment-comment -->\n## Old deployment',
author: {
login: 'github-actions[bot]'
}
}
]
}
}
}
}
)

// Mock updating the comment
mockApi.interceptGithub(
{
query: MutationUpdateComment,
variables: {
id: 'existing-comment-id',
body: '<!-- cloudflare-pages-deployment-comment -->\n## Cloudflare Pages Deployment\n**Event Name:** pull_request\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
}
},
{
data: {
updateIssueComment: {
issueComment: {
id: 'existing-comment-id'
}
}
}
}
)

const comment = await addComment(mockData, 'success')

expect(comment).toBe('existing-comment-id')

Check failure on line 522 in __tests__/common/github/comment.test.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/common/github/comment.test.ts > addComment > comment-mode: update > should update existing comment when comment-mode is update

AssertionError: expected undefined to be 'existing-comment-id' // Object.is equality - Expected: "existing-comment-id" + Received: undefined ❯ __tests__/common/github/comment.test.ts:522:23
})

test('should create new comment when no existing comment found in update mode', async () => {
expect.assertions(1)

vi.spyOn(CommonInputs, 'useCommonInputs').mockReturnValue({
cloudflareApiToken: 'mock-cloudflare-api-token',
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: undefined,
wranglerVersion: 'mock-wrangler-version',
commentMode: 'update',
hideWranglerOutput: false
})

// Mock finding no existing comments
mockApi.interceptGithub(
{
query: QueryPullRequestComments,
variables: {
prNodeId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
first: 50
}
},
{
data: {
node: {
comments: {
nodes: []
}
}
}
}
)

// Mock creating new comment
mockApi.interceptGithub(
{
query: MutationAddComment,
variables: {
subjectId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
body: '<!-- cloudflare-pages-deployment-comment -->\n## Cloudflare Pages Deployment\n**Event Name:** pull_request\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev\n\n### Wrangler Output\nsuccess'
}
},
{
data: {
addComment: {
commentEdge: {
node: {
id: 'new-comment-id'
}
}
}
}
}
)

const comment = await addComment(mockData, 'success')

expect(comment).toBe('new-comment-id')

Check failure on line 582 in __tests__/common/github/comment.test.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/common/github/comment.test.ts > addComment > comment-mode: update > should create new comment when no existing comment found in update mode

AssertionError: expected undefined to be 'new-comment-id' // Object.is equality - Expected: "new-comment-id" + Received: undefined ❯ __tests__/common/github/comment.test.ts:582:23
})
})

describe('hide-wrangler-output', () => {
test('should hide wrangler output when hideWranglerOutput is true', async () => {
expect.assertions(1)

vi.spyOn(CommonInputs, 'useCommonInputs').mockReturnValue({
cloudflareApiToken: 'mock-cloudflare-api-token',
gitHubApiToken: 'mock-github-token',
gitHubEnvironment: undefined,
prNumber: undefined,
wranglerVersion: 'mock-wrangler-version',
commentMode: 'new',
hideWranglerOutput: true
})

mockApi.interceptGithub(
{
query: MutationAddComment,
variables: {
subjectId: 'MDExOlB1bGxSZXF1ZXN0Mjc5MTQ3NDM3',
body: '<!-- cloudflare-pages-deployment-comment -->\n## Cloudflare Pages Deployment\n**Event Name:** pull_request\n**Environment:** production\n**Project:** cloudflare-pages-action\n**Built with commit:** mock-github-sha\n**Preview URL:** https://206e215c.cloudflare-pages-action-a5z.pages.dev\n**Branch Preview URL:** https://unknown-branch.cloudflare-pages-action-a5z.pages.dev'
}
},
{
data: {
addComment: {
commentEdge: {
node: {
id: '1'
}
}
}
}
}
)

const comment = await addComment(mockData, 'success')

expect(comment).toBe('1')

Check failure on line 623 in __tests__/common/github/comment.test.ts

View workflow job for this annotation

GitHub Actions / test

__tests__/common/github/comment.test.ts > addComment > hide-wrangler-output > should hide wrangler output when hideWranglerOutput is true

AssertionError: expected undefined to be '1' // Object.is equality - Expected: "1" + Received: undefined ❯ __tests__/common/github/comment.test.ts:623:23
})
})
})
Loading
Loading