Skip to content

Commit

Permalink
Fix empty listing
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthomas23 committed May 30, 2024
1 parent d87133d commit 9ee609b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/commands/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export class LsCommand extends Command<LsOptions> {

}

const width = context.env_number("COLUMNS")
const output = _toColumns(filenames, width)
await context.stdout.write(output) // How to deal with newlines?
if (filenames.length > 0) {
const width = context.env_number("COLUMNS")
const output = _toColumns(filenames, width)
await context.stdout.write(output) // How to deal with newlines?
}
return 0
}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/commands/ls.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { ContentsManagerMock } from "@jupyterlab/services/lib/testutils"

import { file_system_setup } from "../file_system_setup"

import { CommandRegistry } from "../../src/command_registry"
import { Context } from "../../src/context"
import { ConsoleOutput } from "../../src/io/console_output"
import { JupyterFileSystem } from "../../src/jupyter_file_system"

describe("ls command", () => {
it.each(["jupyter"])
Expand Down Expand Up @@ -38,4 +41,20 @@ describe("ls command", () => {
expect(spy).toHaveBeenCalledWith("file2\r\n")
spy.mockRestore()
})

it("should handle empty listing", async () => {
const fs = new JupyterFileSystem(new ContentsManagerMock())
const stdout = new ConsoleOutput()
const context = new Context([], fs, stdout)

const spy = jest.spyOn(console, 'log').mockImplementation(() => {})

const cmd = CommandRegistry.instance().create("ls")
expect(cmd).not.toBeNull()
const exit_code = await cmd!.run(context)
expect(exit_code).toBe(0)

expect(spy).toHaveBeenCalledTimes(0)
spy.mockRestore()
})
})

0 comments on commit 9ee609b

Please sign in to comment.