Giter Club home page Giter Club logo

emacs-jest's Introduction

jest.el

https://melpa.org/packages/jest-badge.svg

Credit: emacs-python-pytest

This package provides helpers to run jest.

Installation

jest.el is available from melpa.

With use-package:

(use-package jest)

Manually:

M-x package-install RET jest RET

Overview

The main command is jest-popup, which will show a dispatcher menu, making it easy to change various options and switches, and then run jest using one of the actions.

  • jest (run all tests)
  • jest-file (current file)
  • jest-file-dwim (‘Do what I mean’ for current file)
  • jest-function (the test function where the pointer is now, fallback to current file)
  • jest-last-failed (rerun previous failures)
  • jest-repeat (repeat last invocation)

A prefix argument causes the generated command line to be offered for editing, and various customization options influence how some of the commands work. See the README.org for detailed information.

Jest Minor Mode

Jest minor mode binds compilation-related commands such as compile-command and recompile-command to Jest commands, so that, for example C-c <RET> (compile) runs jest-popup and C-c C-<RET> (recompile) runs jest-repeat. The commands to run are configurable.

(use-package jest
  :after (js2-mode)
  :hook (js2-mode . jest-minor-mode))

Jest Popup

Switches
 -b bail (--bail)
 -c colors (--colors)
 -C coverage (--coverage)
 -d run doctests (--doctest-modules)
 -D debug jest config (--debug)
 -e expand (--expand)
 -f force exit (--forceExit)
 -l last commit (--lastCommit)
 -o only changed (--onlyChanged)
 -s silent (--silent)
 -v verbose (--verbose)
 -w watch (--watch)
 -W watch all (--watchAll)

Options
 =c config file (--config=)
 =k only names matching expression (-t)
 =p only files matching expression (--testPathPattern )
 =P only files not matching expression (--testPathIgnorePatterns )
 =o output file (--outputFile=)
 =x exit after N failures or errors (--maxfail=)

Run tests
 t Test all            x Test last-failed

Run tests for current context
 f Test file           F Test this file
 d Test function

Repeat tests
 r Repeat last test run

Contributing

Please create a new issue or submit a PR.

emacs-jest's People

Contributors

andrewswerlick avatar basil-conto avatar edmundmiller avatar khalfaniw avatar lazyskulptor avatar nverno avatar purcell avatar sandinmyjoints avatar syohex avatar xlarsx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

emacs-jest's Issues

Support jest-function for Typescript-mode

The jest-function uses js2, so it does not work on other modes like typescript-mode.

A few ideas:

  • one option could be to just add code to get the same information from other modes.
  • another one could be to have some basic heuristics and not rely on js2-mode at all. So using some basic regular expressions to extract the path of describe/it strings.
  • Maybe another libraries like like lsp, imenu, could be used?

Symbol’s function definition is void: python-pdbtrack-comint-output-filter-function

Line: 385 python-pdbtrack-comint-output-filter-function

      (when jest-pdb-track
        (add-hook
         'comint-output-filter-functions
         'python-pdbtrack-comint-output-filter-function
         nil t))

The code only requires

(require 'comint)
(require 'compile)
(require 'js2-mode)

(require 'dash)
(require 'dash-functional)
(require 'magit-popup)
(require 'projectile)

Which probably don't contain python-pdbtrack-comint-output-filter-function

jest-function generates invalid jest command line

When jest--current-defun finds a function jest is called with a command line like jest file.test.js::functionName. To my understanding the :: syntax is unknown to jest so matching tests will never be found. jest --testNamePattern=<regex> should be used instead.

Documentation of use

I've been trying to use your package without good results, for the installation I'm using use-package in this way:

;; Jest mode
(use-package jest
  :ensure t
  :config
  (setq jest-executable "npm run test --"))

(use-package add-node-modules-path
  :ensure t)

When I'm editing a test file and after executing M-x jest-popup t I get the following message in the minibuffer:

Wrong type argument: stringp, nil

My package.json looks like this:

"scripts": {
    "test": "jest"
  }

Could anyone provide me help on this configuration issue?

Better default value for jest-executable

I have been setting up jest.el for my projects and noticed that the default value of jest-executable (npm test) is not that general.

In my case, the default breaks because we work in a monorepository where the toplevel test is not directly invoking jest.

Proposed solution

I would propose to change it to npx --no-install jest, which should work in a larger number of cases.

The downside is you need a bit more modern version of npm. But it was introduced a while back.

Alternative solution

Alternatively, finding "jest" in the path would also work and the user could rely on add-node-modules-path. Related discussion: #2. But my proposed default value should work in most installations.

emacs-jest assumes jest is located on the user's path

I was excited to use emacs-jest, but when I tried it out I got:
/bin/sh jest: command not found.

Could it be possible to make it so that this package looks for jest in the module? Like it could try to find the nearest package.json and execute jest from the node_modules in that folder.

I've used other packages like grunt.el https://github.com/gempesaw/grunt.el and it has similar behavior where it tries to find the nearest package json to run grunt.

Turn on colors by default

Any reason why colors are disabled by default and would you be amenable to adding an option to enable them by default?

Clean up popup

There are a few thing that are left over from the pytest pilfering such as

-d run doctest (--doctest-modules)

That need to be removed.

Links in compile buffer dont't work

PR #29 is a basic implementation that seems to fix this.

For me some of the rules for java (and cucumber) were matching but they didn't do the right thing. It's conceivable that other people had some magic rules in compilation-error-regexp-alist from another language that worked for them...

Use compilation-shell-minor-mode

Activating compilation-shell-minor-mode will enable the all the cool features of compilation-mode, for example, compilation-next-error, compilation-previous-error, and compile-goto-error. So you quickly go to a failing test and jump from its stack trace directly to the failed assertion.

emacs-jest assumes that jest options are in project root

My project does not store the Jest configuration in the project root. It stores the Jest configuration in web/react, where the relevant code lives. This directory includes files such as:

  • jest.config.js
  • package.json

Other project directories include code in other programming languages. There is no package.json in project/ or project/web.

#2 discusses the difficulty in finding the jest executable, but even if I hardcode a working executable, when I try to invoke jest-file on /Users/thomaswhaples/code/project/web/react/src/ReactAppName/SubApp/Component/__tests__/Form.spec.jsx

then the process runs in /Users/thomaswhaples/code/project instead of /Users/thomaswhaples/code/project/web/react. As a result, I have to hardcode an additional paramter:

--config web/react/package.json

This is inconvenient to set up, glues the configuration to one specific project, and generally should not be necessary.

Feature request: per project jest-arguments

For example, at work we have different jest config files for different repos. Because jest-arguments is global, when I save a config file for a particular repo, it is not only the default for that repo but also for other repos.

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.