Skip to content

Commit

Permalink
fix(test): fix tmp-promise for custom. new scriptlet accept name. rec…
Browse files Browse the repository at this point in the history
…ent group ignore favorite
  • Loading branch information
johnlindquist committed Dec 4, 2024
1 parent 3bd9167 commit e685e29
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/cli/new-scriptlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() !== "") {
Expand All @@ -23,9 +27,9 @@ if (arg?.pass) {

await appendFile(
scriptletsPath,
`${whitespace}## ${arg?.pass}
`${whitespace}## ${name}
\`\`\`
\`\`\`ts
\`\`\`
`
Expand Down
20 changes: 20 additions & 0 deletions src/core/group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions src/core/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export let groupChoices = (
if (
choice[recentKey] &&
!choice.pass &&
choice.group !== "Favorite" &&
!(
typeof choice?.recent === "boolean" &&
choice?.recent === false
Expand Down
9 changes: 7 additions & 2 deletions src/globals/custom.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
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"

// biome-ignore lint/suspicious/useAwait: <explanation>
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())

Expand Down
1 change: 1 addition & 0 deletions src/main/scriptlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export let runScriptlet = async (
formattedFocusedScriptlet.scriptlet = formattedScriptlet

switch (formattedFocusedScriptlet.tool) {
case "":
case "kit":
case "ts":
case "js": {
Expand Down

0 comments on commit e685e29

Please sign in to comment.