Skip to content

Add objectscript.unitTest.enabled setting for better coexistence with other testing extensions #1627

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
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,11 @@
"type": "boolean",
"default": true
},
"objectscript.unitTest.enabled": {
"description": "Controls whether the unit testing features are available.",
"type": "boolean",
"default": true
},
"objectscript.unitTest.relativeTestRoots": {
"description": "Paths to where client-side test classes are stored. Relative to the workspace folder root.",
"type": "array",
Expand Down
46 changes: 43 additions & 3 deletions src/commands/unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,27 @@ function configureHandler(): void {
}

/** Set up the `TestController` and all of its dependencies. */
export function setUpTestController(): vscode.Disposable[] {
export function setUpTestController(context: vscode.ExtensionContext): vscode.Disposable[] {
// If currently disabled, just create a mechanism to activate when the setting changes
if (vscode.workspace.getConfiguration("objectscript.unitTest").get("enabled") === false) {
const disposablesWhenDisabled = [
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("objectscript.unitTest")) {
if (vscode.workspace.getConfiguration("objectscript.unitTest").get("enabled") === true) {
// Set myself up as active
const disposablesWhenEnabled = setUpTestController(context);
context.subscriptions.push(...disposablesWhenEnabled);
// Clean up after inactive state
disposablesWhenDisabled.forEach((disposable) => {
disposable.dispose();
});
return;
}
}
}),
];
return disposablesWhenDisabled;
}
// Create and set up the test controller
const testController = vscode.tests.createTestController(extensionId, "ObjectScript");
testController.resolveHandler = async (item?: vscode.TestItem) => {
Expand Down Expand Up @@ -1049,8 +1069,8 @@ export function setUpTestController(): vscode.Disposable[] {
return result;
};

// Register disposables
return [
// Gather disposables
const disposables = [
testController,
runProfile,
debugProfile,
Expand Down Expand Up @@ -1130,4 +1150,24 @@ export function setUpTestController(): vscode.Disposable[] {
})
),
];

return [
...disposables,
// Add a listener to disable myself if the setting changes
vscode.workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration("objectscript.unitTest")) {
if (vscode.workspace.getConfiguration("objectscript.unitTest").get("enabled") === false) {
// Remove my active self and clean up
testController.dispose();
disposables.forEach((disposable) => {
disposable.dispose();
});
// Create a stub self that will reactivate when enabled again
const disposablesWhenEnabled = setUpTestController(context);
context.subscriptions.push(...disposablesWhenEnabled);
return;
}
}
}),
];
}
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}
}
}),
...setUpTestController(),
...setUpTestController(context),
vscode.commands.registerCommand("vscode-objectscript.reopenInLowCodeEditor", (uri: vscode.Uri) => {
if (vscode.window.activeTextEditor?.document.uri.toString() == uri.toString()) {
vscode.commands
Expand Down Expand Up @@ -1943,6 +1943,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
"config.autoPreviewXML": String(conf.get("autoPreviewXML")),
"config.showGeneratedFileDecorations": String(conf.get("showGeneratedFileDecorations")),
"config.showProposedApiPrompt": String(conf.get("showProposedApiPrompt")),
"config.unitTest.enabled": String(conf.get("unitTest.enabled")),
});
sendWsFolderTelemetryEvent(vscode.workspace.workspaceFolders);

Expand Down