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

broken build #4

Closed lironess closed 8 years ago

lironess commented 8 years ago

Hi. I did npm install mocktail and it successfully installed last version (v0.3.5), but when I try to use it at code I cant require it, as you can see here:

> const a = require('mocktail');

Error: Cannot find module 'mocktail'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at repl:1:11
    at REPLServer.defaultEval (repl.js:164:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)

Also - I am not having problem at previous versions. Please fix the build script

Wildhoney commented 8 years ago

That's probably relating to a recently merged PR, which introduces a build step.

I'm going to put the main file back to what it was originally, however – and treat the built version as an exception.

Please try with v0.3.6 :+1:

lironess commented 8 years ago

build works now, but I have another problem. I'm trying to run the example you provided (with mocha and babel 5), and I'm getting this error:

node_modules/mocha/bin/mocha --recursive --compilers js:babel/register test.js

/Users/myuser/Workspace/playground/node_modules/mocktail/component/mocktail.js:23
export const ENV = { PRODUCTION, TESTING };
^^^^^^

SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:414:25)
    at Module._extensions..js (module.js:442:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/myuser/Workspace/playground/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:214:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/myuser/Workspace/playground/Setup.js:5:17)
    at Module._compile (module.js:435:26)
    at normalLoader (/Users/myuser/Workspace/playground/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/myuser/Workspace/playground/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/myuser/Workspace/playground/test.js:5:1)
    at Module._compile (module.js:435:26)
    at normalLoader (/Users/myuser/Workspace/playground/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/myuser/Workspace/playground/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at /Users/myuser/Workspace/playground/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/myuser/Workspace/playground/node_modules/mocha/lib/mocha.js:213:14)
    at Mocha.run (/Users/myuser/Workspace/playground/node_modules/mocha/lib/mocha.js:453:10)
    at Object.<anonymous> (/Users/myuser/Workspace/playground/node_modules/mocha/bin/_mocha:393:18)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:134:18)
    at node.js:961:3
Wildhoney commented 8 years ago

You'll need to transpile the module using something like Browserify, because otherwise modules aren't going to work.

If you're using Mocha with Karma then you can add the transpiling as a preprocessor.

If you're using something else, then you'll need to refer to the documentation for that — maybe mochify is worth trying.

lironess commented 8 years ago

doesn't the --compilers js:babel/register do that for me ?

Wildhoney commented 8 years ago

It should do — take a look at this on StackOverflow.

lironess commented 8 years ago

Well, the ignore does not working .. tried also with "ignore": false

lironess commented 8 years ago

can you maybe just make the built version to run with es5 ?

Wildhoney commented 8 years ago

:+1: Please try with v0.3.7.

lironess commented 8 years ago

It says it cannot find module browserify

Wildhoney commented 8 years ago

v0.3.8?

lironess commented 8 years ago

still:

mocktailexample  npm test

> mocktailexample@1.0.0 test /Users/lironshmuel/Workspace/playground/mocktailexample
> node_modules/mocha/bin/mocha --recursive --compilers js:babel-core/register --reporter spec ./

module.js:339
    throw err;
    ^

Error: Cannot find module 'browserify'
    at Function.Module._resolveFilename (module.js:337:15)
    at Function.Module._load (module.js:287:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/Users/lironshmuel/Workspace/playground/mocktailexample/node_modules/acorn/bin/build-acorn.js:4:18)
    at Module._compile (module.js:425:26)
    at Module._extensions..js (module.js:432:10)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/lironshmuel/Workspace/playground/mocktailexample/node_modules/babel-core/lib/api/register/node.js:144:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at /Users/lironshmuel/Workspace/playground/mocktailexample/node_modules/mocha/lib/mocha.js:216:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/lironshmuel/Workspace/playground/mocktailexample/node_modules/mocha/lib/mocha.js:213:14)
    at Mocha.run (/Users/lironshmuel/Workspace/playground/mocktailexample/node_modules/mocha/lib/mocha.js:453:10)
    at Object.<anonymous> (/Users/lironshmuel/Workspace/playground/mocktailexample/node_modules/mocha/bin/_mocha:393:18)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:136:18)
    at node.js:972:3
npm ERR! Test failed.  See above for more details.
Wildhoney commented 8 years ago

That looks more like an issue with your setup, rather than with Mocktail itself.

lironess commented 8 years ago

run successfully now, but it doesn't mock at all :

  Request
    1) Give me RequestMock

  0 passing (25ms)
  1 failing

  1) Request Give me RequestMock:

      AssertionError: expected 'Requester' to equal 'RequestMock'
      + expected - actual

      -Requester
      +RequestMock

      at Context.<anonymous> (test/test.js:8:25)

uploaded my code so you can clone and try yourself (also make you collaborator so you can push the fix directly to it): https://github.com/lironess/mocktail-example

Wildhoney commented 8 years ago

I've just pushed a commit to your repo.

It wasn't working because Mocha simply includes everything in the test/ directory, whereas we want it to be based on the order we choose in the test file, to ensure the Setup.js is run before the including of the Request module :+1:

lironess commented 8 years ago

Works perfect ! you can close the issue

Wildhoney commented 8 years ago

Thanks @lironess — let me know if you need anything more.