mantoni / mochify.js

☕️ TDD with Browserify, Mocha, Headless Chrome and WebDriver
MIT License
346 stars 57 forks source link

Rewrite: read spec/bundle from stdin #268

Closed m90 closed 2 years ago

m90 commented 2 years ago

We talked about this in #229 already, but tbh I am not entirely sure if it reads like a yes or a no over there, which is why I am opening this issue.


Proposal: Instead of passing a list of files and a bundling command to Mochify, the (possibly) bundled spec could also be read from stdin. This could work like:

CLI

Users could invoke the CLI and pass - as the spec:

./my_custom_bundler_very_good_never_fails.sh | mochify --driver puppeteer -

which would just pipe the received bundle through to the driver.

API

The API could be extended to either receive a string (files) or a stream (stdin) as the spec option:

mochify({
  spec: process.stdin
})

This might also be helpful in gulp-like scenarios (if they still exist).

How does this work in conjunction with --bundle?

The interesting question is how does this work in case --bundle is given. Does Mochify a. disregard the --bundle option (maybe it refuses to do things in the first place) or b. pipe the stream through to the bundle command itself?

Do we even want this?

While I personally would prefer this for passing bundles (as a consumer I do not need to know about Mochify internals but can run my bundling command in total isolation), it also adds some extra complexity to Mochify. Use cases that use code generation or similar (if such even exist) could also just use temp files or similar instead of piping output.

mantoni commented 2 years ago

I wouldn't use it this way, but I support this feature. How would this be enabled? How does the cli decide whether it reads from stdin or uses the files (files should actually default to test like mocha does it)?

Regarding --bundle I would probably throw an exception.

m90 commented 2 years ago

I think the convention is to just pass - (as in above example) if you expect data to be read from stdin.