Skip to content

Commit

Permalink
fix: support webpack@5 (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Dec 18, 2019
1 parent 3203688 commit 8f89c01
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 192 deletions.
67 changes: 48 additions & 19 deletions azure-pipelines.yml
Expand Up @@ -2,10 +2,13 @@ trigger:
- master
- next

variables:
npm_config_cache: $(Pipeline.Workspace)/.npm

jobs:
- job: Lint
pool:
vmImage: ubuntu-16.04
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
Expand All @@ -20,10 +23,12 @@ jobs:
node -v
npm -v
displayName: 'Print versions'
- task: Npm@1
- task: CacheBeta@1
inputs:
command: custom
customCommand: ci
key: npm | $(Agent.OS) | package-lock.json
path: $(npm_config_cache)
displayName: 'Cache npm'
- script: npm ci
displayName: 'Install dependencies'
- script: npm run lint
displayName: 'Run lint'
Expand All @@ -34,10 +39,13 @@ jobs:

- job: Linux
pool:
vmImage: ubuntu-16.04
vmImage: ubuntu-latest
strategy:
maxParallel: 5
maxParallel: 6
matrix:
node-13:
node_version: ^13.0.0
webpack_version: latest
node-12:
node_version: ^12.0.0
webpack_version: latest
Expand All @@ -50,6 +58,9 @@ jobs:
node-6:
node_version: ^6.9.0
webpack_version: latest
node-10-canary:
node_version: ^10.13.0
webpack_version: next
steps:
- task: NodeTool@0
inputs:
Expand All @@ -64,10 +75,12 @@ jobs:
node -v
npm -v
displayName: 'Print versions'
- task: Npm@1
- task: CacheBeta@1
inputs:
command: custom
customCommand: ci
key: npm | $(Agent.OS) | package-lock.json
path: $(npm_config_cache)
displayName: 'Cache npm'
- script: npm ci
displayName: 'Install dependencies'
- script: npm i webpack@$(webpack_version)
displayName: 'Install "webpack@$(webpack_version)"'
Expand All @@ -85,10 +98,13 @@ jobs:

- job: macOS
pool:
vmImage: macOS-10.14
vmImage: macOS-latest
strategy:
maxParallel: 5
maxParallel: 6
matrix:
node-13:
node_version: ^13.0.0
webpack_version: latest
node-12:
node_version: ^12.0.0
webpack_version: latest
Expand All @@ -101,6 +117,9 @@ jobs:
node-6:
node_version: ^6.9.0
webpack_version: latest
node-10-canary:
node_version: ^10.13.0
webpack_version: next
steps:
- task: NodeTool@0
inputs:
Expand All @@ -115,10 +134,12 @@ jobs:
node -v
npm -v
displayName: 'Print versions'
- task: Npm@1
- task: CacheBeta@1
inputs:
command: custom
customCommand: ci
key: npm | $(Agent.OS) | package-lock.json
path: $(npm_config_cache)
displayName: 'Cache npm'
- script: npm ci
displayName: 'Install dependencies'
- script: npm i webpack@$(webpack_version)
displayName: 'Install "webpack@$(webpack_version)"'
Expand All @@ -136,10 +157,13 @@ jobs:

- job: Windows
pool:
vmImage: windows-2019
vmImage: windows-latest
strategy:
maxParallel: 5
maxParallel: 6
matrix:
node-13:
node_version: ^13.0.0
webpack_version: latest
node-12:
node_version: ^12.0.0
webpack_version: latest
Expand All @@ -152,6 +176,9 @@ jobs:
node-6:
node_version: ^6.9.0
webpack_version: latest
node-10-canary:
node_version: ^10.13.0
webpack_version: next
steps:
- script: 'git config --global core.autocrlf input'
displayName: 'Config git core.autocrlf'
Expand All @@ -169,10 +196,12 @@ jobs:
node -v
npm -v
displayName: 'Print versions'
- task: Npm@1
- task: CacheBeta@1
inputs:
command: custom
customCommand: ci
key: npm | $(Agent.OS) | package-lock.json
path: $(npm_config_cache)
displayName: 'Cache npm'
- script: npm ci
displayName: 'Install dependencies'
- script: npm i webpack@$(webpack_version)
displayName: 'Install "webpack@$(webpack_version)"'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -114,7 +114,7 @@
"webpack-cli": "^3.3.10"
},
"peerDependencies": {
"webpack": "^4.0.0"
"webpack": "^4.0.0 || ^5.0.0"
},
"author": "Tobias Koppers @sokra",
"bugs": "https://github.com/webpack/webpack-dev-server/issues",
Expand Down
20 changes: 15 additions & 5 deletions test/cli/cli.test.js
Expand Up @@ -176,8 +176,9 @@ describe('CLI', () => {

it('should exit the process when SIGINT is detected, even before the compilation is done', (done) => {
const cliPath = resolve(__dirname, '../../bin/webpack-dev-server.js');
const examplePath = resolve(__dirname, '../../examples/cli/public');
const cp = execa('node', [cliPath], { cwd: examplePath });
const simpleConfig = resolve(__dirname, '../fixtures/simple-config');
const cp = execa('node', [cliPath], { cwd: simpleConfig });

let killed = false;

cp.stdout.on('data', () => {
Expand All @@ -197,11 +198,13 @@ describe('CLI', () => {

it('should use different random port when multiple instances are started on different processes', (done) => {
const cliPath = resolve(__dirname, '../../bin/webpack-dev-server.js');
const examplePath = resolve(__dirname, '../../examples/cli/public');
const simpleConfig = resolve(__dirname, '../fixtures/simple-config');

const cp = execa('node', [cliPath, '--colors=false'], { cwd: examplePath });
const cp = execa('node', [cliPath, '--colors=false'], {
cwd: simpleConfig,
});
const cp2 = execa('node', [cliPath, '--colors=false'], {
cwd: examplePath,
cwd: simpleConfig,
});

const runtime = {
Expand All @@ -220,22 +223,27 @@ describe('CLI', () => {
const portMatch = /Project is running at http:\/\/localhost:(\d*)\//.exec(
bits
);

if (portMatch) {
runtime.cp.port = portMatch[1];
}

if (/Compiled successfully/.test(bits)) {
expect(cp.pid !== 0).toBe(true);
cp.kill('SIGINT');
}
});

cp2.stdout.on('data', (data) => {
const bits = data.toString();
const portMatch = /Project is running at http:\/\/localhost:(\d*)\//.exec(
bits
);

if (portMatch) {
runtime.cp2.port = portMatch[1];
}

if (/Compiled successfully/.test(bits)) {
expect(cp.pid !== 0).toBe(true);
cp2.kill('SIGINT');
Expand All @@ -249,8 +257,10 @@ describe('CLI', () => {
done();
}
});

cp2.on('exit', () => {
runtime.cp2.done = true;

if (runtime.cp.done) {
expect(runtime.cp.port !== runtime.cp2.port).toBe(true);
done();
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/ClientOptions.test.js
Expand Up @@ -324,7 +324,8 @@ describe('Client console.log', () => {
});
})
.then(() => {
expect(res).toMatchSnapshot();
// Order doesn't matter, maybe we should improve that in future
expect(res.sort()).toMatchSnapshot();
done();
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/Iframe.test.js
Expand Up @@ -84,7 +84,8 @@ describe('Client iframe console.log', () => {
});
})
.then(() => {
expect(res).toMatchSnapshot();
// Order doesn't matter, maybe we should improve that in future
expect(res.sort()).toMatchSnapshot();
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/__snapshots__/ClientOptions.test.js.snap
Expand Up @@ -15,8 +15,8 @@ Array [

exports[`Client console.log hot enabled 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[HMR] Waiting for update signal from WDS...",
"[WDS] Hot Module Replacement enabled.",
"[WDS] Live Reloading enabled.",
]
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/__snapshots__/Iframe.test.js.snap
Expand Up @@ -15,8 +15,8 @@ Array [

exports[`Client iframe console.log hot enabled 1`] = `
Array [
"[HMR] Waiting for update signal from WDS...",
"Hey.",
"[HMR] Waiting for update signal from WDS...",
"[WDS] Hot Module Replacement enabled.",
"[WDS] Live Reloading enabled.",
]
Expand Down
70 changes: 31 additions & 39 deletions test/server/Server.test.js
Expand Up @@ -39,9 +39,9 @@ describe('Server', () => {
return relative('.', p).split(sep);
})
).toMatchSnapshot();
expect(
server.middleware.context.compiler.options.plugins
).toMatchSnapshot();
expect(server.middleware.context.compiler.options.plugins).toEqual([
new webpack.HotModuleReplacementPlugin(),
]);

compiler.hooks.done.tap('webpack-dev-server', () => {
server.close(done);
Expand All @@ -64,9 +64,9 @@ describe('Server', () => {
return relative('.', p).split(sep);
})
).toMatchSnapshot();
expect(
server.middleware.context.compiler.options.plugins
).toMatchSnapshot();
expect(server.middleware.context.compiler.options.plugins).toEqual([
new webpack.HotModuleReplacementPlugin(),
]);

compiler.hooks.done.tap('webpack-dev-server', () => {
server.close(done);
Expand All @@ -78,14 +78,6 @@ describe('Server', () => {

// issue: https://github.com/webpack/webpack-dev-server/issues/1724
describe('express.static.mine.types', () => {
beforeEach(() => {
jest.resetModules();
});

afterEach(() => {
jest.unmock('express');
});

it("should success even if mine.types doesn't exist", (done) => {
jest.mock('express', () => {
const data = jest.requireActual('express');
Expand Down Expand Up @@ -118,31 +110,6 @@ describe('Server', () => {
});
});

describe('WEBPACK_DEV_SERVER environment variable', () => {
const OLD_ENV = process.env;

beforeEach(() => {
// this is important - it clears the cache
jest.resetModules();

process.env = { ...OLD_ENV };

delete process.env.WEBPACK_DEV_SERVER;
});

afterEach(() => {
process.env = OLD_ENV;
});

it('should be present', () => {
expect(process.env.WEBPACK_DEV_SERVER).toBeUndefined();

require('../../lib/Server');

expect(process.env.WEBPACK_DEV_SERVER).toBe(true);
});
});

describe('Invalidate Callback', () => {
describe('Testing callback functions on calling invalidate without callback', () => {
it('should be `noop` (the default callback function)', (done) => {
Expand Down Expand Up @@ -178,4 +145,29 @@ describe('Server', () => {
});
});
});

describe('WEBPACK_DEV_SERVER environment variable', () => {
const OLD_ENV = process.env;

beforeEach(() => {
// this is important - it clears the cache
jest.resetModules();

process.env = { ...OLD_ENV };

delete process.env.WEBPACK_DEV_SERVER;
});

afterEach(() => {
process.env = OLD_ENV;
});

it('should be present', () => {
expect(process.env.WEBPACK_DEV_SERVER).toBeUndefined();

require('../../lib/Server');

expect(process.env.WEBPACK_DEV_SERVER).toBe(true);
});
});
});

0 comments on commit 8f89c01

Please sign in to comment.