forked from webpack-contrib/webpack-bundle-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
path.join
instead of path.resolve
to support bundle names sta…
…rting with `/`
- Loading branch information
Showing
13 changed files
with
836 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
{ | ||
"extends": "../.eslintrc.json", | ||
"env": { | ||
"mocha": true | ||
"mocha": true, | ||
"browser": true | ||
}, | ||
"globals": { | ||
"sinon": true, | ||
"expect": true, | ||
"makeWebpackConfig": true, | ||
"webpackCompile": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output |
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,42 @@ | ||
const chai = require('chai'); | ||
const webpack = require('webpack'); | ||
|
||
chai.use(require('chai-subset')); | ||
|
||
global.expect = chai.expect; | ||
global.sinon = require('sinon'); | ||
global.webpackCompile = webpackCompile; | ||
global.makeWebpackConfig = makeWebpackConfig; | ||
|
||
const BundleAnalyzerPlugin = require('../lib/BundleAnalyzerPlugin'); | ||
|
||
function webpackCompile(config) { | ||
return new Promise((resolve, reject) => { | ||
webpack(config, err => { | ||
if (err) return reject(err); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
function makeWebpackConfig(opts) { | ||
opts = { | ||
analyzerOpts: { | ||
analyzerMode: 'static', | ||
openAnalyzer: false | ||
}, | ||
...opts | ||
}; | ||
|
||
return { | ||
context: __dirname, | ||
entry: './src', | ||
output: { | ||
path: `${__dirname}/output`, | ||
filename: 'bundle.js' | ||
}, | ||
plugins: [ | ||
new BundleAnalyzerPlugin(opts.analyzerOpts) | ||
] | ||
}; | ||
} |
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 @@ | ||
module.exports = 'module a'; |
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 @@ | ||
module.exports = 'module a'; |
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 @@ | ||
module.exports = 'module b'; |
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,3 @@ | ||
require('./a'); | ||
require('./b'); | ||
require('./a-clone'); |
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,38 @@ | ||
const fs = require('fs'); | ||
const del = require('del'); | ||
const Nightmare = require('nightmare'); | ||
const nightmare = Nightmare(); | ||
|
||
describe('Webpack config', function () { | ||
before(function () { | ||
del.sync(`${__dirname}/output`); | ||
this.clock = sinon.useFakeTimers(); | ||
}); | ||
|
||
afterEach(function () { | ||
del.sync(`${__dirname}/output`); | ||
}); | ||
|
||
after(function () { | ||
this.clock.restore(); | ||
}); | ||
|
||
it('with head slash in bundle filename should be supported', async function () { | ||
const config = makeWebpackConfig(); | ||
|
||
config.output.filename = '/bundle.js'; | ||
|
||
await webpackCompile(config); | ||
this.clock.tick(1000); | ||
|
||
expect(fs.existsSync(`${__dirname}/output/bundle.js`)).to.be.true; | ||
expect(fs.existsSync(`${__dirname}/output/report.html`)).to.be.true; | ||
const chartData = await nightmare | ||
.goto(`file://${__dirname}/output/report.html`) | ||
.evaluate(() => window.chartData); | ||
expect(chartData[0]).to.containSubset({ | ||
parsedSize: 213, | ||
statSize: 141 | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.