diff --git a/src/features/helper/configuration.ts b/src/features/helper/configuration.ts index 6cad68c..4cef2e1 100644 --- a/src/features/helper/configuration.ts +++ b/src/features/helper/configuration.ts @@ -428,6 +428,9 @@ export default class Configuration { const fileName = editor ? Utilities.normalizePath(editor.document.fileName) : undefined; const vars: Variables = { + // - the path of the user's home folder + userHome: process.env.HOME || process.env.USERPROFILE, + // - the path of the folder opened in VS Code workspaceFolder: rootPath, diff --git a/src/features/helper/types/variables.ts b/src/features/helper/types/variables.ts index 4f3cf8a..55ff7fd 100644 --- a/src/features/helper/types/variables.ts +++ b/src/features/helper/types/variables.ts @@ -1,4 +1,5 @@ type Variables = { + userHome?: string; fileWorkspaceFolder?: string; workspaceFolder?: string; workspaceFolderBasename?: string; diff --git a/src/features/helper/utilities.ts b/src/features/helper/utilities.ts index aa373fa..d999216 100644 --- a/src/features/helper/utilities.ts +++ b/src/features/helper/utilities.ts @@ -14,7 +14,7 @@ export default class Utilities { } static interpolateString(command: string, variables: Variables): string { - const regex = /\$\{([^\}]+)\}/g; // eslint-disable-line no-useless-escape + const regex = /\$\{([^}]+)\}/g; const match = command.match(regex); while (match?.length) { diff --git a/test/suite/extension.test.ts b/test/suite/extension.test.ts index a8ed696..a4779cc 100644 --- a/test/suite/extension.test.ts +++ b/test/suite/extension.test.ts @@ -36,13 +36,10 @@ suite("Extension Test Suite", () => { test("Bad SQL has zero diagnostics after document format", async () => { const documentUri = Helper.getDocumentUri("/test_sql/format.sql"); - const document = await Helper.activate(documentUri); + await Helper.activate(documentUri); const preFormatDiagnostics = vscode.languages.getDiagnostics(documentUri); assert.strictEqual(preFormatDiagnostics.length, 1, "Pre-format diagnostics not expected length"); - await Helper.format(documentUri); - await Helper.activate(documentUri); - const postFormatDiagnostics = vscode.languages.getDiagnostics(documentUri); assert.strictEqual(postFormatDiagnostics.length, 0, "Post-format diagnostics not expected length"); diff --git a/test/suite/helper.ts b/test/suite/helper.ts index 9a9fde1..4131652 100644 --- a/test/suite/helper.ts +++ b/test/suite/helper.ts @@ -1,7 +1,7 @@ import * as assert from "assert"; import * as vscode from "vscode"; -export const SLEEP_TIME = 10000; +export const SLEEP_TIME = 2000; export const activate = async (documentUri: vscode.Uri): Promise => { // The extensionId is `publisher.name` from package.json @@ -13,9 +13,7 @@ export const activate = async (documentUri: vscode.Uri): Promise { const document = await vscode.workspace.openTextDocument(documentUri); await vscode.window.showTextDocument(document); await vscode.commands.executeCommand("editor.action.formatDocument"); - await sleep(SLEEP_TIME); await document.save(); - await sleep(SLEEP_TIME); // Wait for server activation - return document; } catch (e) { console.error(e); diff --git a/test/suite/utilities.test.ts b/test/suite/utilities.test.ts new file mode 100644 index 0000000..81a9270 --- /dev/null +++ b/test/suite/utilities.test.ts @@ -0,0 +1,25 @@ +import * as assert from "assert"; + +import Configuration from "../../src/features/helper/configuration"; +import Variables from "../../src/features/helper/types/variables"; +import Utilities from "../../src/features/helper/utilities"; + +suite("Utilities Function Test Suite", () => { + const variables = Configuration.variables(); + const variablesToCheck = [ + "userHome", + "workspaceFolder", + "workspaceFolderBasename", + "execPath", + ]; + variablesToCheck.forEach((variable) => { + test(`${variable} resolves in interpolation`, function () { + const interpolatedString = Utilities.interpolateString( + `\${${variable}}`, + variables, + ); + const expectedValue = variables[variable as keyof Variables]; + assert.strictEqual(interpolatedString, expectedValue); + }); + }); +});