Giter VIP home page Giter VIP logo

neotest-jest's Introduction

neotest-jest

build

This plugin provides a jest adapter for the Neotest framework. It is currently a work in progress.

Installation

Using packer:

use({
  'nvim-neotest/neotest',
  requires = {
    ...,
    'haydenmeade/neotest-jest',
  }
  config = function()
    require('neotest').setup({
      ...,
      adapters = {
        require('neotest-jest')({
          jestCommand = "npm test --",
          jestConfigFile = "custom.jest.config.ts",
          env = { CI = true },
          cwd = function(path)
            return vim.fn.getcwd()
          end,
        }),
      }
    })
  end
})

Make sure you have the appropriate treesitter language parsers installed otherwise no tests will be found:

:TSInstall javascript

Usage

See neotest's documentation for more information on how to run tests.

Running tests in watch mode

jest allows to run your tests in watch mode. To run test in this mode you either can enable it globally in the setup:

require('neotest').setup({
  ...,
  adapters = {
    require('neotest-jest')({
      jestCommand = "jest --watch ",
    }),
  }
})

or add a specific keymap to run tests with watch mode:

vim.api.nvim_set_keymap("n", "<leader>tw", "<cmd>lua require('neotest').run.run({ jestCommand = 'jest --watch ' })<cr>", {})

Monorepos

If you have a monorepo setup, you might have to do a little more configuration, especially if you have different jest configurations per package.

jestConfigFile = function()
  local file = vim.fn.expand('%:p')
  if string.find(file, "/packages/") then
    return string.match(file, "(.-/[^/]+/)src") .. "jest.config.ts"
  end

  return vim.fn.getcwd() .. "/jest.config.ts"
end,

Also, if your monorepo set up requires you to run a specific test file with cwd on the package directory (like when you have a lerna setup for example), you might also have to tweak things a bit:

cwd = function()
  local file = vim.fn.expand('%:p')
  if string.find(file, "/packages/") then
    return string.match(file, "(.-/[^/]+/)src")
  end
  return vim.fn.getcwd()
end

๐ŸŽ Contributing

Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example spec that can be tested.

To trigger the tests for the adapter, run:

./scripts/test

Bug Reports

Please file any bug reports and I might take a look if time permits otherwise please submit a PR, this plugin is intended to be by the community for the community.

neotest-jest's People

Contributors

adrigzr avatar ammarcodes avatar benlubas avatar entropitor avatar gugahoi avatar guivazcabral avatar haydenmeade avatar kostkabrukowa avatar marilari88 avatar mikaoelitiana avatar mrjones2014 avatar rcarriga avatar stevearc avatar stevearc-stripe avatar tapayne88 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.