From 8e71d368140e5c904caf311c383b9150d211c2a8 Mon Sep 17 00:00:00 2001 From: Aryan sharma Date: Tue, 31 Dec 2024 18:07:37 +0530 Subject: [PATCH 1/5] refracting jest to vitest issue-#2749 --- ...Url.test.ts => askForTalawaApiUrl.spec.ts} | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) rename src/setup/askForTalawaApiUrl/{askForTalawaApiUrl.test.ts => askForTalawaApiUrl.spec.ts} (62%) diff --git a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.test.ts b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts similarity index 62% rename from src/setup/askForTalawaApiUrl/askForTalawaApiUrl.test.ts rename to src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts index 3a11a0d799..8c0ea38061 100644 --- a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.test.ts +++ b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts @@ -1,17 +1,22 @@ import inquirer from 'inquirer'; import { askForTalawaApiUrl } from './askForTalawaApiUrl'; - -jest.mock('inquirer', () => ({ - prompt: jest.fn(), -})); +import {vi , it , expect , beforeEach , describe} from 'vitest'; + +vi.mock('inquirer', async (importOriginal) => { + const actual = await importOriginal(); + return { + ...actual, + prompt: vi.fn(), + }; +}); describe('askForTalawaApiUrl', () => { beforeEach(() => { - jest.clearAllMocks(); + vi.clearAllMocks(); }); - test('should return the provided endpoint when user enters it', async () => { - const mockPrompt = jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ + it('should return the provided endpoint when user enters it', async () => { + const mockPrompt = vi.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ endpoint: 'http://example.com/graphql/', }); @@ -29,8 +34,8 @@ describe('askForTalawaApiUrl', () => { expect(result).toBe('http://example.com/graphql/'); }); - test('should return the default endpoint when the user does not enter anything', async () => { - const mockPrompt = jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ + it('should return the default endpoint when the user does not enter anything', async () => { + const mockPrompt = vi.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ endpoint: 'http://localhost:4000/graphql/', }); @@ -48,3 +53,5 @@ describe('askForTalawaApiUrl', () => { expect(result).toBe('http://localhost:4000/graphql/'); }); }); + + From 6e262722023e2d816a796740442b42ebf18a97a3 Mon Sep 17 00:00:00 2001 From: Aryan sharma Date: Tue, 31 Dec 2024 18:25:34 +0530 Subject: [PATCH 2/5] Fix formatting using Prettier --- src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts index 8c0ea38061..4d85177ce5 100644 --- a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts +++ b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts @@ -1,12 +1,12 @@ import inquirer from 'inquirer'; import { askForTalawaApiUrl } from './askForTalawaApiUrl'; -import {vi , it , expect , beforeEach , describe} from 'vitest'; +import { vi, it, expect, beforeEach, describe } from 'vitest'; vi.mock('inquirer', async (importOriginal) => { const actual = await importOriginal(); return { - ...actual, - prompt: vi.fn(), + ...actual, + prompt: vi.fn(), }; }); @@ -53,5 +53,3 @@ describe('askForTalawaApiUrl', () => { expect(result).toBe('http://localhost:4000/graphql/'); }); }); - - From 1dd1ba48b09fd1ced1eda3922937df85d52d0d25 Mon Sep 17 00:00:00 2001 From: Aryan sharma Date: Tue, 31 Dec 2024 21:06:37 +0530 Subject: [PATCH 3/5] fix --- src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts index 4d85177ce5..eb58719e97 100644 --- a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts +++ b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts @@ -1,9 +1,9 @@ import inquirer from 'inquirer'; import { askForTalawaApiUrl } from './askForTalawaApiUrl'; -import { vi, it, expect, beforeEach, describe } from 'vitest'; +import { vi, it, describe, expect, beforeEach } from 'vitest'; vi.mock('inquirer', async (importOriginal) => { - const actual = await importOriginal(); + const actual = await importOriginal(); // Adding explicit type return { ...actual, prompt: vi.fn(), @@ -52,4 +52,4 @@ describe('askForTalawaApiUrl', () => { expect(result).toBe('http://localhost:4000/graphql/'); }); -}); +}); \ No newline at end of file From ff5b9265d52fd3572e7099c8c2d528c8be596962 Mon Sep 17 00:00:00 2001 From: Aryan sharma Date: Tue, 31 Dec 2024 21:14:21 +0530 Subject: [PATCH 4/5] fix --- src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts index eb58719e97..400c5196c2 100644 --- a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts +++ b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts @@ -2,8 +2,8 @@ import inquirer from 'inquirer'; import { askForTalawaApiUrl } from './askForTalawaApiUrl'; import { vi, it, describe, expect, beforeEach } from 'vitest'; -vi.mock('inquirer', async (importOriginal) => { - const actual = await importOriginal(); // Adding explicit type +vi.mock('inquirer', async () => { + const actual = await vi.importActual('inquirer'); return { ...actual, prompt: vi.fn(), From 751e1b45f07eace3ceee19fc1f5be0e9d8940d72 Mon Sep 17 00:00:00 2001 From: Aryan sharma Date: Tue, 31 Dec 2024 21:20:15 +0530 Subject: [PATCH 5/5] fixed --- src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts index 400c5196c2..bceecb806f 100644 --- a/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts +++ b/src/setup/askForTalawaApiUrl/askForTalawaApiUrl.spec.ts @@ -52,4 +52,4 @@ describe('askForTalawaApiUrl', () => { expect(result).toBe('http://localhost:4000/graphql/'); }); -}); \ No newline at end of file +});