From e685e294da79db879c20456e2e6ee6f181368a53 Mon Sep 17 00:00:00 2001 From: John Lindquist Date: Wed, 4 Dec 2024 13:07:56 -0700 Subject: [PATCH] fix(test): fix tmp-promise for custom. new scriptlet accept name. recent group ignore favorite --- src/cli/new-scriptlet.ts | 10 +++++++--- src/core/group.test.ts | 20 ++++++++++++++++++++ src/core/group.ts | 1 + src/globals/custom.test.ts | 9 +++++++-- src/main/scriptlet.ts | 1 + 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/cli/new-scriptlet.ts b/src/cli/new-scriptlet.ts index b6b6588f..c5082de0 100755 --- a/src/cli/new-scriptlet.ts +++ b/src/cli/new-scriptlet.ts @@ -14,7 +14,11 @@ Opens ~/.kenv/scriptlets/scriptlets.md in your selected editor await ensureDir(kenvPath("scriptlets")) let scriptletsPath = kenvPath("scriptlets", "scriptlets.md") -if (arg?.pass) { +let name = arg?.pass || await arg({ + placeholder: "Scriptlet Name", + enter: "Create Scriptlet", +}) +if (name) { let content = await readFile(scriptletsPath, "utf-8") let whitespace = "" if (content.trim() !== "") { @@ -23,9 +27,9 @@ if (arg?.pass) { await appendFile( scriptletsPath, - `${whitespace}## ${arg?.pass} + `${whitespace}## ${name} -\`\`\` +\`\`\`ts \`\`\` ` diff --git a/src/core/group.test.ts b/src/core/group.test.ts index 4a16b750..7167ab01 100644 --- a/src/core/group.test.ts +++ b/src/core/group.test.ts @@ -144,6 +144,26 @@ ava("groupChoices - recentKey and recentLimit", t => { t.is(result[0].choices[1].name, "B1") }) +ava("groupChoices - don't add Favorite group to recent", t => { + const choices: Choice[] = [ + { name: "A1", group: "Favorite", lastUsed: 3 }, + { name: "A2", group: "A", lastUsed: 1 }, + { name: "B1", group: "B", lastUsed: 2 }, + { name: "C1", group: "C" }, + ] as Choice[] + + const result = groupChoices(choices, { + recentKey: "lastUsed", + recentLimit: 2, + }) + + t.is(result[0].name, "Recent") + t.is(result[0].choices.length, 2) + t.is(result[0].choices[0].name, "B1") + t.is(result[0].choices[1].name, "A2") +}) + + ava("groupChoices - hideWithoutInput", t => { const choices: Choice[] = [ { name: "A1", group: "A" }, diff --git a/src/core/group.ts b/src/core/group.ts index b2e57695..502627ac 100644 --- a/src/core/group.ts +++ b/src/core/group.ts @@ -80,6 +80,7 @@ export let groupChoices = ( if ( choice[recentKey] && !choice.pass && + choice.group !== "Favorite" && !( typeof choice?.recent === "boolean" && choice?.recent === false diff --git a/src/globals/custom.test.ts b/src/globals/custom.test.ts index b8a3b323..bf3d3d87 100644 --- a/src/globals/custom.test.ts +++ b/src/globals/custom.test.ts @@ -1,8 +1,8 @@ import ava from "ava" import "../core/utils.js" import tmp from "tmp-promise" -import { randomUUID } from "crypto" -import path from "path" +import { randomUUID } from "node:crypto" +import path from "node:path" import { ensureDir } from "fs-extra" import { kenvPath, kitPath } from "../core/utils.js" @@ -10,12 +10,17 @@ import { kenvPath, kitPath } from "../core/utils.js" await tmp.withDir(async (dir) => { process.env.KENV = dir.path process.env.KIT_CONTEXT = "workflow" + + // Create the base directory first + await ensureDir(dir.path) + // Then set KENV to the .kenv subdirectory process.env.KENV = path.resolve(dir.path, ".kenv") ava.beforeEach(async (t) => { global.kitScript = `${randomUUID()}.js` global.__kitDbMap = new Map() + // Create directories after ensuring base directory exists await ensureDir(kenvPath()) await ensureDir(kitPath()) diff --git a/src/main/scriptlet.ts b/src/main/scriptlet.ts index 2a11d731..1f4e3c5f 100644 --- a/src/main/scriptlet.ts +++ b/src/main/scriptlet.ts @@ -101,6 +101,7 @@ export let runScriptlet = async ( formattedFocusedScriptlet.scriptlet = formattedScriptlet switch (formattedFocusedScriptlet.tool) { + case "": case "kit": case "ts": case "js": {