robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.8 KiB73 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, teardown, pending =
5  t.describe, t.it, t.before_each, t.teardown, t.pending
6local eq, clear = t.eq, n.clear
7local missing_provider = n.missing_provider
8local command = n.command
9local write_file = t.write_file
10local eval = n.eval
11local retry = t.retry
12
13do
14  clear()
15  local reason = missing_provider('node')
16  if reason then
17    pending(
18      string.format('Missing nodejs host, or nodejs version is too old (%s)', reason),
19      function() end
20    )
21    return
22  end
23end
24
25before_each(function()
26  clear()
27end)
28
29describe('nodejs host', function()
30  teardown(function()
31    os.remove('Xtest-nodejs-hello.js')
32    os.remove('Xtest-nodejs-hello-plugin.js')
33  end)
34
35  it('works', function()
36    local fname = 'Xtest-nodejs-hello.js'
37    write_file(
38      fname,
39      [[
40      const neovim = require('neovim');
41      const nvim = neovim.attach({socket: process.env.NVIM});
42      nvim.command('let g:job_out = "hello"');
43    ]]
44    )
45    command('let g:job_id = jobstart(["node", "' .. fname .. '"])')
46    retry(nil, 3000, function()
47      eq('hello', eval('g:job_out'))
48    end)
49  end)
50  it('plugin works', function()
51    local fname = 'Xtest-nodejs-hello-plugin.js'
52    write_file(
53      fname,
54      [[
55      const neovim = require('neovim');
56      const nvim = neovim.attach({socket: process.env.NVIM});
57
58      class TestPlugin {
59        hello() {
60          this.nvim.command('let g:job_out = "hello-plugin"');
61        }
62      }
63      const PluginClass = neovim.Plugin(TestPlugin);
64      const plugin = new neovim.NvimPlugin(null, PluginClass, nvim);
65      plugin.instance.hello();
66    ]]
67    )
68    command('let g:job_id = jobstart(["node", "' .. fname .. '"])')
69    retry(nil, 3000, function()
70      eq('hello-plugin', eval('g:job_out'))
71    end)
72  end)
73end)