-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathintegration.test.ts
153 lines (132 loc) · 4.01 KB
/
integration.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import * as cp from 'node:child_process';
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as http from 'node:http';
import expect from 'expect';
import * as jestMock from 'jest-mock';
//
//
// TODO: The old rplugin design is deprecated and NOT supported.
// This file will be deleted.
//
//
import { NeovimClient, attach, findNvim } from 'neovim';
describe.skip('Node host (OLD, DELETE ME)', () => {
const testdir = process.cwd();
let proc: cp.ChildProcessWithoutNullStreams;
let args;
let nvim: NeovimClient;
before(async () => {
const plugdir = path.resolve(__dirname);
const nvimrc = path.join(plugdir, 'nvimrc');
args = [
'-u',
nvimrc,
'--headless',
'-i',
'NONE',
'-c',
'UpdateRemotePlugins',
'-c',
'q!',
];
const integrationDir = path.resolve(plugdir, '..', '..', 'example-plugin');
process.chdir(plugdir);
fs.writeFileSync(
nvimrc,
`set rtp+=${integrationDir}
let g:node_host_prog = '${path.resolve(plugdir, '../../neovim/bin/cli')}'
`
);
const minVersion = '0.9.5';
const nvimInfo = findNvim({ minVersion });
const nvimPath = nvimInfo.matches[0]?.path;
if (!nvimPath) {
throw new Error(`nvim ${minVersion} not found`);
}
cp.spawnSync(nvimPath, args);
proc = cp.spawn(
nvimPath,
['-u', nvimrc, '-i', 'NONE', '--headless', '--embed', '-n'],
{}
);
nvim = attach({ proc });
});
after(() => {
process.chdir(testdir);
nvim.quit();
if (proc && proc.connected) {
proc.disconnect();
}
});
beforeEach(() => {});
afterEach(() => {});
// it.skip('should return specs', async done => {
// const proc = cp.spawn('nvim', args.concat(['--embed']));
// const nvim = attach({ proc });
// nvim.command('UpdateRemotePlugins');
// done();
// });
it('console.log is monkey-patched to logger.info #329', async () => {
const spy = jestMock.spyOn(nvim.logger, 'info');
console.log('log message');
expect(spy).toHaveBeenCalledWith('log message');
// Still alive?
expect(await nvim.eval('1+1')).toEqual(2);
});
it('can run a command from plugin', async () => {
await nvim.command('JSHostTestCmd');
const line = await nvim.line;
expect(line).toEqual('A line, for your troubles');
});
it('can catch thrown errors from plugin', async () => {
try {
await nvim.command('JSHostTestCmd canhazresponse?');
// Below should not be evaluated because above throws
expect(true).toEqual(false);
} catch (err) {
expect(err).toBeInstanceOf(Error);
}
});
it('can call a function from plugin', async () => {
const result = await nvim.callFunction('Func', []);
expect(result).toEqual('Funcy ');
});
it('can call a function from plugin with args', async () => {
const result = await nvim.callFunction('Func', ['args']);
expect(result).toEqual('Funcy args');
});
it.skip('can call a function from plugin with args', async () => {
await nvim.command('e! nvimrc');
});
it('spawns a child host if $NVIM_NODE_HOST_DEBUG is set', done => {
const childHost = cp.spawn(
process.execPath,
[path.join(__dirname, '..', '..', 'neovim', 'bin', 'cli.js')],
{ env: { NVIM_NODE_HOST_DEBUG: 'TRUE' }, stdio: 'ignore' }
);
setTimeout(() => {
http.get('http://127.0.0.1:9229/json/list', res => {
let rawData = '';
res.on('data', chunk => {
rawData = rawData + chunk;
});
res.on('end', () => {
try {
const debugData = JSON.parse(rawData);
childHost.kill();
expect(Array.isArray(debugData) && debugData.length).toBeTruthy();
expect(debugData[0].webSocketDebuggerUrl).toMatch(
'ws://127.0.0.1:9229'
);
done();
} catch (e: any) {
// eslint-disable-next-line no-console
console.error(e.message);
throw e;
}
});
});
}, 500);
});
});