Created
June 19, 2025 22:03
-
-
Save michel/3a8536c84c606e08e668889a08ca9f3e to your computer and use it in GitHub Desktop.
vim-test/vim-test bun adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " put in .config/nvim/autoload/test/javascript/bun.vim | |
| " add to vim config: | |
| " vim.cmd([[ | |
| " let test#custom_runners = {'javascript': ['bun']} | |
| " ]]) | |
| if !exists('g:test#javascript#bun#file_pattern') | |
| let g:test#javascript#bun#file_pattern = '\v(__tests__/.*|(spec|test))\.(js|jsx|coffee|ts|tsx)$' | |
| endif | |
| function! test#javascript#bun#test_file(file) abort | |
| if a:file =~# g:test#javascript#bun#file_pattern | |
| return filereadable(findfile('bun.lockb', fnamemodify(a:file, ':p:h') . ';')) | |
| endif | |
| endfunction | |
| function! test#javascript#bun#build_position(type, position) abort | |
| let file = escape(a:position['file'], '()[]') | |
| if a:type ==# 'nearest' | |
| let name = s:nearest_test(a:position) | |
| if !empty(name) | |
| let name = '-t '.shellescape(escape(name, '()[]'), 1) | |
| endif | |
| return ['--runTestsByPath', name, '--', file] | |
| elseif a:type ==# 'file' | |
| return ['--runTestsByPath', '--', file] | |
| else | |
| return [] | |
| endif | |
| endfunction | |
| let s:yarn_command = '\<yarn\>' | |
| function! test#javascript#bun#build_args(args) abort | |
| if exists('g:test#javascript#bun#executable') | |
| \ && g:test#javascript#bun#executable =~# s:yarn_command | |
| return filter(a:args, 'v:val != "--"') | |
| else | |
| return a:args | |
| endif | |
| endfunction | |
| function! test#javascript#bun#executable() abort | |
| if filereadable('/opt/homebrew/bin/bun') | |
| return '/opt/homebrew/bin/bun test' | |
| else | |
| return 'bun test' | |
| endif | |
| endfunction | |
| function! s:nearest_test(position) abort | |
| let name = test#base#nearest_test(a:position, g:test#javascript#patterns) | |
| return (len(name['namespace']) ? '^' : '') . | |
| \ test#base#escape_regex(join(name['namespace'] + name['test'])) . | |
| \ (len(name['test']) ? '$' : '') | |
| endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment