carbonfive / mocha-server

8 stars 4 forks source link

could make the module to expose APIs? #23

Open ghost opened 11 years ago

ghost commented 11 years ago

While providing a command line tool is very useful, in some cases we may also want to use this module through API in javscript code as well.

For example, I use Jake as my task management tool. It's completely in javascript. So I would prefer calling APIs directly over executing a shell command. It's more flexible and may integrate better to work with other modules as well.

Currenlty requiring 'mocha-server' in node.js throws error. I think this is due to the incorrect file that the main field in package.json refers to. Also if you would agree to expose APIs, could you also add some documents?

Thanks!

rudyjahchan commented 11 years ago

An interesting idea. Keep in mind though that even if mocha-server isn't called via a script, if we try to run it heedlessly, it has to call out to the command line. But will definitely add this to the "roadmap".

Rudy Jahchan

On Monday, June 3, 2013 at 1:19 AM, mchen745 wrote:

While providing a command line tool is very useful, in some cases we may also want to use this module through API in javscript code as well. For example, I use Jake as my task management tool. It's completely in javascript. So I would prefer calling APIs directly over executing a shell command. It's more flexible and may integrate better to work with other modules as well. Currenlty requiring 'mocha-server' in node.js throws error. I think this is due to the incorrect file that the main field in package.json refers to. Also if you would agree to expose APIs, could you also add some documents? Thanks!

— Reply to this email directly or view it on GitHub (https://github.com/carbonfive/mocha-server/issues/23).

ghost commented 11 years ago

Thanks Rudy! I haven't thought about running it heedlessly though. And I think that is totally fine for my use case. :)

By the way, I have another idea. But not sure if your module would also like to cover. I recently started a few projects that are all targeting both node.js and the browsers. I write code in CommonJS module style, which runs smoothly in node.js. Then use browserify to bundle the code for browsers. It works great! But currently my tests run only in node.js (easily by using mocha). Since my code is also targeting browsers, I definitely want the tests to run in browsers as well. One straightforward way is to write runner html files for each project. But I really hate to do that. A tool to automatically generate the runner html is needed! So I found your project!

But there's a problem. My code is in CommonJS style. It does not work by directly including each module files in the browser. I need something like browserify to support that.

While definitely I can browserify by myself before running mocha-server, my question is, would you natively support tests written in node.js style to run in the browsers in the future? (Just hope though. It's OK to me if your answer is no. :)

Actually this is also why I ask the first question of exposing apis. If possible I would like to avoid generating a temporary bundle file (of mocha tests), instead generate it on the fly so that the test code is always updated for each new request. So if mocha-server could expose an API to embed inline scripts, that is enough for my use case.

Great thanks, Martin

rudyjahchan commented 11 years ago

Actually supporting the various "require" styles is something I want to do as well! So yeah, let's hack a solution. And don't hesitate to make a pull request.  — Sent from Mailbox for iPad

On Wed, Jun 5, 2013 at 1:40 AM, mchen745 notifications@github.com wrote:

Thanks Rudy! I haven't thought about running it heedlessly though. And I think that is totally fine for my use case. :) By the way, I have another idea. But not sure if your module would also like to cover. I recently started a few projects that are all targeting both node.js and the browsers. I write code in CommonJS module style, which runs smoothly in node.js. Then use browserify to bundle the code for browsers. It works great! But currently my tests run only in node.js (easily by using mocha). Since my code is also targeting browsers, I definitely want the tests to run in browsers as well. One straightforward way is to write runner html files for each project. But I really hate to do that. A tool to automatically generate the runner html is needed! So I found your project! But there's a problem. My code is in CommonJS style. It does not work by directly including each module files in the browser. I need something like browserify to support that. While definitely I can browserify by myself before running mocha-server, my question is, would you natively support tests written in node.js style to run in the browsers in the future? (Just hope though. It's OK to me if your answer is no. :) Actually this is also why I ask the first question of exposing apis. If possible I would like to avoid generating a temporary bundle file (of mocha tests), instead generate it on the fly so that the test code is always updated for each new request. So if mocha-server could expose an API to embed inline scripts, that is enough for my use case. Great thanks,

Martin

Reply to this email directly or view it on GitHub: https://github.com/carbonfive/mocha-server/issues/23#issuecomment-18962584

ghost commented 11 years ago

Cool! I would definitely like to contribute as well. But let me get familiar with the code first :) 在 2013-6-5 下午10:39,"Rudy Jahchan" notifications@github.com写道:

Actually supporting the various "require" styles is something I want to do as well! So yeah, let's hack a solution. And don't hesitate to make a pull request. — Sent from Mailbox for iPad

On Wed, Jun 5, 2013 at 1:40 AM, mchen745 notifications@github.com wrote:

Thanks Rudy! I haven't thought about running it heedlessly though. And I think that is totally fine for my use case. :) By the way, I have another idea. But not sure if your module would also like to cover. I recently started a few projects that are all targeting both node.js and the browsers. I write code in CommonJS module style, which runs smoothly in node.js. Then use browserify to bundle the code for browsers. It works great! But currently my tests run only in node.js (easily by using mocha). Since my code is also targeting browsers, I definitely want the tests to run in browsers as well. One straightforward way is to write runner html files for each project. But I really hate to do that. A tool to automatically generate the runner html is needed! So I found your project! But there's a problem. My code is in CommonJS style. It does not work by directly including each module files in the browser. I need something like browserify to support that. While definitely I can browserify by myself before running mocha-server, my question is, would you natively support tests written in node.js style to run in the browsers in the future? (Just hope though. It's OK to me if your answer is no. :) Actually this is also why I ask the first question of exposing apis. If possible I would like to avoid generating a temporary bundle file (of mocha tests), instead generate it on the fly so that the test code is always updated for each new request. So if mocha-server could expose an API to embed inline scripts, that is enough for my use case. Great thanks,

Martin

Reply to this email directly or view it on GitHub:

https://github.com/carbonfive/mocha-server/issues/23#issuecomment-18962584

— Reply to this email directly or view it on GitHubhttps://github.com/carbonfive/mocha-server/issues/23#issuecomment-18980689 .