Handle comments from the PR

This commit is contained in:
Sander Declerck 2025-07-18 14:23:51 +02:00
parent 6c269a1bb5
commit 36c195f5a9
No known key found for this signature in database
14 changed files with 166 additions and 181 deletions

View file

@ -3,6 +3,7 @@ import assert from "node:assert";
import { tmpdir } from "node:os";
import fs from "node:fs";
import path from "path";
import { knownAikidoTools } from "../helpers.js";
describe("Windows PowerShell shell integration", () => {
let mockStartupFile;
@ -10,8 +11,11 @@ describe("Windows PowerShell shell integration", () => {
beforeEach(async () => {
// Create temporary startup file for testing
mockStartupFile = path.join(tmpdir(), `test-windows-powershell-profile-${Date.now()}.ps1`);
mockStartupFile = path.join(
tmpdir(),
`test-windows-powershell-profile-${Date.now()}.ps1`
);
// Mock the helpers module
mock.module("../helpers.js", {
namedExports: {
@ -26,10 +30,10 @@ describe("Windows PowerShell shell integration", () => {
if (!fs.existsSync(filePath)) return;
const content = fs.readFileSync(filePath, "utf-8");
const lines = content.split("\n");
const filteredLines = lines.filter(line => !pattern.test(line));
const filteredLines = lines.filter((line) => !pattern.test(line));
fs.writeFileSync(filePath, filteredLines.join("\n"), "utf-8");
}
}
},
},
});
// Mock child_process execSync
@ -48,7 +52,7 @@ describe("Windows PowerShell shell integration", () => {
if (fs.existsSync(mockStartupFile)) {
fs.unlinkSync(mockStartupFile);
}
// Reset mocks
mock.reset();
});
@ -69,34 +73,30 @@ describe("Windows PowerShell shell integration", () => {
const tools = [
{ tool: "npm", aikidoCommand: "aikido-npm" },
{ tool: "npx", aikidoCommand: "aikido-npx" },
{ tool: "yarn", aikidoCommand: "aikido-yarn" }
{ tool: "yarn", aikidoCommand: "aikido-yarn" },
];
const result = windowsPowershell.setup(tools);
assert.strictEqual(result, true);
const content = fs.readFileSync(mockStartupFile, "utf-8");
assert.ok(content.includes('Set-Alias npm aikido-npm # Safe-chain alias for npm'));
assert.ok(content.includes('Set-Alias npx aikido-npx # Safe-chain alias for npx'));
assert.ok(content.includes('Set-Alias yarn aikido-yarn # Safe-chain alias for yarn'));
});
it("should call teardown before setup", () => {
// Pre-populate file with existing aliases
fs.writeFileSync(mockStartupFile, 'Set-Alias npm old-npm\nSet-Alias npx old-npx\n', "utf-8");
const tools = [{ tool: "npm", aikidoCommand: "aikido-npm" }];
windowsPowershell.setup(tools);
const content = fs.readFileSync(mockStartupFile, "utf-8");
assert.ok(!content.includes('Set-Alias npm old-npm'));
assert.ok(content.includes('Set-Alias npm aikido-npm'));
assert.ok(
content.includes("Set-Alias npm aikido-npm # Safe-chain alias for npm")
);
assert.ok(
content.includes("Set-Alias npx aikido-npx # Safe-chain alias for npx")
);
assert.ok(
content.includes(
"Set-Alias yarn aikido-yarn # Safe-chain alias for yarn"
)
);
});
it("should handle empty tools array", () => {
const result = windowsPowershell.setup([]);
assert.strictEqual(result, true);
// File should be created during teardown call even if no tools are provided
if (fs.existsSync(mockStartupFile)) {
const content = fs.readFileSync(mockStartupFile, "utf-8");
@ -113,12 +113,12 @@ describe("Windows PowerShell shell integration", () => {
"Set-Alias npx aikido-npx",
"Set-Alias yarn aikido-yarn",
"Set-Alias ls Get-ChildItem",
"Set-Alias grep Select-String"
"Set-Alias grep Select-String",
].join("\n");
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
const result = windowsPowershell.teardown();
const result = windowsPowershell.teardown(knownAikidoTools);
assert.strictEqual(result, true);
const content = fs.readFileSync(mockStartupFile, "utf-8");
@ -134,7 +134,7 @@ describe("Windows PowerShell shell integration", () => {
fs.unlinkSync(mockStartupFile);
}
const result = windowsPowershell.teardown();
const result = windowsPowershell.teardown(knownAikidoTools);
assert.strictEqual(result, true);
});
@ -142,12 +142,12 @@ describe("Windows PowerShell shell integration", () => {
const initialContent = [
"# Windows PowerShell profile",
"Set-Alias ls Get-ChildItem",
"$env:PATH += ';C:\\Tools'"
"$env:PATH += ';C:\\Tools'",
].join("\n");
fs.writeFileSync(mockStartupFile, initialContent, "utf-8");
const result = windowsPowershell.teardown();
const result = windowsPowershell.teardown(knownAikidoTools);
assert.strictEqual(result, true);
const content = fs.readFileSync(mockStartupFile, "utf-8");
@ -173,17 +173,17 @@ describe("Windows PowerShell shell integration", () => {
it("should handle complete setup and teardown cycle", () => {
const tools = [
{ tool: "npm", aikidoCommand: "aikido-npm" },
{ tool: "yarn", aikidoCommand: "aikido-yarn" }
{ tool: "yarn", aikidoCommand: "aikido-yarn" },
];
// Setup
windowsPowershell.setup(tools);
let content = fs.readFileSync(mockStartupFile, "utf-8");
assert.ok(content.includes('Set-Alias npm aikido-npm'));
assert.ok(content.includes('Set-Alias yarn aikido-yarn'));
assert.ok(content.includes("Set-Alias npm aikido-npm"));
assert.ok(content.includes("Set-Alias yarn aikido-yarn"));
// Teardown
windowsPowershell.teardown();
windowsPowershell.teardown(tools);
content = fs.readFileSync(mockStartupFile, "utf-8");
assert.ok(!content.includes("Set-Alias npm "));
assert.ok(!content.includes("Set-Alias yarn "));
@ -193,11 +193,12 @@ describe("Windows PowerShell shell integration", () => {
const tools = [{ tool: "npm", aikidoCommand: "aikido-npm" }];
windowsPowershell.setup(tools);
windowsPowershell.teardown(tools);
windowsPowershell.setup(tools);
const content = fs.readFileSync(mockStartupFile, "utf-8");
const npmMatches = (content.match(/Set-Alias npm /g) || []).length;
assert.strictEqual(npmMatches, 1, "Should not duplicate aliases");
});
});
});
});