-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(server): check that serverMode implementation is correct #2051
Open
knagaitsev
wants to merge
4
commits into
webpack:master
Choose a base branch
from
knagaitsev:serverMode-implementation-check
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
62b5ba5
feat(server): check for serverMode implementation problems
knagaitsev 557f7e8
test(server): remove extends BaseServer requirement
knagaitsev 2b10ece
feat(server): test socket server implementation with schema utils
knagaitsev cf6e74a
fix(server): allow any properties for server impl schema
knagaitsev 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
27 changes: 27 additions & 0 deletions
27
lib/schemas/utils/socketServerImplementationPrototype.json
This file contains 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 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"constructor": { | ||
"instanceof": "Function" | ||
}, | ||
"send": { | ||
"instanceof": "Function" | ||
}, | ||
"close": { | ||
"instanceof": "Function" | ||
}, | ||
"onConnection": { | ||
"instanceof": "Function" | ||
} | ||
}, | ||
"errorMessage": { | ||
"properties": { | ||
"constructor": "- serverMode must have a constructor that takes a single server argument and calls super(server) on the superclass BaseServer, found via require('webpack-dev-server/lib/servers/BaseServer')", | ||
"send": "- serverMode must have a send(connection, message) method that sends the message string to the provided client connection object", | ||
"close": "- serverMode must have a close(connection) method that closes the provided client connection object", | ||
"onConnection": "- serverMode must have a onConnection(f) method that calls f(connection) whenever a new client connection is made" | ||
} | ||
}, | ||
"required": ["constructor", "send", "close", "onConnection"], | ||
"additionalProperties": false | ||
} | ||
This file contains 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
37 changes: 37 additions & 0 deletions
37
test/server/utils/__snapshots__/getSocketServerImplementation.test.js.snap
This file contains 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,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getSocketServerImplementation util should throw with serverMode (bad path) 1`] = `[Error: serverMode must be a string denoting a default implementation (e.g. 'sockjs'), a full path to a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer) via require.resolve(...), or the class itself which extends BaseServer]`; | ||
|
||
exports[`getSocketServerImplementation util should throw with serverMode (no close, onConnection methods) 1`] = ` | ||
[ValidationError: webpack Dev Server Invalid Options | ||
|
||
options should have required property 'close' | ||
options should have required property 'onConnection' | ||
] | ||
`; | ||
|
||
exports[`getSocketServerImplementation util should throw with serverMode (no constructor, send, close, onConnection methods) 1`] = ` | ||
[ValidationError: webpack Dev Server Invalid Options | ||
|
||
options should have required property 'constructor' | ||
options should have required property 'send' | ||
options should have required property 'close' | ||
options should have required property 'onConnection' | ||
] | ||
`; | ||
|
||
exports[`getSocketServerImplementation util should throw with serverMode (no onConnection method) 1`] = ` | ||
[ValidationError: webpack Dev Server Invalid Options | ||
|
||
options should have required property 'onConnection' | ||
] | ||
`; | ||
|
||
exports[`getSocketServerImplementation util should throw with serverMode (no send, close, onConnection methods) 1`] = ` | ||
[ValidationError: webpack Dev Server Invalid Options | ||
|
||
options should have required property 'send' | ||
options should have required property 'close' | ||
options should have required property 'onConnection' | ||
] | ||
`; |
This file contains 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
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.
I think we can have one schema (put this inside original schema) for better maintenance
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.
@evilebottnawi The problem is that I couldn't find a way to test the prototype of a function with
schema-utils
when it matched"instanceof": "Function"
. I think it only looks at"properties"
if the thing in question matches"type": "object"
, hence why I passServerImplementation.prototype
into the schemaThere 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.
Unless you just mean make
options.json
into something like:But that could be a breaking change if something else is using this schema.
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.
hm we can rewrite schema-utils and allow to define own validator (where we can implement any logic), i will take care about this, let's keep this PR open, it is not high priority because we can improve documentation