-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server/client): made progress option available to API (#1961)
* feat(server/client): made progress option available to API * test(client): switched snapshot test to single line confirmation * refactor(server): removed this.profile * test(client): fixed progress test css path * test(client): remove jest timeout * test(e2e): change how use of progress on client checked * test(e2e): moved css unlink into afterAll * test(e2e): use port assigner * test(client): add full progress snapshot * test(client): reg exp progress test * test(client): check end of progress updates in console * test(client): more generalized test reg exp * test(client): test to isolate ci problem * test(client): made custom progress plugin to test * test(client): new progress plugin multi handler test * test(client): more testing to identify progress problem * test(client): test with 1 progress plugin * test(client): new console.log to test sending of data * feat(server): re-add two progress plugins * test(client): revert to original changes * test(progress): added progress and profile option tests * fix(test): fix profile test port map
- Loading branch information
1 parent
fa78347
commit 56274e4
Showing
11 changed files
with
225 additions
and
18 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
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,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); | ||
}); | ||
|
||
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()); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,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'); | ||
}); | ||
}); | ||
}); |
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,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'); | ||
}); | ||
}); | ||
}); |