Problem: reload_spec.lua called io.open() without nil checks, causing
need-check-nil warnings. Adding ${3rd}/busted and ${3rd}/luassert to
workspace.library caused lua-language-server 3.7.4 to run diagnostics
on its own bundled meta files, surfacing pre-existing cast-local-type
bugs in luassert's annotations that are not ours to fix.
Solution: use assert(io.open(...)) in reload_spec.lua to satisfy the
nil check. Remove busted/luassert library paths from .luarc.json since
they only benefit spec/ which is not type-checked in CI. Narrow the
lua-language-server check in scripts/ci.sh to lua/ to match CI.
58 lines
1.4 KiB
Lua
58 lines
1.4 KiB
Lua
describe('reload', function()
|
|
local reload
|
|
|
|
before_each(function()
|
|
package.loaded['preview.reload'] = nil
|
|
reload = require('preview.reload')
|
|
end)
|
|
|
|
after_each(function()
|
|
reload.stop()
|
|
end)
|
|
|
|
describe('inject', function()
|
|
it('injects script before </body>', function()
|
|
local path = os.tmpname()
|
|
local f = assert(io.open(path, 'w'))
|
|
f:write('<html><body><p>hello</p></body></html>')
|
|
f:close()
|
|
|
|
reload.inject(path)
|
|
|
|
local fr = assert(io.open(path, 'r'))
|
|
local content = fr:read('*a')
|
|
fr:close()
|
|
os.remove(path)
|
|
|
|
assert.is_truthy(content:find('EventSource', 1, true))
|
|
local script_pos = content:find('EventSource', 1, true)
|
|
local body_pos = content:find('</body>', 1, true)
|
|
assert.is_truthy(body_pos)
|
|
assert.is_true(script_pos < body_pos)
|
|
end)
|
|
|
|
it('appends script when no </body>', function()
|
|
local path = os.tmpname()
|
|
local f = assert(io.open(path, 'w'))
|
|
f:write('<html><p>hello</p></html>')
|
|
f:close()
|
|
|
|
reload.inject(path)
|
|
|
|
local fr = assert(io.open(path, 'r'))
|
|
local content = fr:read('*a')
|
|
fr:close()
|
|
os.remove(path)
|
|
|
|
assert.is_truthy(content:find('EventSource', 1, true))
|
|
end)
|
|
end)
|
|
|
|
describe('broadcast', function()
|
|
it('does not error with no clients', function()
|
|
assert.has_no.errors(function()
|
|
reload.broadcast()
|
|
end)
|
|
end)
|
|
end)
|
|
end)
|