Skip to content

Commit

Permalink
fix(test): fix jest fail
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Dec 21, 2018
1 parent 4443529 commit 813b017
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 146 deletions.
9 changes: 7 additions & 2 deletions autoload/coc/rpc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ function! coc#rpc#start_server()
if $NODE_ENV ==# 'test'
" server already started
let s:client = coc#client#create(s:name, [])
let s:client['running'] = 1
let s:client['chan_id'] = get(g:, 'coc_node_channel_id', 0)
call dictwatcheradd(g:, 'coc_node_channel_id', function('s:ChannelSet'))
return
endif
if empty(s:client)
Expand All @@ -17,10 +20,12 @@ function! coc#rpc#start_server()
call s:client['start']()
endfunction

function! coc#rpc#set_channel_id(chan_id)
function! s:ChannelSet(dict, key, val)
let chan_id = get(a:val, 'new', 0)
if empty(s:client) | return | endif
let s:client['running'] = 1
let s:client['chan_id'] = a:chan_id
let s:client['chan_id'] = chan_id
call dictwatcherdel(g:, 'coc_node_channel_id', function('s:ChannelSet'))
endfunction

function! coc#rpc#kill()
Expand Down
140 changes: 0 additions & 140 deletions bin/lspForkStart.js

This file was deleted.

3 changes: 3 additions & 0 deletions bin/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Object.defineProperty(console, 'log', {
value: () => { }
})
const attach = require('../lib/attach').default
const logger = require('../lib/util/logger')('server')
const isVim = process.env.VIM_NODE_RPC == 1
Expand Down
4 changes: 4 additions & 0 deletions jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

module.exports = async () => {
process.env.NODE_ENV = 'test'
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"globals": {
"__TEST__": true
},
"clearMocks": true,
"globalSetup": "./jest.js",
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
Expand Down
8 changes: 4 additions & 4 deletions src/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import Plugin from './plugin'
import semver from 'semver'
const logger = require('./util/logger')('attach')

export default function(opts: Attach): Plugin {
const isTest = process.env.NODE_ENV == 'test'

export default function (opts: Attach): Plugin {
const nvim: NeovimClient = attach(opts)
const plugin = new Plugin(nvim)
let initialized = false
Expand Down Expand Up @@ -54,9 +56,7 @@ export default function(opts: Attach): Plugin {
})

nvim.channelId.then(async channelId => {
if (global.hasOwnProperty('__TEST__')) {
await nvim.call('coc#rpc#set_channel_id', channelId)
}
if (isTest) nvim.command(`let g:coc_node_channel_id = ${channelId}`, true)
let json = require('../package.json')
let { major, minor, patch } = semver.parse(json.version)
nvim.setClientInfo('coc', { major, minor, patch }, 'remote', {}, {})
Expand Down

0 comments on commit 813b017

Please sign in to comment.