Skip to content

Commit 33c7a0b

Browse files
committed
bug: Mock PR body in test
* Mock body to get consistent testing * Fix lint warnings
1 parent 99c27ad commit 33c7a0b

4 files changed

Lines changed: 26 additions & 15 deletions

File tree

dist/index.js

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

src/dry-run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable no-console, @typescript-eslint/no-var-requires, no-unused-expressions */
1+
22
import * as github from '@actions/github'
33
import { Context } from '@actions/github/lib/context'
44
import * as dotenv from 'dotenv'

src/main.test.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ beforeEach(() => {
1111
jest.spyOn(core, 'setFailed').mockImplementation(jest.fn())
1212
jest.spyOn(core, 'startGroup').mockImplementation(jest.fn())
1313
jest.spyOn(core, 'getBooleanInput').mockReturnValue(false)
14+
jest.spyOn(util, 'getBody').mockReturnValue(`
15+
Bumps [fake/package](https://github.com/) from 0.0.0 to 0.0.1.
16+
<details>
17+
<summary>Release notes</summary>
18+
<blockquote>
19+
<h2>0.0.1</h2>
20+
<h2>Summary</h2>
21+
<p>This is a fake description for a fake update</p>
22+
<h2>What's Changed</h2>
23+
* Nothing
24+
</blockquote>
25+
</details>
26+
`)
1427
})
1528

1629
test('it early exits with an error if github-token is not set', async () => {
@@ -22,10 +35,10 @@ test('it early exits with an error if github-token is not set', async () => {
2235
expect(core.setFailed).toHaveBeenCalledWith(
2336
expect.stringContaining('github-token is not set!')
2437
)
25-
/* eslint-disable no-unused-expressions */
38+
2639
expect(dependabotCommits.getMessage).not.toHaveBeenCalled
2740
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
28-
/* eslint-enable no-unused-expressions */
41+
2942
})
3043

3144
test('it does nothing if the PR is not verified as from Dependabot', async () => {
@@ -40,9 +53,9 @@ test('it does nothing if the PR is not verified as from Dependabot', async () =>
4053
expect(core.setFailed).toHaveBeenCalledWith(
4154
expect.stringContaining('PR is not from Dependabot, nothing to do.')
4255
)
43-
/* eslint-disable no-unused-expressions */
56+
4457
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
45-
/* eslint-enable no-unused-expressions */
58+
4659
})
4760

4861
test('it does nothing if there is no metadata in the commit', async () => {
@@ -57,9 +70,9 @@ test('it does nothing if there is no metadata in the commit', async () => {
5770
expect(core.setFailed).toHaveBeenCalledWith(
5871
expect.stringContaining('PR does not contain metadata, nothing to do.')
5972
)
60-
/* eslint-disable no-unused-expressions */
73+
6174
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
62-
/* eslint-enable no-unused-expressions */
75+
6376
})
6477

6578
test('it sets the updated dependency as an output for subsequent actions when given a commit message for application', async () => {
@@ -499,9 +512,9 @@ test('it sets the action to failed if there is an unexpected exception', async (
499512
expect(core.setFailed).toHaveBeenCalledWith(
500513
expect.stringContaining('Something bad happened!')
501514
)
502-
/* eslint-disable no-unused-expressions */
515+
503516
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
504-
/* eslint-enable no-unused-expressions */
517+
505518
})
506519

507520
test('it sets the action to failed if there is a request error', async () => {
@@ -525,7 +538,7 @@ test('it sets the action to failed if there is a request error', async () => {
525538
expect(core.setFailed).toHaveBeenCalledWith(
526539
expect.stringContaining('(500) Something bad happened!')
527540
)
528-
/* eslint-disable no-unused-expressions */
541+
529542
expect(dependabotCommits.getAlert).not.toHaveBeenCalled
530-
/* eslint-enable no-unused-expressions */
543+
531544
})

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export async function run (): Promise<void> {
1010
const token = core.getInput('github-token')
1111

1212
if (!token) {
13-
/* eslint-disable no-template-curly-in-string */
13+
1414
core.setFailed(
1515
'github-token is not set! Please add \'github-token: "${{ secrets.GITHUB_TOKEN }}"\' to your workflow file.'
1616
)
17-
/* eslint-enable no-template-curly-in-string */
17+
1818
return
1919
}
2020

0 commit comments

Comments
 (0)