Skip to content

Commit 84d4881

Browse files
committed
chore: refactor spyOn
depending on the version of vitest, calling twice is reusing the spy or creating a new one ensure we always reuse the same spy related to podman-desktop#11553 Signed-off-by: Florent Benoit <[email protected]>
1 parent 303db25 commit 84d4881

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

extensions/docker/src/docker-context-handler.spec.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,9 @@ describe('getContexts', () => {
218218
} as fs.Dirent,
219219
]);
220220

221-
vi.spyOn(fs.promises, 'readFile').mockResolvedValueOnce('invalid JSON');
222-
vi.spyOn(fs.promises, 'readFile').mockResolvedValueOnce(
223-
JSON.stringify({ Name: 'bar', Endpoints: { docker: { Host: 'foo' } } }),
224-
);
221+
const spyReadFile = vi.spyOn(fs.promises, 'readFile');
222+
spyReadFile.mockResolvedValueOnce('invalid JSON');
223+
spyReadFile.mockResolvedValueOnce(JSON.stringify({ Name: 'bar', Endpoints: { docker: { Host: 'foo' } } }));
225224

226225
const contexts = await dockerContextHandler.getContexts();
227226

@@ -247,8 +246,9 @@ describe('getContexts', () => {
247246
} as fs.Dirent,
248247
]);
249248

250-
vi.spyOn(fs.promises, 'readFile').mockResolvedValueOnce(JSON.stringify({ Name: 'foo' }));
251-
vi.spyOn(fs.promises, 'readFile').mockResolvedValueOnce(JSON.stringify({ Name: 'bar' }));
249+
const spyReadFile = vi.spyOn(fs.promises, 'readFile');
250+
spyReadFile.mockResolvedValueOnce(JSON.stringify({ Name: 'foo' }));
251+
spyReadFile.mockResolvedValueOnce(JSON.stringify({ Name: 'bar' }));
252252

253253
const contexts = await dockerContextHandler.getContexts();
254254

@@ -269,9 +269,10 @@ describe('getContexts', () => {
269269
name: 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9',
270270
} as fs.Dirent,
271271
]);
272+
const spyReadFile = vi.spyOn(fs.promises, 'readFile');
272273

273-
vi.spyOn(fs.promises, 'readFile').mockResolvedValueOnce(JSON.stringify({ Name: 'foo' }));
274-
vi.spyOn(fs.promises, 'readFile').mockResolvedValueOnce(JSON.stringify({ Name: 'bar' }));
274+
spyReadFile.mockResolvedValueOnce(JSON.stringify({ Name: 'foo' }));
275+
spyReadFile.mockResolvedValueOnce(JSON.stringify({ Name: 'bar' }));
275276

276277
const contexts = await dockerContextHandler.getContexts();
277278

0 commit comments

Comments
 (0)