mirror of
https://github.com/neovim/neovim.git
synced 2026-03-01 06:38:26 +00:00
Merge #7706 'ci: nodejs acceptance-test'
This commit is contained in:
@@ -9,6 +9,8 @@ matrix:
|
||||
allow_failures:
|
||||
- configuration: MINGW_64-gcov
|
||||
install: []
|
||||
before_build:
|
||||
- ps: Install-Product node 8
|
||||
build_script:
|
||||
- call ci\build.bat
|
||||
cache:
|
||||
|
||||
@@ -37,3 +37,15 @@ else
|
||||
# https://github.com/travis-ci/travis-ci/issues/8363
|
||||
pip3 -q install --user --upgrade pip || true
|
||||
fi
|
||||
|
||||
if [[ "${TRAVIS_OS_NAME}" == linux ]]; then
|
||||
echo "Install node (LTS)"
|
||||
|
||||
if [ ! -f ~/.nvm/nvm.sh ]; then
|
||||
curl -o ~/.nvm/nvm.sh https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh
|
||||
fi
|
||||
|
||||
source ~/.nvm/nvm.sh
|
||||
nvm install --lts
|
||||
nvm use --lts
|
||||
fi
|
||||
|
||||
@@ -37,6 +37,9 @@ set PATH=C:\Ruby24\bin;%PATH%
|
||||
cmd /c gem.cmd install neovim || goto :error
|
||||
where.exe neovim-ruby-host.bat || goto :error
|
||||
|
||||
cmd /c npm.cmd install -g neovim || goto :error
|
||||
where.exe neovim-node-host.cmd || goto :error
|
||||
|
||||
mkdir .deps
|
||||
cd .deps
|
||||
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo ..\third-party\ || goto :error
|
||||
|
||||
@@ -23,3 +23,8 @@ CC=cc pip3 -q install --user --upgrade neovim || true
|
||||
|
||||
echo "Install neovim RubyGem."
|
||||
gem install --no-document --version ">= 0.2.0" neovim
|
||||
|
||||
if [[ "${TRAVIS_OS_NAME}" == linux ]]; then
|
||||
echo "Install neovim npm package"
|
||||
npm install -g neovim
|
||||
fi
|
||||
|
||||
@@ -488,7 +488,7 @@ function! s:check_ruby() abort
|
||||
endfunction
|
||||
|
||||
function! s:check_node() abort
|
||||
call health#report_start('Node provider (optional)')
|
||||
call health#report_start('Node.js provider (optional)')
|
||||
|
||||
let loaded_var = 'g:loaded_node_provider'
|
||||
if exists(loaded_var) && !exists('*provider#node#Call')
|
||||
@@ -502,7 +502,16 @@ function! s:check_node() abort
|
||||
\ ['Install Node.js and verify that `node` and `npm` commands work.'])
|
||||
return
|
||||
endif
|
||||
call health#report_info('Node: '. s:system('node -v'))
|
||||
let node_v = get(split(s:system('node -v'), "\n"), 0, '')
|
||||
call health#report_info('Node.js: '. node_v)
|
||||
if !s:shell_error && s:version_cmp(node_v[1:], '6.0.0') < 0
|
||||
call health#report_warn('Neovim node.js host does not support '.node_v)
|
||||
" Skip further checks, they are nonsense if nodejs is too old.
|
||||
return
|
||||
endif
|
||||
if !provider#node#can_inspect()
|
||||
call health#report_warn('node.js on this system does not support --inspect-brk so $NVIM_NODE_HOST_DEBUG is ignored.')
|
||||
endif
|
||||
|
||||
let host = provider#node#Detect()
|
||||
if empty(host)
|
||||
@@ -511,7 +520,7 @@ function! s:check_node() abort
|
||||
\ 'Is the npm bin directory in $PATH?'])
|
||||
return
|
||||
endif
|
||||
call health#report_info('Host: '. host)
|
||||
call health#report_info('Neovim node.js host: '. host)
|
||||
|
||||
let latest_npm_cmd = has('win32') ? 'cmd /c npm info neovim --json' : 'npm info neovim --json'
|
||||
let latest_npm = s:system(split(latest_npm_cmd))
|
||||
@@ -530,11 +539,11 @@ function! s:check_node() abort
|
||||
let latest_npm = get(get(pkg_data, 'dist-tags', {}), 'latest', 'unable to parse')
|
||||
endif
|
||||
|
||||
let current_npm_cmd = host .' --version'
|
||||
let current_npm_cmd = ['node', host, '--version']
|
||||
let current_npm = s:system(current_npm_cmd)
|
||||
if s:shell_error
|
||||
call health#report_error('Failed to run: '. current_npm_cmd,
|
||||
\ ['Report this issue with the output of: ', current_npm_cmd])
|
||||
call health#report_error('Failed to run: '. string(current_npm_cmd),
|
||||
\ ['Report this issue with the output of: ', string(current_npm_cmd)])
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -544,7 +553,7 @@ function! s:check_node() abort
|
||||
\ current_npm, latest_npm),
|
||||
\ ['Run in shell: npm update neovim'])
|
||||
else
|
||||
call health#report_ok('Latest "neovim" npm is installed: '. current_npm)
|
||||
call health#report_ok('Latest "neovim" npm package is installed: '. current_npm)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -5,11 +5,53 @@ let g:loaded_node_provider = 1
|
||||
|
||||
let s:job_opts = {'rpc': v:true, 'on_stderr': function('provider#stderr_collector')}
|
||||
|
||||
function! provider#node#Detect() abort
|
||||
return has('win32') ? exepath('neovim-node-host.cmd') : exepath('neovim-node-host')
|
||||
function! s:is_minimum_version(version, min_major, min_minor) abort
|
||||
let nodejs_version = a:version
|
||||
if !a:version
|
||||
let nodejs_version = get(split(system(['node', '-v']), "\n"), 0, '')
|
||||
if v:shell_error || nodejs_version[0] !=# 'v'
|
||||
return 0
|
||||
endif
|
||||
endif
|
||||
" [major, minor, patch]
|
||||
let v_list = !!a:version ? a:version : split(nodejs_version[1:], '\.')
|
||||
return len(v_list) == 3
|
||||
\ && ((str2nr(v_list[0]) > str2nr(a:min_major))
|
||||
\ || (str2nr(v_list[0]) == str2nr(a:min_major)
|
||||
\ && str2nr(v_list[1]) >= str2nr(a:min_minor)))
|
||||
endfunction
|
||||
|
||||
function! provider#node#Prog()
|
||||
" Support for --inspect-brk requires node 6.12+ or 7.6+ or 8+
|
||||
" Return 1 if it is supported
|
||||
" Return 0 otherwise
|
||||
function! provider#node#can_inspect() abort
|
||||
if !executable('node')
|
||||
return 0
|
||||
endif
|
||||
let ver = get(split(system(['node', '-v']), "\n"), 0, '')
|
||||
if v:shell_error || ver[0] !=# 'v'
|
||||
return 0
|
||||
endif
|
||||
return (ver[1] ==# '6' && s:is_minimum_version(ver, 6, 12))
|
||||
\ || s:is_minimum_version(ver, 7, 6)
|
||||
endfunction
|
||||
|
||||
function! provider#node#Detect() abort
|
||||
let global_modules = get(split(system('npm root -g'), "\n"), 0, '')
|
||||
if v:shell_error || !isdirectory(global_modules)
|
||||
return ''
|
||||
endif
|
||||
if !s:is_minimum_version(v:null, 6, 0)
|
||||
return ''
|
||||
endif
|
||||
let entry_point = glob(global_modules . '/neovim/bin/cli.js')
|
||||
if !filereadable(entry_point)
|
||||
return ''
|
||||
endif
|
||||
return entry_point
|
||||
endfunction
|
||||
|
||||
function! provider#node#Prog() abort
|
||||
return s:prog
|
||||
endfunction
|
||||
|
||||
@@ -19,18 +61,14 @@ function! provider#node#Require(host) abort
|
||||
return
|
||||
endif
|
||||
|
||||
if has('win32')
|
||||
let args = provider#node#Prog()
|
||||
else
|
||||
let args = ['node']
|
||||
let args = ['node']
|
||||
|
||||
if !empty($NVIM_NODE_HOST_DEBUG)
|
||||
call add(args, '--inspect-brk')
|
||||
endif
|
||||
|
||||
call add(args , provider#node#Prog())
|
||||
if !empty($NVIM_NODE_HOST_DEBUG) && provider#node#can_inspect()
|
||||
call add(args, '--inspect-brk')
|
||||
endif
|
||||
|
||||
call add(args, provider#node#Prog())
|
||||
|
||||
try
|
||||
let channel_id = jobstart(args, s:job_opts)
|
||||
if rpcrequest(channel_id, 'poll') ==# 'ok'
|
||||
@@ -49,7 +87,7 @@ function! provider#node#Require(host) abort
|
||||
throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_NODE_LOG_FILE')
|
||||
endfunction
|
||||
|
||||
function! provider#node#Call(method, args)
|
||||
function! provider#node#Call(method, args) abort
|
||||
if s:err != ''
|
||||
echoerr s:err
|
||||
return
|
||||
|
||||
@@ -11,11 +11,11 @@ let g:loaded_python_provider = 1
|
||||
|
||||
let [s:prog, s:err] = provider#pythonx#Detect(2)
|
||||
|
||||
function! provider#python#Prog()
|
||||
function! provider#python#Prog() abort
|
||||
return s:prog
|
||||
endfunction
|
||||
|
||||
function! provider#python#Error()
|
||||
function! provider#python#Error() abort
|
||||
return s:err
|
||||
endfunction
|
||||
|
||||
@@ -29,7 +29,7 @@ endif
|
||||
call remote#host#RegisterClone('legacy-python-provider', 'python')
|
||||
call remote#host#RegisterPlugin('legacy-python-provider', 'script_host.py', [])
|
||||
|
||||
function! provider#python#Call(method, args)
|
||||
function! provider#python#Call(method, args) abort
|
||||
if s:err != ''
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -11,11 +11,11 @@ let g:loaded_python3_provider = 1
|
||||
|
||||
let [s:prog, s:err] = provider#pythonx#Detect(3)
|
||||
|
||||
function! provider#python3#Prog()
|
||||
function! provider#python3#Prog() abort
|
||||
return s:prog
|
||||
endfunction
|
||||
|
||||
function! provider#python3#Error()
|
||||
function! provider#python3#Error() abort
|
||||
return s:err
|
||||
endfunction
|
||||
|
||||
@@ -29,7 +29,7 @@ endif
|
||||
call remote#host#RegisterClone('legacy-python3-provider', 'python3')
|
||||
call remote#host#RegisterPlugin('legacy-python3-provider', 'script_host.py', [])
|
||||
|
||||
function! provider#python3#Call(method, args)
|
||||
function! provider#python3#Call(method, args) abort
|
||||
if s:err != ''
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -7,7 +7,7 @@ let g:loaded_ruby_provider = 1
|
||||
let s:stderr = {}
|
||||
let s:job_opts = {'rpc': v:true}
|
||||
|
||||
function! s:job_opts.on_stderr(chan_id, data, event)
|
||||
function! s:job_opts.on_stderr(chan_id, data, event) abort
|
||||
let stderr = get(s:stderr, a:chan_id, [''])
|
||||
let last = remove(stderr, -1)
|
||||
let a:data[0] = last.a:data[0]
|
||||
@@ -23,7 +23,7 @@ function! provider#ruby#Detect() abort
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! provider#ruby#Prog()
|
||||
function! provider#ruby#Prog() abort
|
||||
return s:prog
|
||||
endfunction
|
||||
|
||||
@@ -50,7 +50,7 @@ function! provider#ruby#Require(host) abort
|
||||
throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_RUBY_LOG_FILE')
|
||||
endfunction
|
||||
|
||||
function! provider#ruby#Call(method, args)
|
||||
function! provider#ruby#Call(method, args) abort
|
||||
if s:err != ''
|
||||
echoerr s:err
|
||||
return
|
||||
|
||||
@@ -614,7 +614,7 @@ local function new_pipename()
|
||||
end
|
||||
|
||||
local function missing_provider(provider)
|
||||
if provider == 'ruby' then
|
||||
if provider == 'ruby' or provider == 'node' then
|
||||
local prog = funcs['provider#' .. provider .. '#Detect']()
|
||||
return prog == '' and (provider .. ' not detected') or false
|
||||
elseif provider == 'python' or provider == 'python3' then
|
||||
|
||||
61
test/functional/provider/nodejs_spec.lua
Normal file
61
test/functional/provider/nodejs_spec.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local eq, clear = helpers.eq, helpers.clear
|
||||
local missing_provider = helpers.missing_provider
|
||||
local command = helpers.command
|
||||
local write_file = helpers.write_file
|
||||
local eval = helpers.eval
|
||||
local retry = helpers.retry
|
||||
|
||||
do
|
||||
clear()
|
||||
if missing_provider('node') then
|
||||
pending("Missing nodejs host, or nodejs version is too old.", function()end)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
clear()
|
||||
command([[let $NODE_PATH = get(split(system('npm root -g'), "\n"), 0, '')]])
|
||||
end)
|
||||
|
||||
describe('nodejs host', function()
|
||||
teardown(function ()
|
||||
os.remove('Xtest-nodejs-hello.js')
|
||||
os.remove('Xtest-nodejs-hello-plugin.js')
|
||||
end)
|
||||
|
||||
it('works', function()
|
||||
local fname = 'Xtest-nodejs-hello.js'
|
||||
write_file(fname, [[
|
||||
const socket = process.env.NVIM_LISTEN_ADDRESS;
|
||||
const neovim = require('neovim');
|
||||
const nvim = neovim.attach({socket: socket});
|
||||
nvim.command('let g:job_out = "hello"');
|
||||
nvim.command('call jobstop(g:job_id)');
|
||||
]])
|
||||
command('let g:job_id = jobstart(["node", "'..fname..'"])')
|
||||
retry(nil, 1000, function() eq('hello', eval('g:job_out')) end)
|
||||
end)
|
||||
it('plugin works', function()
|
||||
local fname = 'Xtest-nodejs-hello-plugin.js'
|
||||
write_file(fname, [[
|
||||
const socket = process.env.NVIM_LISTEN_ADDRESS;
|
||||
const neovim = require('neovim');
|
||||
const nvim = neovim.attach({socket: socket});
|
||||
|
||||
class TestPlugin {
|
||||
hello() {
|
||||
this.nvim.command('let g:job_out = "hello-plugin"')
|
||||
}
|
||||
}
|
||||
|
||||
const PluginClass = neovim.Plugin(TestPlugin);
|
||||
const plugin = new PluginClass(nvim);
|
||||
plugin.hello();
|
||||
nvim.command('call jobstop(g:job_id)');
|
||||
]])
|
||||
command('let g:job_id = jobstart(["node", "'..fname..'"])')
|
||||
retry(nil, 1000, function() eq('hello-plugin', eval('g:job_out')) end)
|
||||
end)
|
||||
end)
|
||||
@@ -15,9 +15,7 @@ local missing_provider = helpers.missing_provider
|
||||
do
|
||||
clear()
|
||||
if missing_provider('ruby') then
|
||||
pending(
|
||||
"Cannot find the neovim RubyGem. Try :checkhealth",
|
||||
function() end)
|
||||
pending("Missing neovim RubyGem.", function() end)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user