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

Requiring coffee files without an extension is broken #44

Closed
AsaAyers opened this issue May 21, 2014 · 5 comments
Closed

Requiring coffee files without an extension is broken #44

AsaAyers opened this issue May 21, 2014 · 5 comments

Comments

@AsaAyers
Copy link
Contributor

When using CoffeeScript in Node or Browserify you can use require './somefile' and it will check for somefile.coffee, somefile.litcoffee, and somefile.coffee.md. Jest does not look for these extensions and simply throws a Cannot find module error.

To reproduce this:

  1. create examples/coffeescript/common.coffee. It can be an empty file, it just should exist.
  2. replace sum.coffee with the code below.
  3. coffee sum.coffee and see that you get get the output 11
  4. run npm test. It will throw the Cannot find module error.

examples/coffeescript/sum.coffee

# It doesn't matter what this module does, it just matters that the extension
# isn't specified. This will work in NodeJS and Browserify
require './common'

sum = (a, b) ->
  a + b

module.exports = sum

# I just added this so you can run `coffee sum.coffee`
# to demonstrate that this is working outside of jest.
if require.main is module
    console.log sum(5, 6)
@sophiebits
Copy link
Contributor

Yeah, perhaps we should support a moduleFileExtensions or something of that sort.

@AsaAyers
Copy link
Contributor Author

I have a pull request I'm putting together. I think it should use require.extensions because that is the list of what Node would use with the native require.

@jeffchan
Copy link

@AsaAyers any updates? I would like to see this too

@AsaAyers
Copy link
Contributor Author

I don't know why it says "Closed with unmerged commits" but my PR was #45.

At vjeux's suggestion it looks like I documented it:
https://github.com/facebook/jest/blob/master/docs/API.md#configmodulefileextensions-array

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants