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