yamadapc / jsdoctest

Run jsdoc examples as doctests.
https://yamadapc.github.io/jsdoctest
MIT License
92 stars 9 forks source link

browserify/babelify + jsdoctest + mocha #20

Closed TheAmazingPT closed 8 years ago

TheAmazingPT commented 8 years ago

Hey,

first of all, i love your module! I enjoy using it in a few of my pet projects. Now i wanted to give it a try in a bigger project, but there i am coding with es6 features, which get transpiled by babel. I am using browserify with babelify as a transformer. Unfortunately i couldnt find a way to make the tests run through mocha. In mocha i tried everything from requireing babel/register to --stdin input of the transpiled js source from browserify.

The problems where always to detect the source or mocha just doesnt print anything. My latest attempt looked like the following:

This one gives no output in the npm run-scripts context:

browserify source/javascript/mobile-header.js -t babelify > mocha --stdin --require jsdoctest -R list

jsdoctest is atleast able to construct a spec

./node_modules/jsdoctest/bin/jsdoctest -s source/javascript/mobile-header.js

require('should');
describe('source/javascript/mobile-header', function() {
  describe('changeVisibilityState()', function() {
    it('this.changeVisibility(true)', function() {
      (this.changeVisibility(true)).should.eql(false);
    });
  });
});

Do you have any ideas or tipps how i can use your wonderful tool, mocha and browserify and babelify?

I have the options to use the stdout and stdin. Is mocha maybe not the right testing framework? Can your tool also work with others, for example tape?

I would be really glad to hear some tips and hints from. Maybe its a missing feature for your tool? ;-)

Greetings and thanks!

yamadapc commented 8 years ago

Hey! Thanks for being a user. Could you send the source-code for what you're trying to test? I haven't tried using it over compiled source, but I have a couple of guesses. The way jsdoctest works with mocha is by injecting itself on require so that it can append the test to loaded module.

This won't work with --stdin, so good catch. I should think of a way of doing that, but require injection is already a huge hack. Doing mocha --require babel/register --require jsdoctest stuff.js (in this order) should work though. I'll add some tests and try to fix it if it doesn't.

Using other testing frameworks... Err... All you would have to do is write these bits everything else should be well factored enough that it'd be easy to add other frameworks. But I haven't got much interest in supporting other frameworks ATM. Try that --require order, I'll try it too, we'll see.

TheAmazingPT commented 8 years ago

Hey, sorry that i couldn't answer you all the time. On this weekend i will have the time for that. I am looking forward to experiment =)

yamadapc commented 8 years ago

From the commit:

This closes #20. Browserify probably won't be supported, but you can see that this works:

$ mocha --require babel-register --require jsdoctest examples/babel-example.js

If you're on later versions of Node.js you can even just:

$ mocha --require jsdoctest examples/babel-example.js

If you can provide a browserify test case we can fix it.