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: allow open option to accept an object #2492

Merged
merged 9 commits into from Apr 2, 2020

Conversation

EslamHiko
Copy link
Member

  • 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?

yes

Motivation / Use-Case

complete : #1770

Breaking Changes

no

Additional Info

I've tested it on ubuntu Linux with this config :

devServer: {
    open: { app: ['google-chrome','--incognito']},
    openPage: 'http://google.com',
  }

@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #2492 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2492      +/-   ##
==========================================
+ Coverage   93.55%   93.57%   +0.01%     
==========================================
  Files          34       34              
  Lines        1319     1322       +3     
  Branches      379      380       +1     
==========================================
+ Hits         1234     1237       +3     
  Misses         83       83              
  Partials        2        2              
Impacted Files Coverage Δ
lib/utils/runOpen.js 100.00% <100.00%> (ø)

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 c6bdfe4...f1eef86. Read the comment docs.

Comment on lines 871 to 875
Object.assign({}, argv, {
open: {
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.

Suggested change
Object.assign({}, argv, {
open: {
app: ['Google Chrome', '--incognito'],
},
}),
{
...argv,
open: {
app: ['Google Chrome', '--incognito'],
},
},

).then(() => {
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"Unable to open \\"https://example.com/index.html\\" in browser: \\"{\\"app\\":[\\"Google Chrome\\",\\"--incognito\\"]}\\". If you are running in a headless environment, please do not use the --open flag"`
);
Copy link
Member

Choose a reason for hiding this comment

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

We need better test 😄

Copy link
Member Author

@EslamHiko EslamHiko Apr 1, 2020

Choose a reason for hiding this comment

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

I think the best way to test it is manually because even if I found a way to test chrome the chrome start name is different in operating systems ex :
from https://www.npmjs.com/package/open

The app name is platform dependent. Don't hard code it in reusable modules. 
For example, Chrome is google chrome on macOS, google-chrome on Linux and chrome on Windows.

This is a demo from my machine.
Peek 2020-04-01 18-49

Copy link
Member

Choose a reason for hiding this comment

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

maybe we can use other flag, not good idea keep errors in tests in that case

Copy link
Member Author

@EslamHiko EslamHiko Apr 1, 2020

Choose a reason for hiding this comment

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

@evilebottnawi what about replacing it with:
expect(opn).toBeCalledWith('https://example.com/index.html',{ app: ['Google Chrome', '--incognito'] });
This will assure that the right expected arguments has been passed to open

Copy link
Member

Choose a reason for hiding this comment

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

Good idea 👍

expect(opn).toBeCalledWith('https://example.com/index.html', {
wait: false,
});

Copy link
Member

Choose a reason for hiding this comment

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

Let's return warn check (logMock.warn)

Comment on lines 871 to 872
Object.assign(
{},
Copy link
Member

Choose a reason for hiding this comment

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

Don't need these lines.

alexander-akait
alexander-akait previously approved these changes Apr 2, 2020
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.

/cc @hiroppy

hiroppy
hiroppy previously approved these changes Apr 2, 2020
@hiroppy
Copy link
Member

hiroppy commented Apr 2, 2020

CI is failing.

@alexander-akait
Copy link
Member

/cc @EslamHiko can you fix CI?

@EslamHiko
Copy link
Member Author

@evilebottnawi Yes, I'll do it in another PR

@alexander-akait
Copy link
Member

@EslamHiko we need fix CI problems in that PR 😄

@EslamHiko
Copy link
Member Author

It's related to test/options.test.js because there's TypeError beside the ValidationError

@EslamHiko EslamHiko dismissed stale reviews from hiroppy and alexander-akait via f1eef86 April 2, 2020 11:58
@EslamHiko
Copy link
Member Author

/cc @hiroppy @evilebottnawi CI is green now 😅😅 !

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.

/cc @hiroppy

@hiroppy hiroppy merged commit adeb92e into webpack:master Apr 2, 2020
@EslamHiko EslamHiko deleted the open-object branch April 2, 2020 12:58
@snitin315
Copy link
Member

This should be documented opening as an issue for the same.

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

4 participants