diff --git a/packages/neovim/src/api/Neovim.test.ts b/packages/neovim/src/api/Neovim.test.ts index c25d8a2f..2227bc77 100644 --- a/packages/neovim/src/api/Neovim.test.ts +++ b/packages/neovim/src/api/Neovim.test.ts @@ -1,5 +1,6 @@ /* eslint-env jest */ import * as path from 'node:path'; +import assert from 'node:assert'; import * as testUtil from '../testUtil'; describe('Neovim API', () => { @@ -25,7 +26,7 @@ describe('Neovim API', () => { // switch buffers [nvim.buffer] = buffers; - expect(await nvim.buffer.name).toMatch(/hello\.txt$/); + expect(await (await nvim.buffer).name).toMatch(/hello\.txt$/); }); it('can list runtimepaths', async () => { @@ -218,7 +219,7 @@ describe('Neovim API', () => { const numWindows = (await nvim.windows).length; const buffer = await nvim.createBuffer(false, false); expect(await nvim.buffers).toHaveLength(numBuffers + 1); - + assert(typeof buffer !== 'number'); const floatingWindow = await nvim.openWindow(buffer, true, { relative: 'editor', row: 5, @@ -227,7 +228,7 @@ describe('Neovim API', () => { height: 50, }); expect(await nvim.windows).toHaveLength(numWindows + 1); - + assert(typeof floatingWindow !== 'number'); await nvim.windowClose(floatingWindow, true); expect(await nvim.windows).toHaveLength(numWindows); }); @@ -235,7 +236,7 @@ describe('Neovim API', () => { it('resizes a window', async () => { const numWindows = (await nvim.windows).length; const buffer = await nvim.createBuffer(false, false); - + assert(typeof buffer !== 'number'); const floatingWindow = await nvim.openWindow(buffer, true, { relative: 'editor', row: 5, @@ -243,6 +244,7 @@ describe('Neovim API', () => { width: 10, height: 10, }); + assert(typeof floatingWindow !== 'number'); expect(await nvim.windows).toHaveLength(numWindows + 1); expect(await floatingWindow.height).toBe(10); expect(await floatingWindow.width).toBe(10); diff --git a/packages/neovim/src/api/Neovim.ts b/packages/neovim/src/api/Neovim.ts index 5929a6b5..8933f9b5 100644 --- a/packages/neovim/src/api/Neovim.ts +++ b/packages/neovim/src/api/Neovim.ts @@ -169,7 +169,7 @@ export class Neovim extends BaseApi { /** * Sets the current buffer */ - set buffer(buffer: AsyncBuffer) { + set buffer(buffer: AsyncBuffer | Buffer) { this.request(`${this.prefix}set_current_buf`, [buffer]); } @@ -232,7 +232,7 @@ export class Neovim extends BaseApi { /** * Sets the current tabpage */ - set tabpage(tabpage: AsyncTabpage) { + set tabpage(tabpage: AsyncTabpage | Tabpage) { this.request(`${this.prefix}set_current_tabpage`, [tabpage]); } @@ -259,7 +259,7 @@ export class Neovim extends BaseApi { * * @param win Window handle */ - set window(win: AsyncWindow) { + set window(win: AsyncWindow | Window) { if (win instanceof Window) this.setWindow(win); else win.then(win => this.setWindow(win)); } diff --git a/packages/neovim/src/api/Tabpage.test.ts b/packages/neovim/src/api/Tabpage.test.ts index 169bfcb9..15f5ec6d 100644 --- a/packages/neovim/src/api/Tabpage.test.ts +++ b/packages/neovim/src/api/Tabpage.test.ts @@ -1,5 +1,6 @@ /* eslint-env jest */ import * as testUtil from '../testUtil'; +import type { Tabpage } from './Tabpage'; describe('Tabpage API', () => { let nvim: ReturnType[1]; @@ -18,7 +19,7 @@ describe('Tabpage API', () => { }); describe('Normal API calls', () => { - let tabpage; + let tabpage: Tabpage; beforeEach(async () => { tabpage = await nvim.tabpage; @@ -68,10 +69,10 @@ describe('Tabpage API', () => { it('logs an error when calling `getOption`', () => { const spy = jest.spyOn(tabpage.logger, 'error'); - tabpage.getOption('option'); + tabpage.getOption(); expect(spy.mock.calls.length).toBe(1); - tabpage.setOption('option', 'value'); + tabpage.setOption(); expect(spy.mock.calls.length).toBe(2); spy.mockClear(); }); diff --git a/packages/neovim/src/api/Window.test.ts b/packages/neovim/src/api/Window.test.ts index ff272002..f59e2562 100644 --- a/packages/neovim/src/api/Window.test.ts +++ b/packages/neovim/src/api/Window.test.ts @@ -1,5 +1,7 @@ /* eslint-env jest */ +import assert from 'node:assert'; import * as testUtil from '../testUtil'; +import type { Window } from './Window'; describe('Window API', () => { let nvim: ReturnType[1]; @@ -24,7 +26,7 @@ describe('Window API', () => { }); describe('Normal API calls', () => { - let win; + let win: Window; beforeEach(async () => { win = await nvim.window; @@ -51,7 +53,7 @@ describe('Window API', () => { }); it('has same cursor position after appending a line to buffer', async () => { - await win.buffer.append(['test']); + await (await win.buffer).append(['test']); expect(await win.buffer.lines).toEqual(['', 'test']); expect(await win.cursor).toEqual([1, 0]); }); @@ -94,7 +96,7 @@ describe('Window API', () => { }); it('has the right window positions in display cells', async () => { - let windows; + let windows: Awaited; nvim.command('vsplit'); // XXX If we re-use `win` without a new call to `nvim.window`, @@ -126,6 +128,7 @@ describe('Window API', () => { expect(await win.getOption('list')).toBe(true); win.setOption('list', false); expect(await win.getOption('list')).toBe(false); + assert(list !== undefined); // Restore option win.setOption('list', list); expect(await win.getOption('list')).toBe(list); @@ -167,7 +170,7 @@ describe('Window API', () => { }); it.skip('gets current lines in buffer', async () => { - expect(await nvim.window.buffer.lines).toEqual(['test']); + expect(await (await nvim.window.buffer).lines).toEqual(['test']); }); }); }); diff --git a/packages/neovim/src/host/NvimPlugin.test.ts b/packages/neovim/src/host/NvimPlugin.test.ts index d6174fae..672f239b 100644 --- a/packages/neovim/src/host/NvimPlugin.test.ts +++ b/packages/neovim/src/host/NvimPlugin.test.ts @@ -128,6 +128,7 @@ describe('NvimPlugin', () => { () => {}, getFakeNvimClient() ); + // @ts-expect-error Intentionally passing empty array for command arguments. plugin.registerCommand('MyCommand', [], {}); expect(Object.keys(plugin.commands)).toHaveLength(0); }); @@ -175,7 +176,7 @@ describe('NvimPlugin', () => { () => {}, getFakeNvimClient() ); - const fn = arg => arg; + const fn = (arg: any) => arg; plugin.registerAutocmd('BufWritePre', fn, { pattern: '*', sync: true }); plugin.registerCommand('MyCommand', fn, { sync: true }); diff --git a/packages/neovim/src/plugin/plugin.test.ts b/packages/neovim/src/plugin/plugin.test.ts index 291fd8ea..6ff003a5 100644 --- a/packages/neovim/src/plugin/plugin.test.ts +++ b/packages/neovim/src/plugin/plugin.test.ts @@ -6,7 +6,7 @@ import { command as Command } from './command'; import { autocmd as Autocmd } from './autocmd'; import { getFakeNvimClient } from '../testUtil'; -const instantiateOrRun = (Fn, ...args) => { +const instantiateOrRun = (Fn: ReturnType, ...args: any[]) => { try { return new Fn(...args); } catch (err) { @@ -36,13 +36,16 @@ describe('Plugin class decorator', () => { }); it('decorates class methods', () => { - class MyClass {} - MyClass.prototype.testF = () => {}; - MyClass.prototype.testC = () => {}; - MyClass.prototype.testA = () => {}; + class MyClass { + testF() {} + + testC() {} + + testA() {} + } // This is how (closeish) babel applies decorators - FunctionDecorator('TestF', { eval: 'test', range: 'test' })( + FunctionDecorator('TestF', { eval: 'test', range: [1, 10] })( MyClass.prototype, 'testF' ); @@ -85,15 +88,18 @@ describe('Plugin class decorator', () => { expect(pluginObject.registerFunction).toHaveBeenCalledWith( 'TestF', [instance, MyClass.prototype.testF], - { sync: false, eval: 'test', range: 'test' } + { sync: false, eval: 'test', range: [1, 10] } ); }); it('generates specs from decorated methods', () => { - class MyClass {} - MyClass.prototype.testF = () => {}; - MyClass.prototype.testC = () => {}; - MyClass.prototype.testA = () => {}; + class MyClass { + testF() {} + + testC() {} + + testA() {} + } // This is how (closeish) babel applies decorators FunctionDecorator('TestF')(MyClass.prototype, 'testF'); diff --git a/packages/neovim/tsconfig.json b/packages/neovim/tsconfig.json index 94e89d26..146c85e3 100644 --- a/packages/neovim/tsconfig.json +++ b/packages/neovim/tsconfig.json @@ -3,6 +3,6 @@ "compilerOptions": { "outDir": "./lib" }, - "include": ["src", "**/api/Buffer.test.ts"], - "exclude": ["node_modules", "__tests__", "**/*.test.ts", "examples", "lib"] + "include": ["src"], + "exclude": ["node_modules", "examples", "lib"] }