fix: properly mock utility functions in session-notification tests (#274)
The test mock for ctx.$ was not handling tagged template literals correctly, causing it to ignore interpolated values. Additionally, utility functions that check for command availability (osascript, notify-send, etc.) were returning null in test environments, causing sendNotification to exit early. Changes: - Fixed template literal reconstruction in mock $ function - Added spyOn mocks for all utility path functions - All session-notification tests now passing (11/11) Fixes #273 Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
This commit is contained in:
@@ -1,16 +1,20 @@
|
|||||||
import { describe, expect, test, beforeEach, afterEach } from "bun:test"
|
import { describe, expect, test, beforeEach, afterEach, spyOn } from "bun:test"
|
||||||
|
|
||||||
import { createSessionNotification } from "./session-notification"
|
import { createSessionNotification } from "./session-notification"
|
||||||
import { setMainSession, subagentSessions } from "../features/claude-code-session-state"
|
import { setMainSession, subagentSessions } from "../features/claude-code-session-state"
|
||||||
|
import * as utils from "./session-notification-utils"
|
||||||
|
|
||||||
describe("session-notification", () => {
|
describe("session-notification", () => {
|
||||||
let notificationCalls: string[]
|
let notificationCalls: string[]
|
||||||
|
|
||||||
function createMockPluginInput() {
|
function createMockPluginInput() {
|
||||||
return {
|
return {
|
||||||
$: async (cmd: TemplateStringsArray | string) => {
|
$: async (cmd: TemplateStringsArray | string, ...values: any[]) => {
|
||||||
// #given - track notification commands (osascript, notify-send, powershell)
|
// #given - track notification commands (osascript, notify-send, powershell)
|
||||||
const cmdStr = typeof cmd === "string" ? cmd : cmd.join("")
|
const cmdStr = typeof cmd === "string"
|
||||||
|
? cmd
|
||||||
|
: cmd.reduce((acc, part, i) => acc + part + (values[i] ?? ""), "")
|
||||||
|
|
||||||
if (cmdStr.includes("osascript") || cmdStr.includes("notify-send") || cmdStr.includes("powershell")) {
|
if (cmdStr.includes("osascript") || cmdStr.includes("notify-send") || cmdStr.includes("powershell")) {
|
||||||
notificationCalls.push(cmdStr)
|
notificationCalls.push(cmdStr)
|
||||||
}
|
}
|
||||||
@@ -26,8 +30,15 @@ describe("session-notification", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// #given - reset state before each test
|
|
||||||
notificationCalls = []
|
notificationCalls = []
|
||||||
|
|
||||||
|
spyOn(utils, "getOsascriptPath").mockResolvedValue("/usr/bin/osascript")
|
||||||
|
spyOn(utils, "getNotifySendPath").mockResolvedValue("/usr/bin/notify-send")
|
||||||
|
spyOn(utils, "getPowershellPath").mockResolvedValue("powershell")
|
||||||
|
spyOn(utils, "getAfplayPath").mockResolvedValue("/usr/bin/afplay")
|
||||||
|
spyOn(utils, "getPaplayPath").mockResolvedValue("/usr/bin/paplay")
|
||||||
|
spyOn(utils, "getAplayPath").mockResolvedValue("/usr/bin/aplay")
|
||||||
|
spyOn(utils, "startBackgroundCheck").mockImplementation(() => {})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user