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

feat(open): modify devServer.options.open to take an object #1770

Conversation

dangreenisrael
Copy link

This PR updates devServer.options to take an array, making it consistent with the underlying library, open

https://www.npmjs.com/package/open

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

I didn't see any tests for the unmodified code, I did however update the options.json schema

Motivation / Use-Case

This updates devServer.options to match the underlying library that is used in the implementation.

#1769

Breaking Changes

N/A

Additional Info

N/A

@jsf-clabot
Copy link

jsf-clabot commented Apr 8, 2019

CLA assistant check
All committers have signed the CLA.

@dangreenisrael dangreenisrael force-pushed the #1769-Allow-passing-args-to-devServer.open branch from ad6d8c7 to 7b0e401 Compare April 8, 2019 21:31
@codecov
Copy link

codecov bot commented Apr 8, 2019

Codecov Report

Merging #1770 into master will increase coverage by 0.36%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1770      +/-   ##
==========================================
+ Coverage   92.42%   92.79%   +0.36%     
==========================================
  Files          25       25              
  Lines         964      971       +7     
  Branches      307      309       +2     
==========================================
+ Hits          891      901      +10     
+ Misses         70       67       -3     
  Partials        3        3
Impacted Files Coverage Δ
lib/utils/runOpen.js 94.11% <100%> (+24.11%) ⬆️
lib/utils/colors.js 60% <0%> (+10%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6973e4c...37f3e88. Read the comment docs.

Copy link
Member

@hiroppy hiroppy left a comment

Choose a reason for hiding this comment

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

Need tests.

@dangreenisrael dangreenisrael force-pushed the #1769-Allow-passing-args-to-devServer.open branch from 7b0e401 to ec7cb84 Compare April 8, 2019 21:51
@dangreenisrael
Copy link
Author

Hey @hiroppy. I added some tests for the config, but I didn't see anything in there testing the status file in general. Did you want me to add a suite for it, or did I miss something?

Thanks for helping maintain such an awesome project!!!

Copy link
Member

@alexander-akait alexander-akait 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, we need tests, just mock opn package and check add arguments were passed in constructor of opn

@alexander-akait
Copy link
Member

/cc @dangreenisrael friendly ping

@dangreenisrael
Copy link
Author

Hey @evilebottnawi. We wound up not auto-open in the end so I'm not able to do it at work, and I don't have much extra time right now (I've got a 14 month old). That said, my plan is to try to get the tests written soon so this can land.

Sorry for the delays

const log = {
info: jest.fn(),
warn: jest.fn(),
};
Copy link
Member

Choose a reason for hiding this comment

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

Can we use just.spyOn to better reading tests, thanks!

Copy link
Author

Choose a reason for hiding this comment

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

We need to create log anyway. Would you prefer:

const log = {
  info: () => {}
  warn: () => {}
}

const infoSpy = jest.spyOn(log, 'info')
const warnSpy = jest.spyOn(log, 'warn')

Copy link
Author

Choose a reason for hiding this comment

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

???

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

One note and we can merge, thanks for PR

@@ -46,7 +46,7 @@ function status(uri, options, log, useColor) {
let openOptions = {};
let openMessage = 'Unable to open browser';

if (typeof options.open === 'string') {
if (typeof options.open === 'string' || Array.isArray(options.open)) {
Copy link
Member

Choose a reason for hiding this comment

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

hm, why is array, based on docs https://github.com/sindresorhus/open it should be object

Copy link
Author

Choose a reason for hiding this comment

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

Options is an object, which takes app. App takes either a string or an array. https://www.npmjs.com/package/open#usage . This keeps with the existing API of this project, passing only the app value for open in options.

i.e:

{
  open: "google chrome"
}

and

{
  open: ['google chrome', '--incognito']
}

Copy link
Member

Choose a reason for hiding this comment

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

Developers can want to use other options example: {wait: true}, also in future package can accept more arguments

Copy link
Author

Choose a reason for hiding this comment

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

Good call @evilebottnawi

Copy link
Author

Choose a reason for hiding this comment

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

I should have some time tomorrow night to work on this again

lib/options.json Outdated
{
"type": "array",
"items": {
"type": "string"
Copy link
Member

Choose a reason for hiding this comment

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

items, can be not only strings

Copy link
Author

Choose a reason for hiding this comment

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

According to this, I believe they are only string https://www.npmjs.com/package/open#usage

Copy link
Member

Choose a reason for hiding this comment

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

{wait: true}

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

I think we should do this in other way.

  • Let's make open will be Boolean, String or Object
if (Object.isObject(this.open)) {
  openOptions = Object.assign({}, options.open);
}

@dangreenisrael
Copy link
Author

dangreenisrael commented Apr 23, 2019

I think we should do this in other way.

  • Let's make open will be Boolean, String or Object
if (Object.isObject(this.open)) {
  openOptions = Object.assign({}, options.open);
}

I'm pretty sure the value of open's options.app which is what we are currently accepting in our options.open can be one of String, or Array<String>. Then if the user passes Boolean we do not pass in options

@dangreenisrael dangreenisrael force-pushed the #1769-Allow-passing-args-to-devServer.open branch 3 times, most recently from 2096bc1 to 7b0560b Compare May 4, 2019 18:42
@dangreenisrael
Copy link
Author

dangreenisrael commented May 4, 2019

@evilebottnawi Based on what you requested (or my understanding of it), I made the following update:

Allow for 3 options to pass as options.open:

As we are now doing now allowing for more complex (and possibly confusing) options to be passed in I have added logging aimed at making this more discoverable to a user.

If they pass in an object with neither app nor wait OR something that is not (boolean|string|object) they will get a warning telling them that they passed in an invalid config and a link to the open docs.

With that, I have also hard coded the open failure message, as config related info should now be caught earlier

@dangreenisrael
Copy link
Author

dangreenisrael commented May 4, 2019

If you guys are +1 to this I’ll update the tests and relevant docs

@dangreenisrael
Copy link
Author

Bump

@hiroppy
Copy link
Member

hiroppy commented May 14, 2019

CI fails

Error: expect(jest.fn()).toBeCalledWith(expected)

Expected mock function to have been called with:
  {"app": ["Google Chrome", "incognito"]}
as argument 2, but it was called with
  ["Google Chrome", "incognito"].

Difference:

  Comparing two different types of values. Expected object but received array.
    at Object.toBeCalledWith (/Users/vsts/agent/2.150.3/work/1/s/test/Status.test.js:58:20)
    at Object.asyncJestTest (/Users/vsts/agent/2.150.3/work/1/s/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)
    at e (/Users/vsts/agent/2.150.3/work/1/s/node_modules/jest-jasmine2/build/queueRunner.js:43:12)
    at mapper (/Users/vsts/agent/2.150.3/work/1/s/node_modules/jest-jasmine2/build/queueRunner.js:26:19)
    at promise.then (/Users/vsts/agent/2.150.3/work/1/s/node_modules/jest-jasmine2/build/queueRunner.js:73:41)

@alexander-akait
Copy link
Member

alexander-akait commented May 14, 2019

/cc @dangreenisrael need fix test problem

@dangreenisrael
Copy link
Author

I just wanted a +1 to the approach before I took the time to update the tests. I should have some time to get it done this weekend

@alexander-akait
Copy link
Member

@dangreenisrael +1

@hiroppy
Copy link
Member

hiroppy commented May 26, 2019

@dangreenisrael friendly ping

@dangreenisrael
Copy link
Author

I haven't forgotten about you guys. Just super busy.

Thanks for the friendly ping tho

@hiroppy hiroppy force-pushed the #1769-Allow-passing-args-to-devServer.open branch 2 times, most recently from de6aad9 to 0ec71b3 Compare June 1, 2019 19:00
@hiroppy
Copy link
Member

hiroppy commented Jun 1, 2019

@evilebottnawi I updated this pr.

I'll do below after merging.

https://www.npmjs.com/package/open

Allow for 3 options to pass as options.open:
- Boolean: runs without any options and thus uses the default browser
- String: opens with the browser of your choice
- Object: takes a settings object as defined by https://github.com/sindresorhus/open

As we are now doing now allowing for more complex (and possibly confusing) options to be passed in I have added logging aimed at making this more discoverable to a user.

If they pass in an object with neither `app` nor `wait` OR something that is not ( boolean | string | object ) they will get a warning telling them that they passed in an invalid config and a link to the `open` docs.

With that, I have also hard coded the open failure message, as config related info should now be caught earlier
@hiroppy hiroppy force-pushed the #1769-Allow-passing-args-to-devServer.open branch from 0ec71b3 to 8ff23b7 Compare June 1, 2019 19:06
@hiroppy hiroppy changed the title Update devServer.options to take an array feat(open): modify devServer.options.open to take an object Jun 1, 2019
@hiroppy hiroppy force-pushed the #1769-Allow-passing-args-to-devServer.open branch from 8ff23b7 to f4e919b Compare June 1, 2019 20:24
@hiroppy hiroppy force-pushed the #1769-Allow-passing-args-to-devServer.open branch from f4e919b to a3b06dc Compare June 1, 2019 20:37
@hiroppy hiroppy closed this Jun 1, 2019
@hiroppy hiroppy reopened this Jun 1, 2019
@hiroppy
Copy link
Member

hiroppy commented Jun 1, 2019

need to update documentation (but I want to consider open types)

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Looks good, one note


if (typeof options.open === 'string') {
openOptions = { app: options.open };
openMessage += `: ${options.open}`;
} else if (typeof options.open === 'object') {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add Array.isArray?

Copy link
Author

Choose a reason for hiding this comment

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

@dangreenisrael
Copy link
Author

Is this still something people are still interested in. If so, can we agree on an interface in principle before any more code changes?

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Two notes

expect(open).toBeCalledWith(uri, { app: ['Google Chrome', 'incognito'] });
});
});
});
Copy link
Member

Choose a reason for hiding this comment

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

openOptions = options.open;
if (!options.app && !options.wait) {
handleInvalidOptionsConfig(log, options.open);
}
Copy link
Member

Choose a reason for hiding this comment

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

Why we need this? open package can add more option in future

@alexander-akait
Copy link
Member

/cc @dangreenisrael friendly ping

@dangreenisrael
Copy link
Author

Wow, totally forgot about this. I can try to look into in the next few weeks. If someone else wants to take it over I promise I won't be offended

@stefan-winkler-diconium
Copy link

@dangreenisrael friendly ping - It would be super-useful to finally have proper "open" support for webpack. Do you think you can wrap this up soon?

@alexander-akait
Copy link
Member

@stefan-winkler-diconium you can send another PR and fix problems described here

@dangreenisrael
Copy link
Author

I've got a broken thumb, so I won't be doing any non-work required coding for at least a month. Sorry

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.

5 participants