Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joeheyming opened this issue Apr 1, 2019 · 10 comments
Closed

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

joeheyming opened this issue Apr 1, 2019 · 10 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@joeheyming
Copy link

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.

@sunesimonsen
Copy link

Take a look at locate-dominating-file. You can use it to find the first path containing node_modules/.bin/jest

@joewreschnig
Copy link

Also consider use of executable-find if you continue using sh. I do have the node_modules bin path in my exec-path, but jest--run-as-comint runs jest through sh, so it doesn't inherit the Emacs executable path. If you're going to wrap the execution, you should also invoke the executable through a fully-qualified path.

@ryanolsonx
Copy link

@edmundmiller edmundmiller added bug Something isn't working enhancement New feature or request labels Apr 4, 2019
@Eeemil
Copy link

Eeemil commented Apr 26, 2019

Try https://github.com/codesuki/add-node-modules-path

does not solve this issue

@Aigeruth
Copy link

I mainly use Jest for React development and these projects are created with the create-react-app command. This means that Jest is configured for npm test. I already have npm in the PATH, so I ended up with the following configuration:

(use-package jest
  :config
  (setq jest-executable "npm test --")
)

@baerrach
Copy link

baerrach commented Nov 14, 2019

There is already an emacs package that will add your project's node_modules to the shell path

(use-package add-node-modules-path
  :after (js2-mode))

@eemil I have everything working with add-node-modules-path and (setq jest-executable "npm test --") what is not working for you?

@baerrach
Copy link

I mainly use Jest for React development and these projects are created with the create-react-app command. This means that Jest is configured for npm test. I already have npm in the PATH, so I ended up with the following configuration:

(use-package jest
  :config
  (setq jest-executable "npm test --")
)

You want to use this anyway. As it centralises the configuration of jest.

We need to add cross-env NODE_PATH-. to the test script so running jest manually would also need that too. Much easier to stick with npm t and configure package.json properly

@edmundmiller
Copy link
Owner

Sorry for taking forever to get around to this, and being a poor maintainer so far, this is my first barely popular project.

@baerrach I'm testing the "npm test --" and it's working great. So great that it works with ava, and I'm going to guess anything you could want as long as it's under your test script.

Could you expand on your cross-env NODE_PATH-. comment?

I don't know whether to rename the repo to something else, maybe just make a note of it in the README, archive the project or what. Any comments on that would be appreciated.

edmundmiller added a commit that referenced this issue Mar 18, 2020
@baerrach
Copy link

Our project has import or require statements for local src modules as path/to/module.

Its a bit equivalent to webpack alias https://webpack.js.org/configuration/resolve/

By setting NODE_PATH=. as an environment variable then node will load the module from the global folders.

To work on both Windows and Unix environments I was using cross-env to see these environment variables.

I've since abandoned that because cross-env has some issues with signal handling Ctrl-C properly and passing them to the spawned child processes.

Now I just recommend Windows users to use https://gitforwindows.org/ and set their shell correctly to export NODE_PATH=. and use the Bash shell provided.

@edmundmiller
Copy link
Owner

Gotcha so it's just windows? But with the npm test -- from @Aigeruth it should work, so I'm going to go ahead and close it.

Sidenote I use yarn on some projects but I went with npm because everyone should have npm, but not everyone needs yarn, and it works with npm test --

I also didn't give proper credit to @Aigeruth in the commit, I apologize, I read @baerrach's, quote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants