-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support webpack-dev-server v4 (#17918)
* feat: migrate to new webpack-dev-server public api * fix: extract version check, and disallow minor releases matching `/3\./` with a starts with req. * feat: support webpack-dev-server v4 * fix webpack warning causing overlay and types * pin test dependency * fix tests that were using incorrect wewbpack configuration Co-authored-by: Ollie Relph <[email protected]>
- Loading branch information
Showing
15 changed files
with
576 additions
and
252 deletions.
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' | ||
// 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) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -2,7 +2,4 @@ module.exports = { | |
output: { | ||
publicPath: '/', | ||
}, | ||
devServer: { | ||
publicPath: '/', | ||
}, | ||
} |
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 |
---|---|---|
|
@@ -5,9 +5,6 @@ const webpackConfig = { | |
output: { | ||
publicPath: '/', | ||
}, | ||
devServer: { | ||
publicPath: '/', | ||
}, | ||
} | ||
|
||
/** | ||
|
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 |
---|---|---|
|
@@ -12,9 +12,6 @@ const webpackConfig = { | |
output: { | ||
publicPath: '/', | ||
}, | ||
devServer: { | ||
publicPath: '/', | ||
}, | ||
} | ||
|
||
/** | ||
|
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
Oops, something went wrong.