diff --git a/src/webview/WebviewProvider/lib/platform/utils/createTest/index.ts b/src/webview/WebviewProvider/lib/platform/utils/createTest/index.ts index 3133a9b1..45475bcd 100644 --- a/src/webview/WebviewProvider/lib/platform/utils/createTest/index.ts +++ b/src/webview/WebviewProvider/lib/platform/utils/createTest/index.ts @@ -1,9 +1,20 @@ import * as vscode from "vscode"; import * as fs from "fs"; +import * as path from "path"; import generateTest from "./generateTest"; import generateValidation from "./generateValidation"; import { appendToFile } from "./utils"; +function getTestPath(filePath: string): string { + const dirName = path.dirname(filePath); + const testDir = path.join(dirName, "tests"); + if (!fs.existsSync(testDir)) { + fs.mkdirSync(testDir); + } + const baseName = path.basename(filePath); + return path.join(testDir, baseName.replace(".nf", ".nf.test")); +} + async function createTest(filePath: string, token: string): Promise { return vscode.window.withProgress( { @@ -15,8 +26,8 @@ async function createTest(filePath: string, token: string): Promise { try { progress.report({ message: "Reading file contents" }); const content = fs.readFileSync(filePath, "utf8"); - const newFilePath = filePath.replace(".nf", ".nf.test"); - const uri = vscode.Uri.file(newFilePath); + const testPath = getTestPath(filePath); + const uri = vscode.Uri.file(testPath); // Create new file progress.report({ message: "Creating test file" }); @@ -53,7 +64,7 @@ async function createTest(filePath: string, token: string): Promise { // Save await document.save(); - vscode.window.showInformationMessage(`nf-test created: ${newFilePath}`); + vscode.window.showInformationMessage(`nf-test created: ${testPath}`); return true; } catch (error: any) {