Skip to content

Commit

Permalink
ci: add progress handle tests and ci workflow (#193)
Browse files Browse the repository at this point in the history
* 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
willothy and j-hui authored Feb 7, 2024
1 parent 824b53f commit ad8873c
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
name: Generate Fidget documentation
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install luajit
run: sudo apt install -y luajit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/luarocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
luarocks-upload:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to count the commits
- name: Get Version
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/tests.yml
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' }"
97 changes: 97 additions & 0 deletions tests/handle_spec.lua
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)
33 changes: 33 additions & 0 deletions tests/minimal_init.lua
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")

0 comments on commit ad8873c

Please sign in to comment.