Skip to content

Commit 0a432b3

Browse files
refactor: update import statements to use .js extensions for consistency
1 parent a6e0828 commit 0a432b3

File tree

6 files changed

+36
-38
lines changed

6 files changed

+36
-38
lines changed

src/tools/testmanagement-utils/TCG-utils/api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {
55
FETCH_DETAILS_URL,
66
FORM_FIELDS_URL,
77
BULK_CREATE_URL,
8-
} from "./config";
8+
} from "./config.js";
99
import {
1010
DefaultFieldMaps,
1111
Scenario,
1212
CreateTestCasesFromFileArgs,
13-
} from "./types";
14-
import { createTestCasePayload } from "./helpers";
15-
import config from "../../../config";
13+
} from "./types.js";
14+
import { createTestCasePayload } from "./helpers.js";
15+
import config from "../../../config.js";
1616

1717
/**
1818
* Fetch default and custom form fields for a project.

src/tools/testmanagement-utils/TCG-utils/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DefaultFieldMaps } from "./types";
1+
import { DefaultFieldMaps } from "./types.js";
22

33
/**
44
* Build mappings for default fields for priority, status, and case type.

src/tools/testmanagement-utils/testcase-from-file.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import { CreateTestCasesFromFileArgs } from "./TCG-utils/types";
1+
import { CreateTestCasesFromFileArgs } from "./TCG-utils/types.js";
22
import {
33
fetchFormFields,
44
triggerTestCaseGeneration,
55
pollScenariosTestDetails,
66
bulkCreateTestCases,
7-
} from "./TCG-utils/api";
8-
import { buildDefaultFieldMaps, findBooleanFieldId } from "./TCG-utils/helpers";
7+
} from "./TCG-utils/api.js";
8+
import {
9+
buildDefaultFieldMaps,
10+
findBooleanFieldId,
11+
} from "./TCG-utils/helpers.js";
912
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
10-
import { signedUrlMap } from "../../lib/inmemory-store";
11-
import logger from "../../logger";
12-
import { projectIdentifierToId } from "./TCG-utils/api";
13+
import { signedUrlMap } from "../../lib/inmemory-store.js";
14+
import logger from "../../logger.js";
15+
import { projectIdentifierToId } from "./TCG-utils/api.js";
1316

1417
export async function createTestCasesFromFile(
1518
args: CreateTestCasesFromFileArgs,

src/tools/testmanagement-utils/upload-file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import FormData from "form-data";
55
import fs from "fs";
66
import path from "path";
77
import { v4 as uuidv4 } from "uuid";
8-
import config from "../../config";
9-
import { signedUrlMap } from "../../lib/inmemory-store";
10-
import { projectIdentifierToId } from "./TCG-utils/api";
8+
import config from "../../config.js";
9+
import { signedUrlMap } from "../../lib/inmemory-store.js";
10+
import { projectIdentifierToId } from "./TCG-utils/api.js";
1111

1212
/**
1313
* Schema for the upload file tool

src/tools/testmanagement.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ import {
4444
import {
4545
UploadFileSchema,
4646
uploadFile,
47-
} from "./testmanagement-utils/upload-file";
47+
} from "./testmanagement-utils/upload-file.js";
4848

49-
import { createTestCasesFromFile } from "./testmanagement-utils/testcase-from-file";
50-
import { CreateTestCasesFromFileSchema } from "./testmanagement-utils/TCG-utils/types";
49+
import { createTestCasesFromFile } from "./testmanagement-utils/testcase-from-file.js";
50+
import { CreateTestCasesFromFileSchema } from "./testmanagement-utils/TCG-utils/types.js";
5151

5252
//TODO: Moving the traceMCP and catch block to the parent(server) function
5353

tests/tools/testmanagement.test.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { updateTestRun } from '../../src/tools/testmanagement-utils/update-testr
1919
import { createTestCasesFromFile } from '../../src/tools/testmanagement-utils/testcase-from-file';
2020
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2121
import axios from 'axios';
22-
import { beforeEach, it, expect, describe, vi, Mock, Mocked } from 'vitest'
22+
import { beforeEach, it, expect, describe, Mocked} from 'vitest';
23+
import { vi, Mock } from 'vitest';
2324
import fs from 'fs';
2425
import { signedUrlMap } from '../../src/lib/inmemory-store';
2526

@@ -39,10 +40,10 @@ vi.mock('../../src/tools/testmanagement-utils/create-testcase', () => ({
3940
},
4041
}));
4142

42-
jest.mock('../../src/tools/testmanagement-utils/testcase-from-file', () => ({
43-
createTestCasesFromFile: jest.fn(),
43+
vi.mock('../../src/tools/testmanagement-utils/testcase-from-file', () => ({
44+
createTestCasesFromFile: vi.fn(),
4445
}));
45-
jest.mock('../../src/config', () => ({
46+
vi.mock('../../src/config', () => ({
4647
__esModule: true,
4748
default: {
4849
browserstackUsername: 'fake-user',
@@ -61,14 +62,14 @@ vi.mock('../../src/tools/testmanagement-utils/add-test-result', () => ({
6162
},
6263
}));
6364

64-
jest.mock('fs');
65-
jest.mock('../../src/lib/inmemory-store', () => ({ signedUrlMap: new Map() }));
65+
vi.mock('fs');
66+
vi.mock('../../src/lib/inmemory-store', () => ({ signedUrlMap: new Map() }));
6667

6768
const mockServer = {
6869
tool: vi.fn(),
6970
server: {
7071
getClientVersion: vi.fn(() => ({
71-
name: 'jest-client',
72+
name: 'vi-client',
7273
version: '1.0.0',
7374
})),
7475
},
@@ -440,21 +441,21 @@ const testDocumentId = "mock-doc-id";
440441
const testFolderId = "mock-folder-id";
441442
const mockFileId = 12345;
442443
const mockDownloadUrl = "https://cdn.browserstack.com/mock.pdf";
443-
const mockContext = { sendNotification: jest.fn(), _meta: { progressToken: "test-progress-token" } };
444+
const mockContext = { sendNotification: vi.fn(), _meta: { progressToken: "test-progress-token" } };
444445

445446
describe("uploadFileTestManagementTool", () => {
446-
beforeEach(() => jest.resetAllMocks());
447+
beforeEach(() => vi.resetAllMocks());
447448

448449
it("returns error when file does not exist", async () => {
449-
(fs.existsSync as jest.Mock).mockReturnValue(false);
450+
(fs.existsSync as Mock).mockReturnValue(false);
450451
const res = await uploadFileTestManagementTool({ project_identifier: testProjectId, file_path: testFilePath });
451452
expect(res.isError).toBe(true);
452453
expect(res.content[0].text).toContain("does not exist");
453454
});
454455

455456
it("uploads file and returns metadata", async () => {
456-
(fs.existsSync as jest.Mock).mockReturnValue(true);
457-
(fs.createReadStream as jest.Mock).mockReturnValue("STREAM");
457+
(fs.existsSync as Mock).mockReturnValue(true);
458+
(fs.createReadStream as Mock).mockReturnValue("STREAM");
458459
const mockUpload = {
459460
status: 200,
460461
data: {
@@ -479,12 +480,11 @@ describe("uploadFileTestManagementTool", () => {
479480

480481
// Tests for createTestCasesFromFileTool
481482
describe("createTestCasesFromFileTool", () => {
482-
beforeEach(() => jest.resetAllMocks());
483+
beforeEach(() => vi.resetAllMocks());
483484

484485
it("returns error when document is not in signedUrlMap", async () => {
485486
signedUrlMap.clear();
486-
// Mock createTestCasesFromFile to throw an error message about re-uploading the file
487-
(createTestCasesFromFile as jest.Mock).mockRejectedValue(new Error("Re-Upload the file"));
487+
(createTestCasesFromFile as Mock).mockRejectedValue(new Error("Re-Upload the file"));
488488

489489
const args = { documentId: testDocumentId, folderId: testFolderId, projectReferenceId: testProjectId };
490490
const res = await createTestCasesFromFileTool(args as any, mockContext);
@@ -504,8 +504,6 @@ describe("createTestCasesFromFileTool", () => {
504504
custom_fields: []
505505
}
506506
});
507-
// Mock the necessary API calls for success
508-
509507
mockedAxios.post.mockImplementation((url: string) => {
510508
if (url.includes("suggest-test-cases")) {
511509
return Promise.resolve({ status: 200, data: { "x-bstack-traceRequestId": "trace" } });
@@ -519,10 +517,7 @@ describe("createTestCasesFromFileTool", () => {
519517
return Promise.resolve({ status: 404, data: {} });
520518
});
521519
const args = { documentId: testDocumentId, folderId: testFolderId, projectReferenceId: testProjectId };
522-
523-
// Mock the createTestCasesFromFile to return a specific result
524-
// Use the mocked implementation directly instead of require
525-
(createTestCasesFromFile as jest.Mock).mockReturnValue({
520+
(createTestCasesFromFile as Mock).mockReturnValue({
526521
content: [{ type: "text", text: "Total of 5 test cases created in 2 scenarios." }],
527522
isError: false
528523
});

0 commit comments

Comments
 (0)