-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add progress handle tests and ci workflow (#193)
* ci: add progress handle tests and ci workflow * chore(ci): bump checkout version to checkout@4 * ci: also run on macOS closes #188 --------- Co-authored-by: j-hui <[email protected]>
- Loading branch information
Showing
5 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
pull_request: | ||
branches: ['main'] | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
nvim-version: ['stable', 'nightly'] | ||
os: [ubuntu-latest, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
name: Run Tests | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install Neovim | ||
uses: rhysd/action-setup-vim@v1 | ||
with: | ||
neovim: true | ||
version: ${{ matrix.nvim-version }} | ||
|
||
- name: Run tests | ||
run: nvim --clean --headless -u tests/minimal_init.lua -c "PlenaryBustedDirectory tests/ { minimal_init = 'tests/minimal_init.lua' }" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
local fidget = require("fidget") | ||
local notif = require("fidget.notification") | ||
local handle = require("fidget.progress.handle") | ||
|
||
local eq = assert.are.same | ||
local is_nil = assert.is_nil | ||
|
||
describe("progress handle", function() | ||
before_each(function() | ||
require("fidget").setup({}) | ||
notif.clear() | ||
notif.window.close() | ||
end) | ||
|
||
it("should create a handle", function() | ||
local h = handle.create({ | ||
title = "test", | ||
message = "test message", | ||
}) | ||
assert(h ~= nil) | ||
|
||
eq(h.title, "test") | ||
eq(h.message, "test message") | ||
eq(h.done, false) | ||
|
||
-- defaults | ||
eq(h.lsp_client, { name = "fidget" }) | ||
eq(h.cancellable, true) | ||
end) | ||
|
||
it("should update when report() is called", function() | ||
local h = handle.create({ | ||
title = "test", | ||
message = "test message", | ||
}) | ||
h:report({ | ||
message = "new message", | ||
percentage = 50, | ||
}) | ||
eq(h.message, "new message") | ||
eq(h.percentage, 50) | ||
end) | ||
|
||
it("should complete when finish() is called", function() | ||
local h = handle.create({ | ||
title = "test", | ||
message = "test message", | ||
}) | ||
h:finish() | ||
eq(h.done, true) | ||
is_nil(h.percentage) | ||
end) | ||
|
||
it("should set percentage to 100 when complete", function() | ||
local h = handle.create({ | ||
title = "test", | ||
message = "test message", | ||
percentage = 0, | ||
}) | ||
eq(h.percentage, 0) | ||
eq(h.done, false) | ||
h:report({ | ||
percentage = 50, | ||
}) | ||
eq(h.percentage, 50) | ||
eq(h.done, false) | ||
h:finish() | ||
eq(h.percentage, 100) | ||
eq(h.done, true) | ||
end) | ||
|
||
it("should *not* set percentage when cancel() is called", function() | ||
local h = handle.create({ | ||
title = "test", | ||
message = "test message", | ||
percentage = 0, | ||
}) | ||
h:report({ | ||
percentage = 40, | ||
}) | ||
h:cancel() | ||
eq(h.done, true) | ||
eq(h.percentage, 40) | ||
end) | ||
|
||
it("should *not* initialize percentage when not provided", function() | ||
local h = handle.create({ | ||
title = "test", | ||
message = "test message", | ||
}) | ||
eq(h.percentage, nil) | ||
eq(h.done, false) | ||
h:finish() | ||
eq(h.percentage, nil) | ||
eq(h.done, true) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
local deps = { | ||
"nvim-lua/plenary.nvim", | ||
} | ||
|
||
local uv = vim.uv or vim.loop | ||
|
||
local tmp = uv.os_tmpdir() | ||
local base = tmp .. "/fidget-test/" | ||
|
||
local waiting = 0 | ||
|
||
for _, dep in ipairs(deps) do | ||
local path = base .. dep:gsub("/", "-") | ||
local stat = vim.loop.fs_stat(path) | ||
if stat == nil or stat.type ~= "directory" then | ||
vim.fn.mkdir(path, "p") | ||
waiting = waiting + 1 | ||
uv.spawn("git", { | ||
args = { "clone", "https://github.com/" .. dep, path }, | ||
}, function() | ||
waiting = waiting - 1 | ||
end) | ||
end | ||
vim.opt.rtp:prepend(path) | ||
end | ||
|
||
vim.wait(10000, function() | ||
return waiting == 0 | ||
end) | ||
|
||
vim.opt.rtp:prepend(uv.cwd()) | ||
|
||
require("plenary.busted") |