Skip to content
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

Allow reading bundle from stdin #269

Merged
merged 6 commits into from Sep 17, 2021
Merged

Allow reading bundle from stdin #269

merged 6 commits into from Sep 17, 2021

Conversation

m90
Copy link
Collaborator

@m90 m90 commented Sep 16, 2021

Solves #268

@m90 m90 changed the title l Allow reading bundle from stdin Sep 16, 2021
cli/index.js Outdated Show resolved Hide resolved
it('reads from stdin', async () => {
let result;
try {
const cp = execa('../../index.js', ['--driver', 'puppeteer', '-'], {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could also teach run about this behaviot, dunno if it's worth it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'd make it rather complicated, no?

mochify/lib/load-config.js Outdated Show resolved Hide resolved
}

async function mergeWithDefault(default_config_promise, config) {
const default_config = await default_config_promise;
if (default_config) {
return deepmerge(default_config.config, config);
return deepmerge(default_config.config, config, {
clone: false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloning a stream apparently causes infinite recursion. Don't think not cloning will hurt us here.

@@ -6,6 +6,10 @@ const glob = promisify(require('glob'));
exports.resolveSpec = resolveSpec;

async function resolveSpec(spec = 'test/**/*.js') {
if (typeof spec === 'object' && typeof spec.pipe === 'function') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it nicer to handle such situations at lib level instead of index.js as index.js already contains a lot of control flow and it would have gotten even more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also get the feeling it's growing quite a bit.

Maybe it's time to introduce more functions like run that handle parts of the control flow. E.g. configure, launch, run and shutdown. Just a random morning thought though 🙃

@m90 m90 marked this pull request as draft September 16, 2021 17:33

exports.validateConfig = validateConfig;

function validateConfig(config) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this function intentionally simple (i.e. manual checking) for now. We can start building our declarative mini DSL later ...

const { exit_code } = await mochify(opts);
}
delete opts._;
mochify(opts)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwrapping this and using a Promise chain is here to stop eslint from complaining. I'm not entirely sure if its complaints are correct or not yet. We could also keep the old version and ignore the rule, no real preference from my side here.

See eslint/eslint#15076

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably even easier to read than the self-invoking async function. 👍

@m90 m90 marked this pull request as ready for review September 17, 2021 10:48
@m90 m90 requested a review from mantoni September 17, 2021 10:50
Copy link
Owner

@mantoni mantoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good to me. Thank you. Just a minor stylistic question, but feel free to merge.

Comment on lines +74 to +75
mochify ./src/*.test.js # Let the shell handle glob expansion
mochify "./src/*.test.js" # Let Mochify handle glob expansion
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const { exit_code } = await mochify(opts);
}
delete opts._;
mochify(opts)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably even easier to read than the self-invoking async function. 👍

mochify/index.js Outdated
Comment on lines 18 to 21
const validation_error = validateConfig(config);
if (validation_error) {
throw validation_error;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is validateConfig not throwing the errors directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I've just been writing too much Go lately. I'll change this as it makes sense for this to behave like everything else (which is throwing to stop execution).

@m90 m90 merged commit d09c468 into rewrite Sep 17, 2021
@m90 m90 deleted the rewrite-stdin branch September 17, 2021 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants