Skip to content

Commit e7ac1d5

Browse files
committed
reset
1 parent a671ea8 commit e7ac1d5

1 file changed

Lines changed: 31 additions & 55 deletions

File tree

packages/deploymentUtils/tests/changesets/checkDestructiveChanges.test.ts

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
describe,
77
expect,
88
test,
9-
vi
9+
vi,
10+
afterEach
1011
} from "vitest"
1112
import {
1213
checkDestructiveChanges,
@@ -102,43 +103,34 @@ describe("checkDestructiveChanges", () => {
102103
})
103104

104105
describe("checkDestructiveChangeSet", () => {
106+
const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined)
107+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined)
108+
afterEach(() => {
109+
logSpy.mockReset()
110+
errorSpy.mockReset()
111+
})
112+
105113
test("logs success when no destructive changes are present", async () => {
106114
mockCloudFormationSend.mockResolvedValueOnce(safeChangeSet)
107115

108-
const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined)
109-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined)
110-
111-
try {
112-
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2")).resolves.toBeUndefined()
116+
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2")).resolves.toBeUndefined()
113117

114-
expect(mockCloudFormationSend).toHaveBeenCalledTimes(1)
115-
const command = mockCloudFormationSend.mock.calls[0][0] as { input: { ChangeSetName: string; StackName: string } }
116-
expect(command.input).toEqual({ChangeSetName: "cs", StackName: "stack"})
117-
expect(logSpy).toHaveBeenCalledWith("Change set cs for stack stack has no destructive changes.")
118-
expect(errorSpy).not.toHaveBeenCalled()
119-
} finally {
120-
logSpy.mockRestore()
121-
errorSpy.mockRestore()
122-
}
118+
expect(mockCloudFormationSend).toHaveBeenCalledTimes(1)
119+
const command = mockCloudFormationSend.mock.calls[0][0] as { input: { ChangeSetName: string; StackName: string } }
120+
expect(command.input).toEqual({ChangeSetName: "cs", StackName: "stack"})
121+
expect(logSpy).toHaveBeenCalledWith("Change set cs for stack stack has no destructive changes.")
122+
expect(errorSpy).not.toHaveBeenCalled()
123123
})
124124

125125
test("logs details and throws when destructive changes exist", async () => {
126126
mockCloudFormationSend.mockResolvedValueOnce(destructiveChangeSet)
127127

128-
const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined)
129-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined)
130-
131-
try {
132-
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2"))
133-
.rejects.toThrow("Change set cs contains destructive changes")
128+
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2"))
129+
.rejects.toThrow("Change set cs contains destructive changes")
134130

135-
expect(mockCloudFormationSend).toHaveBeenCalledTimes(1)
136-
expect(logSpy).not.toHaveBeenCalled()
137-
expect(errorSpy).toHaveBeenCalledWith("Resources that require attention:")
138-
} finally {
139-
logSpy.mockRestore()
140-
errorSpy.mockRestore()
141-
}
131+
expect(mockCloudFormationSend).toHaveBeenCalledTimes(1)
132+
expect(logSpy).not.toHaveBeenCalled()
133+
expect(errorSpy).toHaveBeenCalledWith("Resources that require attention:")
142134
})
143135

144136
test("allows matching destructive changes when waiver is active", async () => {
@@ -169,21 +161,13 @@ describe("checkDestructiveChangeSet", () => {
169161
}
170162
]
171163

172-
const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined)
173-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined)
174-
175-
try {
176-
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2", allowedChanges))
177-
.resolves.toBeUndefined()
164+
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2", allowedChanges))
165+
.resolves.toBeUndefined()
178166

179-
expect(mockCloudFormationSend).toHaveBeenCalledTimes(1)
180-
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Allowing destructive change ResourceToRemove"))
181-
expect(logSpy).toHaveBeenCalledWith("Change set cs for stack stack has no destructive changes.")
182-
expect(errorSpy).not.toHaveBeenCalled()
183-
} finally {
184-
logSpy.mockRestore()
185-
errorSpy.mockRestore()
186-
}
167+
expect(mockCloudFormationSend).toHaveBeenCalledTimes(1)
168+
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Allowing destructive change ResourceToRemove"))
169+
expect(logSpy).toHaveBeenCalledWith("Change set cs for stack stack has no destructive changes.")
170+
expect(errorSpy).not.toHaveBeenCalled()
187171
})
188172

189173
test("throws when waiver expired before change set creation", async () => {
@@ -214,19 +198,11 @@ describe("checkDestructiveChangeSet", () => {
214198
}
215199
]
216200

217-
const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined)
218-
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined)
201+
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2", allowedChanges))
202+
.rejects.toThrow("Change set cs contains destructive changes")
219203

220-
try {
221-
await expect(checkDestructiveChangeSet("cs", "stack", "eu-west-2", allowedChanges))
222-
.rejects.toThrow("Change set cs contains destructive changes")
223-
224-
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("Waiver for ResourceToRemove"))
225-
expect(errorSpy).toHaveBeenCalledWith("Resources that require attention:")
226-
expect(logSpy).not.toHaveBeenCalledWith("Change set cs for stack stack has no destructive changes.")
227-
} finally {
228-
logSpy.mockRestore()
229-
errorSpy.mockRestore()
230-
}
204+
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining("Waiver for ResourceToRemove"))
205+
expect(errorSpy).toHaveBeenCalledWith("Resources that require attention:")
206+
expect(logSpy).not.toHaveBeenCalledWith("Change set cs for stack stack has no destructive changes.")
231207
})
232208
})

0 commit comments

Comments
 (0)