Skip to content

Commit 6468f10

Browse files
Fix nf-test folder (#127)
--------- Co-authored-by: Ben Sherman <bentshermann@gmail.com>
1 parent 684c0db commit 6468f10

File tree

1 file changed

+14
-3
lines changed
  • src/webview/WebviewProvider/lib/platform/utils/createTest

1 file changed

+14
-3
lines changed

src/webview/WebviewProvider/lib/platform/utils/createTest/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import * as vscode from "vscode";
22
import * as fs from "fs";
3+
import * as path from "path";
34
import generateTest from "./generateTest";
45
import generateValidation from "./generateValidation";
56
import { appendToFile } from "./utils";
67

8+
function getTestPath(filePath: string): string {
9+
const dirName = path.dirname(filePath);
10+
const testDir = path.join(dirName, "tests");
11+
if (!fs.existsSync(testDir)) {
12+
fs.mkdirSync(testDir);
13+
}
14+
const baseName = path.basename(filePath);
15+
return path.join(testDir, baseName.replace(".nf", ".nf.test"));
16+
}
17+
718
async function createTest(filePath: string, token: string): Promise<boolean> {
819
return vscode.window.withProgress(
920
{
@@ -15,8 +26,8 @@ async function createTest(filePath: string, token: string): Promise<boolean> {
1526
try {
1627
progress.report({ message: "Reading file contents" });
1728
const content = fs.readFileSync(filePath, "utf8");
18-
const newFilePath = filePath.replace(".nf", ".nf.test");
19-
const uri = vscode.Uri.file(newFilePath);
29+
const testPath = getTestPath(filePath);
30+
const uri = vscode.Uri.file(testPath);
2031

2132
// Create new file
2233
progress.report({ message: "Creating test file" });
@@ -53,7 +64,7 @@ async function createTest(filePath: string, token: string): Promise<boolean> {
5364
// Save
5465
await document.save();
5566

56-
vscode.window.showInformationMessage(`nf-test created: ${newFilePath}`);
67+
vscode.window.showInformationMessage(`nf-test created: ${testPath}`);
5768

5869
return true;
5970
} catch (error: any) {

0 commit comments

Comments
 (0)