From 33c7a0bfc8c64c28af2c81b3431ef4c59ec496b4 Mon Sep 17 00:00:00 2001 From: Thomas Ruggeri Date: Mon, 22 Dec 2025 20:31:50 +0000 Subject: [PATCH] bug: Mock PR body in test * Mock body to get consistent testing * Fix lint warnings --- dist/index.js | 2 -- src/dry-run.ts | 2 +- src/main.test.ts | 33 +++++++++++++++++++++++---------- src/main.ts | 4 ++-- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index ba5d534..9242b88 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10497,9 +10497,7 @@ const util = __importStar(__nccwpck_require__(9180)); async function run() { const token = core.getInput('github-token'); if (!token) { - /* eslint-disable no-template-curly-in-string */ core.setFailed('github-token is not set! Please add \'github-token: "${{ secrets.GITHUB_TOKEN }}"\' to your workflow file.'); - /* eslint-enable no-template-curly-in-string */ return; } try { diff --git a/src/dry-run.ts b/src/dry-run.ts index d36fd71..1ff65d9 100755 --- a/src/dry-run.ts +++ b/src/dry-run.ts @@ -1,4 +1,4 @@ -/* eslint-disable no-console, @typescript-eslint/no-var-requires, no-unused-expressions */ + import * as github from '@actions/github' import { Context } from '@actions/github/lib/context' import * as dotenv from 'dotenv' diff --git a/src/main.test.ts b/src/main.test.ts index 7fddb0c..01bf721 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -11,6 +11,19 @@ beforeEach(() => { jest.spyOn(core, 'setFailed').mockImplementation(jest.fn()) jest.spyOn(core, 'startGroup').mockImplementation(jest.fn()) jest.spyOn(core, 'getBooleanInput').mockReturnValue(false) + jest.spyOn(util, 'getBody').mockReturnValue(` +Bumps [fake/package](https://github.com/) from 0.0.0 to 0.0.1. +
+Release notes +
+

0.0.1

+

Summary

+

This is a fake description for a fake update

+

What's Changed

+* Nothing +
+
+`) }) 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 () => { expect(core.setFailed).toHaveBeenCalledWith( expect.stringContaining('github-token is not set!') ) - /* eslint-disable no-unused-expressions */ + expect(dependabotCommits.getMessage).not.toHaveBeenCalled expect(dependabotCommits.getAlert).not.toHaveBeenCalled - /* eslint-enable no-unused-expressions */ + }) 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 () => expect(core.setFailed).toHaveBeenCalledWith( expect.stringContaining('PR is not from Dependabot, nothing to do.') ) - /* eslint-disable no-unused-expressions */ + expect(dependabotCommits.getAlert).not.toHaveBeenCalled - /* eslint-enable no-unused-expressions */ + }) 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 () => { expect(core.setFailed).toHaveBeenCalledWith( expect.stringContaining('PR does not contain metadata, nothing to do.') ) - /* eslint-disable no-unused-expressions */ + expect(dependabotCommits.getAlert).not.toHaveBeenCalled - /* eslint-enable no-unused-expressions */ + }) 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 ( expect(core.setFailed).toHaveBeenCalledWith( expect.stringContaining('Something bad happened!') ) - /* eslint-disable no-unused-expressions */ + expect(dependabotCommits.getAlert).not.toHaveBeenCalled - /* eslint-enable no-unused-expressions */ + }) 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 () => { expect(core.setFailed).toHaveBeenCalledWith( expect.stringContaining('(500) Something bad happened!') ) - /* eslint-disable no-unused-expressions */ + expect(dependabotCommits.getAlert).not.toHaveBeenCalled - /* eslint-enable no-unused-expressions */ + }) diff --git a/src/main.ts b/src/main.ts index f05bc1f..4cd488f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,11 +10,11 @@ export async function run (): Promise { const token = core.getInput('github-token') if (!token) { - /* eslint-disable no-template-curly-in-string */ + core.setFailed( 'github-token is not set! Please add \'github-token: "${{ secrets.GITHUB_TOKEN }}"\' to your workflow file.' ) - /* eslint-enable no-template-curly-in-string */ + return }