neovim/test/functional/preload.lua
bfredl 942f26279d fix(tests): only get the color map once, even for multiple test files
Problem: test/functional/ui/screen.lua would be reloaded for each
*_spec.lua file, which causes an extra nvim session to be started
to get the color map each time.

solution: Mark screen.lua as a preloaded file, but defer the
loading of the color map to the first time Screen object is initialised.
2022-11-27 11:51:10 +01:00

42 lines
1.1 KiB
Lua

-- Modules loaded here will NOT be cleared and reloaded by Busted.
-- Busted started doing this to help provide more isolation. See issue #62
-- for more information about this.
local helpers = require('test.functional.helpers')(nil)
local screen = require('test.functional.ui.screen')
local busted = require("busted")
local is_os = helpers.is_os
if is_os('win') then
local ffi = require('ffi')
ffi.cdef[[
typedef int errno_t;
errno_t _set_fmode(int mode);
]]
ffi.C._set_fmode(0x8000)
end
local testid = (function()
local id = 0
return (function()
id = id + 1
return id
end)
end)()
-- Global before_each. https://github.com/Olivine-Labs/busted/issues/613
local function before_each(_element, _parent)
local id = ('T%d'):format(testid())
_G._nvim_test_id = id
return nil, true
end
busted.subscribe({ 'test', 'start' },
before_each,
{
-- Ensure our --helper is handled before --output (see busted/runner.lua).
priority = 1,
-- Don't generate a test-id for skipped tests. /shrug
predicate = function (element, _, status)
return not ((element.descriptor == 'pending' or status == 'pending'))
end
})