-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: support webpack-dev-server v4 #17918
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51d780b
feat: migrate to new webpack-dev-server public api
BBB 1389d15
fix: extract version check, and disallow minor releases matching `/3\…
BBB f2c37ae
feat: support webpack-dev-server v4
ZachJW34 edcbce0
fix webpack warning causing overlay and types
ZachJW34 2ccfeaa
pin test dependency
ZachJW34 f26f555
fix tests that were using incorrect wewbpack configuration
ZachJW34 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 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 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 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 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 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,14 @@ | ||
import webpackDevServerPkg from 'webpack-dev-server/package.json' | ||
|
||
export const webpackDevServerFacts = { | ||
version: webpackDevServerPkg.version, | ||
isV3 (version = webpackDevServerPkg.version) { | ||
return /^3\./.test(version) | ||
}, | ||
isV4 (version = webpackDevServerPkg.version) { | ||
return /^4\./.test(version) | ||
}, | ||
unsupported () { | ||
return Error(`@cypress/webpack-dev-server only supports webpack-dev-server v3 and v4. Found: ${webpackDevServerFacts.version}.`) | ||
}, | ||
} |
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,49 @@ | ||
const execa = require('execa') | ||
const pkg = require('./package.json') | ||
const fs = require('fs') | ||
|
||
/** | ||
* This file installs WebpackDevServer 3 and runs the tests for the dev-server. | ||
* We read package.json, update the webpack version, then re-run yarn install. | ||
* After it finishes, pass or fail, | ||
* we revert the package.json back to the original state. | ||
* | ||
* The tests for the example projects (inside of examples) run with WebpackDevServer 3. | ||
* This ensures we have some coverage for both versions. | ||
*/ | ||
const main = async () => { | ||
const originalPkg = JSON.stringify(pkg, null, 2) | ||
|
||
const resetPkg = async () => { | ||
fs.writeFileSync('package.json', originalPkg, 'utf8') | ||
await execa('yarn', ['install'], { stdio: 'inherit' }) | ||
} | ||
|
||
const checkExit = async ({ exitCode }) => { | ||
if (typeof exitCode !== 'number') { | ||
// eslint-disable-next-line no-console | ||
console.error(`Finished with missing exit code from execa (received ${exitCode})`) | ||
} | ||
|
||
await resetPkg() | ||
process.exit(exitCode) | ||
} | ||
|
||
pkg.devDependencies['webpack-dev-server'] = '^3.11.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, should we specify the exact version during CI runs to ensure the tests always us the same one? eg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense I'll pin it. |
||
// eslint-disable-next-line no-console | ||
console.log('[@cypress/webpack-dev-server]: updating package.json...') | ||
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)) | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('[@cypress/webpack-dev-server]: install dependencies...') | ||
await execa('yarn', ['install'], { stdio: 'inherit' }) | ||
|
||
const { exitCode } = await execa('yarn', ['test-all'], { stdio: 'inherit' }) | ||
|
||
await checkExit({ exitCode }) | ||
} | ||
|
||
// execute main function if called from command line | ||
if (require.main === module) { | ||
main() | ||
} |
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
19 changes: 19 additions & 0 deletions
19
npm/webpack-dev-server/test/unit/webpackDevServerFacts.spec.ts
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,19 @@ | ||
import { expect } from 'chai' | ||
import { webpackDevServerFacts } from '../../src/webpackDevServerFacts' | ||
|
||
describe('webpackDevServerFacts', () => { | ||
it('should detect v3', () => { | ||
expect(webpackDevServerFacts.isV3('3.0.0')).equals(true) | ||
expect(webpackDevServerFacts.isV3('3.1.4')).equals(true) | ||
expect(webpackDevServerFacts.isV3('4.0.0')).equals(false) | ||
expect(webpackDevServerFacts.isV3('4.3.0')).equals(false) | ||
}) | ||
|
||
it('should detect v4', () => { | ||
expect(webpackDevServerFacts.isV4('3.0.0')).equals(false) | ||
expect(webpackDevServerFacts.isV4('3.1.4')).equals(false) | ||
expect(webpackDevServerFacts.isV4('3.4.4')).equals(false) | ||
expect(webpackDevServerFacts.isV4('4.0.0')).equals(true) | ||
expect(webpackDevServerFacts.isV4('4.3.0')).equals(true) | ||
}) | ||
}) |
Oops, something went wrong.
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.
A debug message would be nice to print the version of WDS being used.