Skip to content

Commit de80d38

Browse files
authored
fix(test): stop runner spinner on exit with noice (#366) (#370)
1 parent b744749 commit de80d38

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

lua/cmake-tools/utils.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ function utils.run(cmd, env_script, env, args, cwd, runner, callback)
212212
end
213213

214214
utils.get_runner(runner.name).run(cmd, env_script, env, args, cwd, runner.opts, function(code)
215+
ntfy:stopSpinner()
215216
local msg = "Exited with code " .. code
216217
local icon = ""
217218
local level = nil -- use the previously defined level

tests/utils_run_spec.lua

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
local stub_notification
2+
local stub_runner
3+
4+
local function clear_modules()
5+
package.loaded["cmake-tools.utils"] = nil
6+
package.loaded["cmake-tools.notification"] = nil
7+
package.loaded["cmake-tools.runners"] = nil
8+
package.loaded["cmake-tools.executors"] = nil
9+
end
10+
11+
describe("utils.run", function()
12+
before_each(function()
13+
clear_modules()
14+
15+
stub_notification = {
16+
enabled = true,
17+
stop_calls = 0,
18+
start_calls = 0,
19+
notify_calls = {},
20+
notify = function(self, msg, level, opts)
21+
table.insert(self.notify_calls, { msg = msg, level = level, opts = opts })
22+
end,
23+
startSpinner = function(self)
24+
self.start_calls = self.start_calls + 1
25+
end,
26+
stopSpinner = function(self)
27+
self.stop_calls = self.stop_calls + 1
28+
end,
29+
}
30+
31+
package.loaded["cmake-tools.notification"] = {
32+
new = function(_)
33+
return stub_notification
34+
end,
35+
}
36+
37+
stub_runner = {
38+
run = function(_, _, _, _, _, _, on_exit, on_output)
39+
on_output("[ 50%] Running test", nil)
40+
on_exit(0)
41+
end,
42+
}
43+
44+
package.loaded["cmake-tools.runners"] = {
45+
fake = stub_runner,
46+
}
47+
48+
package.loaded["cmake-tools.executors"] = {
49+
fake = {},
50+
}
51+
end)
52+
53+
after_each(function()
54+
clear_modules()
55+
end)
56+
57+
it("stops spinner when run completes", function()
58+
local utils = require("cmake-tools.utils")
59+
60+
utils.run("ctest", "", {}, {}, vim.loop.cwd(), { name = "fake", opts = {} }, nil)
61+
62+
assert.equals(1, stub_notification.start_calls)
63+
assert.equals(1, stub_notification.stop_calls)
64+
end)
65+
end)

0 commit comments

Comments
 (0)