-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mochify Rewrite #229
Comments
Woohoo 🎉 this seems to be an amazing start. I love how much simpler this is. Some uninformed feedback after a first glance: Zero configThe reason why I started using Mochify in ~2014 was that "it just worked ™️". I would install the package, it picked up my Playing the devil's advocate, seeing that I now have to install multiple packages and possibly provide a config file makes me feel slightly uneasy. Will zero config work too? Will there be a single package that wraps the CLI and a default driver? Passing options to DriversMaybe you're still planning to do this, but it seems to me as if we'd need to be able to pass options to drivers at some point, which currently seems to be unsupported: Line 16 in 764b134
playwright driver and wanted to tell playwright which engine to use, how would that work?
Custom non-@mochify driversDrivers seem to require to reside under the Default driverI don't know if you ever had a look at that branch, but I ported Mochify to use playwright instead of puppeteer a while ago, which was relatively painless (but I never got around to know how the testing story should work, so I shamefully abandoned it): https://github.com/mantoni/mochify.js/tree/playwright-firefox. Considering this also adds Firefox and Webkit support I wonder if this should maybe become the default driver instead of puppeteer? Or is puppeteer a nicer option because it's more lightweight? Really not sure. Extra depsThis might be very subjective because my $DAYJOB consists of googling for error messages of npm failing on humongous dependency trees ~70% of the time (no exaggeration unfortunately), but I am wondering if adding If time allows I think I'd like to try adding a |
Thank you for the quick feedback. Here are my thoughts on your points:
This was my design goal with mochify at the time, but you're sort of making the point that we cannot keep it this way yourself 😄. You might want to bundle with
Yes, we'd need to be able to pass options to drivers. The current state is just a proof of concept. There's a lot to do.
Yep, it would be nice to allow "external" drivers. The mochify cli could map "puppeteer" and "selenium" to the
I had a brief look at your work on
Sure, we could do the work ourselves. However, Another note: With the latest commits, I managed to run the ../mochify.js/cli/index.js './test/**/*-test.js' --bundle 'browserify --no-detect-globals --plugin [ proxyquire-universal ] --debug' -R dot |
A few more words about the "default": I probably could have made this a lot clearer, but when I said "default" I was mostly referring to what is being mentioned in the above-the-fold installation instructions in the README, which of course isn't a bundled default, but I'd argue it creates an implicit default. Right now, it reads:
and I would assume this means that 98% people trying it out will install this driver and 90% of users will stick to it, no matter how many other options there are. I understand it's meant to be pluggable, but many consumers won't have time and/or knowledge to make an educated decision about which driver to use, so they will stick to what they initially installed. So what i was trying to say is: it's a really important decision which driver is mentioned in the Another question unrelated to this came to mind: how do you plan to handle versioning in the monorepo? Are drivers and the cli planned to use the same major always or could they theoretically differ and each package has its own set of compatibility guarantees? |
That's a good point. We should make "the best" driver the default. If On top of the "default"
With npm workspaces, each of the workspace folders is a separate module that can be versioned and published. E.g. {
"peerDependencies": {
"@mochify/mochify": "^1 || ^2"
}
} |
Another random shower thought of mine: Assuming we want to completely offload the bundling to the consumer and just have Mochify consume a bundle bundled by basically everything, why doesn't this command:
look like this instead, freeing us of having to handle the bundling command:
i.e. Mochify just reads the bundled files from |
We could support your proposal, to read from |
Ah, so the |
That's the idea so far. We can allow to specify / override it on the command line though. |
I found half an hour to play around with this and I couldn't find any major issues:
|
About reading the bundle from |
Hm, interesting point. My design goal here would be that the API and the CLI work the same way. Basically all options are a one-to-one mapping of configs that can be passed to However, the API can do more than the CLI and allow the |
This makes a lot of sense considering the config file plan. Adding extra options to the API will still work. |
For what it's worth I tried implementing a jsdom driver (which would be nice as a very minimal option) over here: https://github.com/mantoni/mochify.js/tree/jsdom-driver I'm running into something I don't fully understand though:
I remember Mocha is doing some custom console modifications, but I cannot really connect the dots here yet. Some more debugging records here:
Found out what is going on here and fixed it in #232 |
Since we have a first version of the rewrite published, I think it's time to have more focused discussions on the individual issues. I have created a Milestone to group open issues here: https://github.com/mantoni/mochify.js/milestone/1 Please feel free to add whatever you feel is missing. Thanks a lot for all the help! |
Let's rewrite mochify 🚀
The
rewrite
branch is an attempt to rethink mochify from the ground up.Modular setup to only install what is needed
Mochify is currently rather bloated and loads all sorts of dependencies that most projects might never use. We can use npm workspaces to keep everything in one repository and publish smaller modules. I reserved the
@mochify
npm namespace.The rewrite introduces "drivers" which are modules that bridge between the mochify CLI and runtime environments to run tests. Here are some ideas for drivers:
driver-puppeteer
(first implementation exists)driver-selenium
to use the selenium protocol (exmin-wd
)driver-chromedriver
could be a bridge for https://www.npmjs.com/package/chromedriverExternalise the bundler
Allow to configure a
bundle
script to run usingexeca
(https://www.npmjs.com/package/execa), similar to whatlint-staged
does. This eliminates the dependency on browserify and allows to use mochify with other bundlers 🙌. And it removes a lot of the current complexity. 👍Instead of bundling mocha with the test files, the pre-built
mocha/mocha.js
bundle is loaded, then a Mochify "client" is loaded, and then the actual script is loaded separately (to retain the correct line numbers for source-maps).Only the actually passed files need to be bundled.
mocha/mocha.js
and the Mochifyclient.js
files don't have any dependencies.Untangle reporter, console, runner and coverage output
Mochify currently does a lot of output parsing. The desired reporter is installed in the browser and the output has to be separated from
console.log
statements and output frompuppeteer
ornyc
.Instead, use a custom reporter in the browser and pass
ndjson
over a communication channel to feed events into a Mocha reporter on the CLI side. This removes the need for excessive parsing since event names can be used to communicate different kinds of output.Support config files
E.g.
cosmiconfig
https://www.npmjs.com/package/cosmiconfigHelp wanted
The rewrite branch is a baiscally a runnable exampe of the above ideas, with no unit tests, documentation and a rough implementation. Please feel free to contribute ideas, PRs, ...
@m90 @mroderick @albertyw @fatso83
The text was updated successfully, but these errors were encountered: