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