Wildhoney / Mocktail

:tropical_drink: Mock all of your ES6 module components with Mocktail using dependency injection.
http://mocktail.herokuapp.com/
MIT License
103 stars 6 forks source link

Add build step with babel transpiling #3

Closed pcgilday closed 8 years ago

pcgilday commented 8 years ago

Transpile es6 code to es5 using babel to allow support for es6 transpiled modules.

Context: Ran into issues running babel-node for tests when importing this module in it's current state. Could probably set up some configuration to get it working, but thought I'd update this module to decrease the barrier to entry for others wanting to use it.

pcgilday commented 8 years ago

I'm going to fix the tests and update the PR.

Wildhoney commented 8 years ago

@pcgilday thanks for this!

If we add the following to the package.json then Babel should transpile the imported file automatically – by default it ignores the node_modules directory.

"browserify": {
  "transform": [
    "babelify"
  ]
}

Could you please try with v0.3.4?

pcgilday commented 8 years ago

@Wildhoney I still get the same error using the updates on master. I am not using browserify in my module because it is not meant for the browser, maybe this is why it doesn't work?

Wildhoney commented 8 years ago

How are you trying to use it? As Mocktail is written in ES6, you just need to transpile your files, including any third-party modules that have been imported.

pcgilday commented 8 years ago

I am transpiling my code using babel with webpack. However, I am using Mocktail for the tests which are run using babel-node. This works fine until I try to import an es6 module.

Wildhoney commented 8 years ago

Understood @pcgilday — I haven't tried Mocktail with Webpack, but I'm sure there must be a better way than adding a build step. However, let me merge now, and come back to it once I've tried it with Webpack.

Thanks for the PR :+1:

pcgilday commented 8 years ago

@Wildhoney I agree there should be a better way, but I have not found one. I have tried adding the require(babel-core/register)() before the mocktail import but that threw a whole new set of babel related errors (I think having to do with the babel 6.0 update). This is not really a webpack specific issue, but more running tests from the command line using babel-node. Maybe this is not the best way to setup tests, but it has been working for me so far and gives me a simple test setup.

This is what I have been doing to all of my es6 modules to improve usability with minimal integration when an older module needs to use it, but if you figure out a better way please let me know, I would like to avoid build steps for future modules if possible.

Thank you for accepting, I like what you have done with Mocktail so far.

Wildhoney commented 8 years ago

Is the GitHub project public that uses this approach with Mocktail? That would give me a test environment.

pcgilday commented 8 years ago

@Wildhoney No, unfortunately it is not at this time. I actually ran into this issue with another library, so I am going to have to figure out a better approach to these tests. I will update you when I figure it out.

I think we can probably roll this PR back and I will update you when I get it working with what configuration I needed. Sorry to bother you with all this if it winds up just being an issue with my setup :smirk: