Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmccray/0b3ae7362ebd6418b408 to your computer and use it in GitHub Desktop.
Save mattmccray/0b3ae7362ebd6418b408 to your computer and use it in GitHub Desktop.

So... I would like to be able to use coffeescript without having to add the ".coffee" extension in my requires (in the lib code, not the test code).

I would guess that in my test a require('coffee-script/register') would work -- but I'd be wrong. :)

For example, I'd like to get this working:

util.coffee:

module.exports= 
  log: (msg)->
    console.log "LOG", msg

sum.coffee:

{ log }= require './util'

module.exports= (a,b)-> 
  log "sum it"
  a + b

__tests__/sum-test.coffee:

jest.dontMock '../sum.coffee'
sum= require '../sum.coffee'

describe 'Sum', ->
  it 'should sum stuff', ->
    expect sum(2,2)
      .toBe 4

Currently, you'd have to do this (Note the added ".coffee"):

util.coffee:

module.exports= 
  log: (msg)->
    console.log "LOG", msg

sum.coffee:

{ log }= require './util.coffee' # <= would rather not pollute my lib code like this

module.exports= (a,b)-> 
  log "sum it"
  a + b

__tests__/sum-test.coffee:

jest.dontMock '../sum.coffee'
sum= require '../sum.coffee'

describe 'Sum', ->
  it 'should sum stuff', ->
    expect sum(2,2)
      .toBe 4

Am I being picky? Yes. But that doesn't mean that it wouldn't be nice.

I'm packaging my project for the client via Browserify. Is there an easy-ish way to accomplish this that I'm missing, or would it be more involved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment