Skip to content

fix(designer): Fixed unit test blade bugs for created/deleted tests #5115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/vs-code-designer/src/app/tree/unitTestTree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ const testsWorkspaceWatcher = (controller: TestController, fileChangedEmitter: E
watcher.onDidChange(async (uri) => {
fileChangedEmitter.fire(uri);
});
watcher.onDidDelete((uri) => controller.items.delete(uri.toString()));
watcher.onDidDelete((uri) => {
deleteFile(controller, uri);
fileChangedEmitter.fire(uri);
});

findInitialFiles(controller, pattern);

Expand Down Expand Up @@ -219,6 +222,9 @@ const getOrCreateFile = async (controller: TestController, uri: Uri) => {
const testName = getUnitTestName(uri.fsPath);
const unitTestFileName = path.basename(uri.fsPath);
const fileTestItem = controller.createTestItem(`${workspaceName}/${workflowName}/${unitTestFileName}`, testName, uri);
controller.items.add(fileTestItem);
const data = new TestFile();
ext.testData.set(fileTestItem, data);
existingWorkflowTest.children.add(fileTestItem);
return {};
}
Expand All @@ -244,6 +250,23 @@ const getOrCreateFile = async (controller: TestController, uri: Uri) => {
return {};
};

/**
* Removes a test for deleted file based on the provided URI.
* @param {TestController} controller - The test controller.
* @param {Uri} uri - The URI of the file.
*/
const deleteFile = async (controller: TestController, uri: Uri) => {
const workspaceName = uri.fsPath.split(path.sep).slice(-5)[0];
const workflowName = path.basename(path.dirname(uri.fsPath));
const existingWorkspaceTest = controller.items.get(workspaceName);
const existingWorkflowTest = existingWorkspaceTest.children.get(`${workspaceName}/${workflowName}`);
const unitTestFileName = path.basename(uri.fsPath);
const fileTestItem = existingWorkflowTest.children.get(`${workspaceName}/${workflowName}/${unitTestFileName}`);
existingWorkflowTest.children.delete(fileTestItem.id);
ext.testData.delete(fileTestItem);
controller.items.delete(fileTestItem.id);
};

/**
* Starts a test run based on the provided request and unit test controller.
* @param {TestRunRequest} request - The test run request.
Expand Down
Loading