-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
plugin use infrastructureLogger and output the report.html to compiler.outputFileSystem #477
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
@@ -1,42 +1,58 @@ | ||
const fs = require('fs'); | ||
const {spawn} = require('child_process'); | ||
|
||
const del = require('del'); | ||
|
||
const ROOT = `${__dirname}/dev-server`; | ||
const WEBPACK_CONFIG_PATH = `${ROOT}/webpack.config.js`; | ||
const webpackConfig = require(WEBPACK_CONFIG_PATH); | ||
const DevServer = require('webpack-dev-server'); | ||
const webpack = require('webpack'); | ||
|
||
describe('Webpack Dev Server', function () { | ||
beforeAll(deleteOutputDirectory); | ||
afterEach(deleteOutputDirectory); | ||
|
||
const timeout = 15000; | ||
jest.setTimeout(timeout); | ||
|
||
it('should save report file to the output directory', function (done) { | ||
const startedAt = Date.now(); | ||
|
||
const devServer = spawn(`${__dirname}/../node_modules/.bin/webpack-dev-server`, ['--config', WEBPACK_CONFIG_PATH], { | ||
cwd: ROOT | ||
it('should save report file to memory file system when writeToDisk is empty', async function () { | ||
expect.assertions(2); | ||
const compiler = webpack(webpackConfig); | ||
const devServer = await new Promise((resolve) => { | ||
const devServerOptions = {host: '127.0.0.1', port: 8080}; | ||
const devServer = new DevServer(compiler, devServerOptions); | ||
devServer.listen(devServerOptions.port, devServerOptions.host, () => { | ||
resolve(devServer); | ||
}); | ||
}); | ||
await new Promise((resolve) => { | ||
compiler.hooks.afterDone.tap('webpack-bundle-analyzer', resolve); | ||
}); | ||
const path = `${webpackConfig.output.path}/report.html`; | ||
expect(compiler.outputFileSystem.existsSync(path)).toBeTruthy(); | ||
expect(fs.existsSync(path)).toBeFalsy(); | ||
compiler.outputFileSystem.unlinkSync(path); | ||
await new Promise((resolve) => { | ||
devServer.close(() => { | ||
resolve(); | ||
}); | ||
}); | ||
|
||
const reportCheckIntervalId = setInterval(() => { | ||
if (fs.existsSync(`${webpackConfig.output.path}/report.html`)) { | ||
finish(); | ||
} else if (Date.now() - startedAt > timeout - 1000) { | ||
finish(`report file wasn't found in "${webpackConfig.output.path}" directory`); | ||
} | ||
}, 300); | ||
}); | ||
|
||
function finish(errorMessage) { | ||
clearInterval(reportCheckIntervalId); | ||
devServer.kill(); | ||
done(errorMessage ? new Error(errorMessage) : null); | ||
} | ||
it.skip('should save report file to the output directory when writeToDisk is true', async function () { | ||
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. Almost complete. This is the test I was talking about in our long conversation with @alexander-akait. And I need some help for this one. Currently, I skip because I do not want to waste the time in the build machine. 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. What is the problem here? 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. 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 have just figured out the reason why it always output to MemoryFileSystem when 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. The correct logic should be this this.fs = compiler.webpack ? compiler.outputFileSystem : require('fs');
if ((process.env.WEBPACK_DEV_SERVER === 'true' || process.env.WEBPACK_SERVE === 'true')
&& (compiler.options.devServer?.writeToDisk || compiler.options.devServer?.devMiddleware?.writeToDisk)) {
this.fs = require('fs');
} 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. No, it is not problem with 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. Then how to get {writeToDisk: true} works if it is not the problem? |
||
expect.assertions(2); | ||
const compiler = webpack(webpackConfig); | ||
const devServer = await new Promise((resolve) => { | ||
const devServerOptions = {host: '127.0.0.1', port: 8080, writeToDisk: true}; | ||
const devServer = new DevServer(compiler, devServerOptions); | ||
devServer.listen(devServerOptions.port, devServerOptions.host, () => { | ||
resolve(devServer); | ||
}); | ||
}); | ||
await new Promise((resolve) => { | ||
compiler.hooks.afterDone.tap('webpack-bundle-analyzer', resolve); | ||
}); | ||
const path = `${webpackConfig.output.path}/report.html`; | ||
expect(compiler.outputFileSystem.existsSync(path)).toBeTruthy(); | ||
expect(fs.existsSync(path)).toBeTruthy(); | ||
compiler.outputFileSystem.unlinkSync(path); | ||
return await new Promise((resolve) => { | ||
devServer.close(() => { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
function deleteOutputDirectory() { | ||
del.sync(webpackConfig.output.path); | ||
} |
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.
So,
logLevel
option won't work anymore?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.
As the launch is always from webpack, it will use webpack.config.js level setting. See https://v4.webpack.js.org/configuration/stats/#statslogging and https://webpack.js.org/configuration/stats/#statslogging
bin/analyzer still can have its own log level
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.
We need to update readme in this case and remove
logLevel
option from this list as it will be ignored.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 have just realized for webpack compiler without using
hooks
, it will fallback to your own logger. I do not know which version is not usinghooks