nodejs_spec.lua 1.7 KB

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