-
-
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/client): made progress option available to API #1961
Changes from all commits
4a51af2
f956b3f
0ccfce1
ef85039
94ef8e7
96c9cd8
adbb746
10a98d3
3744482
b66dd47
e688449
fe1db5d
08f79ff
33bf227
357df68
ce5603e
ea99c9f
9d9aa24
ad7a5b5
8faed38
4741e21
0b898ec
0eaae0f
ae7d586
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,23 @@ describe('CLI', () => { | |
.then((output) => { | ||
expect(output.code).toEqual(0); | ||
expect(output.stderr.includes('0% compiling')).toBe(true); | ||
// should not profile | ||
expect( | ||
output.stderr.includes('ms after chunk modules optimization') | ||
).toBe(false); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('--progress --profile', (done) => { | ||
testBin('--progress --profile') | ||
.then((output) => { | ||
expect(output.code).toEqual(0); | ||
// should profile | ||
expect( | ||
output.stderr.includes('ms after chunk modules optimization') | ||
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. I think better use here snapshot for easy updating, changing string is more difficult 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. I will try, last time output did not always match though 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. We can implement helper for tests what remove unnecessary stuff from output to keep snapshot small and testable 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.
I will try that.
It could be undefined though. 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. Thanks, you are right 👍 |
||
).toBe(true); | ||
done(); | ||
}) | ||
.catch(done); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable | ||
no-undef | ||
*/ | ||
const fs = require('fs'); | ||
const { resolve } = require('path'); | ||
const testServer = require('../helpers/test-server'); | ||
const reloadConfig = require('../fixtures/reload-config/webpack.config'); | ||
const runBrowser = require('../helpers/run-browser'); | ||
const port = require('../ports-map').Progress; | ||
|
||
const cssFilePath = resolve(__dirname, '../fixtures/reload-config/main.css'); | ||
|
||
describe('client progress', () => { | ||
describe('using hot', () => { | ||
beforeAll((done) => { | ||
fs.writeFileSync( | ||
cssFilePath, | ||
'body { background-color: rgb(0, 0, 255); }' | ||
); | ||
const options = { | ||
port, | ||
host: '0.0.0.0', | ||
inline: true, | ||
hot: true, | ||
progress: true, | ||
watchOptions: { | ||
poll: 500, | ||
}, | ||
}; | ||
testServer.startAwaitingCompilation(reloadConfig, options, done); | ||
}); | ||
|
||
afterAll((done) => { | ||
fs.unlinkSync(cssFilePath); | ||
testServer.close(done); | ||
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. fs.unlinkSync(cssFilePath); 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. need to add 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. done |
||
}); | ||
|
||
describe('on browser client', () => { | ||
it('should console.log progress', (done) => { | ||
runBrowser().then(({ page, browser }) => { | ||
const res = []; | ||
page.waitForNavigation({ waitUntil: 'load' }).then(() => { | ||
fs.writeFileSync( | ||
cssFilePath, | ||
'body { background-color: rgb(255, 0, 0); }' | ||
); | ||
page.waitFor(10000).then(() => { | ||
browser.close().then(() => { | ||
// check that there is some percentage progress output | ||
const regExp = /^\[WDS\] [0-9]{1,3}% - /; | ||
const match = res.find((line) => { | ||
return regExp.test(line); | ||
}); | ||
// eslint-disable-next-line no-undefined | ||
expect(match).not.toEqual(undefined); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
page.goto(`http://localhost:${port}/main`); | ||
page.on('console', (data) => { | ||
res.push(data.text()); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
const webpack = require('webpack'); | ||
const Server = require('../../lib/Server'); | ||
const config = require('../fixtures/simple-config/webpack.config'); | ||
const port = require('../ports-map')['profile-option']; | ||
|
||
describe('profile', () => { | ||
describe('output', () => { | ||
let mockStderr; | ||
|
||
beforeAll(() => { | ||
mockStderr = jest | ||
.spyOn(process.stderr, 'write') | ||
.mockImplementation(() => {}); | ||
}); | ||
|
||
it('should show percentage progress with profile data', (done) => { | ||
const compiler = webpack(config); | ||
const server = new Server(compiler, { | ||
port, | ||
// profile will only have an effect when progress is enabled | ||
progress: true, | ||
profile: true, | ||
}); | ||
|
||
compiler.hooks.done.tap('webpack-dev-server', () => { | ||
const calls = mockStderr.mock.calls; | ||
mockStderr.mockRestore(); | ||
let foundProgress = false; | ||
let foundProfile = false; | ||
calls.forEach((call) => { | ||
if (call[0].includes('0% compiling')) { | ||
foundProgress = true; | ||
} | ||
|
||
// this is an indicator that the profile option is enabled, | ||
// so we should expect to find it in stderr since profile is enabled | ||
if (call[0].includes('ms after chunk modules optimization')) { | ||
foundProfile = true; | ||
} | ||
}); | ||
expect(foundProgress).toBeTruthy(); | ||
expect(foundProfile).toBeTruthy(); | ||
|
||
server.close(done); | ||
}); | ||
|
||
compiler.run(() => {}); | ||
server.listen(port, 'localhost'); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
const webpack = require('webpack'); | ||
const Server = require('../../lib/Server'); | ||
const config = require('../fixtures/simple-config/webpack.config'); | ||
const port = require('../ports-map')['progress-option']; | ||
|
||
describe('progress', () => { | ||
describe('output', () => { | ||
let mockStderr; | ||
|
||
beforeAll(() => { | ||
mockStderr = jest | ||
.spyOn(process.stderr, 'write') | ||
.mockImplementation(() => {}); | ||
}); | ||
|
||
it('should show percentage progress without profile data', (done) => { | ||
const compiler = webpack(config); | ||
const server = new Server(compiler, { | ||
port, | ||
progress: true, | ||
}); | ||
|
||
compiler.hooks.done.tap('webpack-dev-server', () => { | ||
const calls = mockStderr.mock.calls; | ||
mockStderr.mockRestore(); | ||
let foundProgress = false; | ||
let foundProfile = false; | ||
calls.forEach((call) => { | ||
if (call[0].includes('0% compiling')) { | ||
foundProgress = true; | ||
} | ||
|
||
// this is an indicator that the profile option is enabled, | ||
// so we should expect to not find it in stderr since it is not enabled | ||
if (call[0].includes('ms after chunk modules optimization')) { | ||
foundProfile = true; | ||
} | ||
}); | ||
expect(foundProgress).toBeTruthy(); | ||
expect(foundProfile).toBeFalsy(); | ||
|
||
server.close(done); | ||
}); | ||
|
||
compiler.run(() => {}); | ||
server.listen(port, 'localhost'); | ||
}); | ||
}); | ||
}); |
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 really need two plugins? I think we can use one instance of plugin
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 2 are needed since one supplies a custom handler but the other uses the default handler: https://github.com/webpack/webpack/blob/master/lib/ProgressPlugin.js#L103
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 need investigate this and tests this, looks like we setup two progress plugin and it can be invalid usage
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 Wouldn't it be the equivalent of two plugins tapping into the exact same events? Assuming the plugin was made properly.
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 Are my changes here causing the Windows CI problems? I'm unsure why progress plugin outputs stuff to
stderr
, but maybe that is causing a problem? https://github.com/webpack/webpack/blob/master/lib/ProgressPlugin.js#L49There 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.
No need
!!
we already validate this only as boolean, so no need convert to boolean again