Skip to content

Commit

Permalink
Merge pull request #189 from kirksl/1.2.5
Browse files Browse the repository at this point in the history
1.2.5
  • Loading branch information
kirksl authored Nov 17, 2023
2 parents e0ec95d + 09e0792 commit 134eaab
Show file tree
Hide file tree
Showing 14 changed files with 642 additions and 477 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Notable changes to this project will be documented in this file.


## 1.2.5
https://github.com/kirksl/karate-runner/milestone/16

## 1.2.4
https://github.com/kirksl/karate-runner/milestone/15

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ Test Results are rolling results meaning they will accumulate and reset only whe
*Note this feature is dependent on Karate Version >= 1.0 and Karate providing result files under the root of your project within a /karate-reports directory. Each file must end with a format of `.karate-json.txt`.*

### Editor Menu Bar
A `Karate` `Editor Menu` will be added to the VSCode Editor Menu Bar for feature files. A menu option will be added to open Karate Runner settings, clear test results from Tests view and the gutter for feature files and finally to toggle showing test results within the gutter for feature files.
A `Karate` `Editor Menu` will be added to the VSCode Editor Menu Bar for open feature files. The menu will have the following options:
- `Align Data Tables` to align delimiters (`|`) for all gherkin data tables
- `Clear Results` to clear test results from the gutter including from the `Tests` view
- `Open Settings` to open Karate Runner settings
- `Toggle Results In Gutter` to toggle showing or hiding test results within the gutter

### Peek
A `Peek` option will be added to the `Control-Click` or `Right-Click` context menu in the VSCode Editor. Clicking `Peek > Peek Definition` on a string or reference (or any combination of if concat'd) which equates to an existing file will display the contents of that file within an `Inline Peek Editor`.
Expand Down
440 changes: 202 additions & 238 deletions package-lock.json

Large diffs are not rendered by default.

56 changes: 41 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/kirksl/karate-runner"
},
"version": "1.2.4",
"version": "1.2.5",
"appInsightsId": "a285938d-a115-44ea-be2a-588a243d5f2c",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -163,7 +163,7 @@
"dark": "resources/dark/vm.svg"
}
},
{
{
"command": "karateRunner.tests.clearResults",
"title": "Clear Results",
"icon": {
Expand Down Expand Up @@ -270,6 +270,10 @@
{
"command": "karateRunner.editor.toggleResultsInGutter",
"title": "Toggle Results In Gutter"
},
{
"command": "karateRunner.editor.alignDataTables",
"title": "Align Data Tables"
}
],
"menus": {
Expand Down Expand Up @@ -300,11 +304,11 @@
"when": "view == karate-reports",
"group": "navigation@3"
},
{
"command": "karateRunner.tests.setEnvironment",
{
"command": "karateRunner.tests.setEnvironment",
"when": "view == karate-tests",
"group": "navigation@1"
},
},
{
"command": "karateRunner.tests.clearResults",
"when": "view == karate-tests",
Expand Down Expand Up @@ -402,19 +406,29 @@
],
"KarateRunner.editor.menu": [
{
"command": "karateRunner.tests.clearResults",
"command": "karateRunner.editor.alignDataTables",
"when": "resourceLangId == karate",
"group": "navigation@1"
},
{
"command": "karateRunner.tests.openSettings",
"command": "karateRunner.tests.setEnvironment",
"when": "resourceLangId == karate",
"group": "navigation@2"
},
{
"command": "karateRunner.editor.toggleResultsInGutter",
"command": "karateRunner.tests.clearResults",
"when": "resourceLangId == karate",
"group": "navigation@3"
},
{
"command": "karateRunner.tests.openSettings",
"when": "resourceLangId == karate",
"group": "navigation@4"
},
{
"command": "karateRunner.editor.toggleResultsInGutter",
"when": "resourceLangId == karate",
"group": "navigation@5"
}
]
},
Expand All @@ -432,12 +446,12 @@
"type": "object",
"title": "Karate Runner",
"properties": {
"karateRunner.core.environment": {
"type": "string",
"default": "",
"description": "Environment to test against. Karate Runner will use this value to set the 'karate.env' system property.",
"scope": "resource"
},
"karateRunner.core.environment": {
"type": "string",
"default": "",
"description": "Environment to test against. Karate Runner will use this value to set the 'karate.env' system property.",
"scope": "resource"
},
"karateRunner.karateJar.commandLineArgs": {
"type": "string",
"default": "java -cp karate.jar com.intuit.karate.Main",
Expand Down Expand Up @@ -590,6 +604,18 @@
"default": true,
"description": "Toggle showing results within the editor's gutter for feature files.",
"scope": "resource"
},
"karateRunner.alignDataTables.PreserveWhitespace": {
"type": "boolean",
"default": true,
"description": "Preserve whitespace within cells when aligning data tables.",
"scope": "resource"
},
"karateRunner.alignDataTables.Indent": {
"type": "number",
"default": 0,
"description": "Number of spaces to indent data table rows from parent (eg Examples: | * table | * set | * replace).",
"scope": "resource"
}
}
},
Expand Down Expand Up @@ -757,7 +783,7 @@
"watch": "tsc -watch -p ./",
"pretest": "npm run compile",
"test": "node ./out/test/runTest.js",
"checktypes": "tsc --noEmit"
"checktypes": "tsc --noEmit"
},
"devDependencies": {
"@types/glob": "^7.2.0",
Expand Down
137 changes: 121 additions & 16 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ async function runKarateTest(args = null)
runPhases = "test";
}

let karateRunnerEnv = (karateEnv === "") ? "" : ` -Dkarate.env=${karateEnv}`;
let karateRunnerEnv = (karateEnv === "") ? "" : ` -Dkarate.env=${karateEnv}`;
let karateRunnerArgs = String(vscode.workspace.getConfiguration('karateRunner.karateRunner').get('commandLineArgs'));

if (Boolean(vscode.workspace.getConfiguration('karateRunner.karateCli').get('overrideKarateRunner')))
Expand Down Expand Up @@ -423,7 +423,7 @@ async function runKarateTest(args = null)
}
else
{
let karateJarEnv = (karateEnv === "") ? "" : ` -e ${karateEnv}`;
let karateJarEnv = (karateEnv === "") ? "" : ` -e ${karateEnv}`;
let karateJarArgs = String(vscode.workspace.getConfiguration('karateRunner.karateJar').get('commandLineArgs'));

if (karateJarArgs === undefined || karateJarArgs === "")
Expand Down Expand Up @@ -486,7 +486,7 @@ async function runKarateTest(args = null)
if (e.execution.task.name == 'Karate Runner')
{
ProviderStatusBar.setExecutionState(false);
ProviderStatusBar.setStatus();
ProviderStatusBar.setStatus();
isTaskExecuting = false;
watcher.dispose();

Expand Down Expand Up @@ -533,8 +533,8 @@ async function runKarateTest(args = null)

let isTaskExecuting = true;
ProviderStatusBar.setExecutionState(true);
ProviderStatusBar.setStatus();
ProviderStatusBar.setStatus();

vscode.tasks.executeTask(task).then((task) => showProgress(task));
}

Expand Down Expand Up @@ -880,7 +880,7 @@ function deleteLine(args)

function openKarateSettings()
{
vscode.commands.executeCommand('workbench.action.openWorkspaceSettings', 'Karate Runner');
vscode.commands.executeCommand('workbench.action.openWorkspaceSettings', 'Karate Runner');
}

function toggleResultsInGutter()
Expand All @@ -891,15 +891,119 @@ function toggleResultsInGutter()

async function setEnvironment()
{
let env = await vscode.window.showInputBox
(
{
prompt: "Karate Environment",
value: String(vscode.workspace.getConfiguration('karateRunner.core').get('environment'))
}
);

await vscode.workspace.getConfiguration().update('karateRunner.core.environment', env);
let env = await vscode.window.showInputBox
(
{
prompt: "Karate Environment",
value: String(vscode.workspace.getConfiguration('karateRunner.core').get('environment'))
}
);

if (env !== undefined)
{
await vscode.workspace.getConfiguration().update('karateRunner.core.environment', env);
}
}

function alignDataTables() {
let preserveWhitespace = (Boolean(vscode.workspace.getConfiguration('karateRunner.alignDataTables').get('PreserveWhitespace')));
let indent = Number(vscode.workspace.getConfiguration('karateRunner.alignDataTables').get('Indent'));

vscode.window.visibleTextEditors.forEach((editor) =>
{
if (editor.document.languageId !== 'karate')
{
return;
}

let edits: { range: vscode.Range, newLine: string }[] = [];
let feature: Feature = new Feature(editor.document);
let sections: ISection[] = feature.getTestSections();

sections.forEach((section) =>
{
let dataTableSections: ISection[] = feature.getDataTableSections(section);
dataTableSections.forEach((dataTableSection) =>
{
let columnWidths: number[] = [];
let startIndex: number = -1;
for(let line = dataTableSection.startLine; line <= dataTableSection.endLine; line++)
{
let lineAt = editor.document.lineAt(line);
let text = lineAt.text.trim();

if (line == dataTableSection.startLine)
{
startIndex = lineAt.firstNonWhitespaceCharacterIndex + indent;
}

if (text.match(/^\|.+\|$/))
{
let cells = text.split('|').slice(1, -1);
cells.forEach((c, idx) =>
{
let cell: string;
if (preserveWhitespace)
{
cell = c;
}
else
{
cell = c.trim();
}

if (!columnWidths[idx] || cell.length > columnWidths[idx])
{
columnWidths[idx] = cell.length;
}
});
}
}

for(let line = dataTableSection.startLine; line <= dataTableSection.endLine; line++)
{
let lineAt = editor.document.lineAt(line);
let text = lineAt.text.trim();

if (text.match(/^\|.+\|$/))
{
let cells = text.split('|').slice(1, -1);
let newLine = ' '.repeat(startIndex) + '|';
cells.forEach((c, idx) =>
{
let newCell = c.trim();

let cellWidth: number;
if (preserveWhitespace)
{
cellWidth = columnWidths[idx] - newCell.length - 1;
}
else
{
cellWidth = columnWidths[idx] - newCell.length + 1;
}

newCell = ` ${newCell}`;
newCell = newCell + ' '.repeat(cellWidth);

newLine += newCell + '|';
});

let range = new vscode.Range(line, 0, line, lineAt.text.length);
edits.push({ range: range, newLine: newLine });
}
}
});
});

editor.edit((editBuilder: vscode.TextEditorEdit) =>
{
edits.forEach((edit) =>
{
editBuilder.replace(edit.range, edit.newLine);
});
});
});
}

export
Expand All @@ -926,5 +1030,6 @@ export
deleteLine,
openKarateSettings,
toggleResultsInGutter,
setEnvironment
setEnvironment,
alignDataTables
};
Loading

0 comments on commit 134eaab

Please sign in to comment.