-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
refactor(server): add updateOptions API helper #2117
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
644b527
refactor(server): add update options api helper
knagaitsev 3690dea
Merge branch 'master' into updateOptions-helper
hiroppy d19861d
test(server): removed global require eslint comments
knagaitsev b4fd742
refactor(server): switch update options to normalize options
knagaitsev 93e870f
Merge branch 'master' into updateOptions-helper
evilebottnawi 939e715
Merge branch 'master' into updateOptions-helper
hiroppy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable | ||
no-undefined | ||
*/ | ||
|
||
function updateOptions(compiler, options) { | ||
// Setup default value | ||
options.contentBase = | ||
options.contentBase !== undefined ? options.contentBase : process.cwd(); | ||
|
||
// set serverMode default | ||
if (options.serverMode === undefined) { | ||
options.serverMode = 'sockjs'; | ||
} | ||
|
||
// set clientMode default | ||
if (options.clientMode === undefined) { | ||
options.clientMode = 'sockjs'; | ||
} | ||
|
||
if (!options.watchOptions) { | ||
options.watchOptions = {}; | ||
} | ||
} | ||
|
||
module.exports = updateOptions; |
40 changes: 40 additions & 0 deletions
40
test/server/utils/__snapshots__/updateOptions.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`updateOptions contentBase array should set correct options 1`] = ` | ||
Object { | ||
"clientMode": "sockjs", | ||
"contentBase": Array [ | ||
"/path/to/dist1", | ||
"/path/to/dist2", | ||
], | ||
"serverMode": "sockjs", | ||
"watchOptions": Object {}, | ||
} | ||
`; | ||
|
||
exports[`updateOptions contentBase string should set correct options 1`] = ` | ||
Object { | ||
"clientMode": "sockjs", | ||
"contentBase": "/path/to/dist", | ||
"serverMode": "sockjs", | ||
"watchOptions": Object {}, | ||
} | ||
`; | ||
|
||
exports[`updateOptions no options should set correct options 1`] = ` | ||
Object { | ||
"clientMode": "sockjs", | ||
"serverMode": "sockjs", | ||
"watchOptions": Object {}, | ||
} | ||
`; | ||
|
||
exports[`updateOptions watchOptions should set correct options 1`] = ` | ||
Object { | ||
"clientMode": "sockjs", | ||
"serverMode": "sockjs", | ||
"watchOptions": Object { | ||
"poll": true, | ||
}, | ||
} | ||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
|
||
const webpack = require('webpack'); | ||
const updateOptions = require('../../../lib/utils/updateOptions'); | ||
|
||
describe('updateOptions', () => { | ||
const cases = [ | ||
{ | ||
title: 'no options', | ||
multiCompiler: false, | ||
options: {}, | ||
optionsResults: null, | ||
}, | ||
{ | ||
title: 'contentBase string', | ||
multiCompiler: false, | ||
options: { | ||
contentBase: '/path/to/dist', | ||
}, | ||
optionsResults: null, | ||
}, | ||
{ | ||
title: 'contentBase array', | ||
multiCompiler: false, | ||
options: { | ||
contentBase: ['/path/to/dist1', '/path/to/dist2'], | ||
}, | ||
optionsResults: null, | ||
}, | ||
{ | ||
title: 'watchOptions', | ||
multiCompiler: false, | ||
options: { | ||
watchOptions: { | ||
poll: true, | ||
}, | ||
}, | ||
optionsResults: null, | ||
}, | ||
]; | ||
|
||
cases.forEach((data) => { | ||
describe(data.title, () => { | ||
let compiler; | ||
beforeAll(() => { | ||
let webpackConfig; | ||
if (data.multiCompiler) { | ||
webpackConfig = require('../../fixtures/multi-compiler-config/webpack.config'); | ||
} else { | ||
webpackConfig = require('../../fixtures/simple-config/webpack.config'); | ||
} | ||
|
||
compiler = webpack(webpackConfig); | ||
}); | ||
|
||
it('should set correct options', () => { | ||
const originalContentBase = data.options.contentBase; | ||
updateOptions(compiler, data.options); | ||
if (data.optionsResults) { | ||
expect(data.options).toEqual(data.optionsResults); | ||
} else { | ||
if (data.options.contentBase !== originalContentBase) { | ||
// we don't want this in the snapshot, because it is | ||
// the current working directory | ||
expect(data.options.contentBase).toEqual(process.cwd()); | ||
delete data.options.contentBase; | ||
} | ||
expect(data.options).toMatchSnapshot(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Loonride maybe
normalizeOptions
better name here? Anyway code looks good