-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: write file directly from the plugin
- Loading branch information
Showing
4 changed files
with
107 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ spec/webpack-out | |
yarn.lock | ||
.nyc_output | ||
coverage | ||
spec/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
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,96 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var _ = require('lodash'); | ||
var webpack = require('webpack'); | ||
var MemoryFileSystem = require('memory-fs'); | ||
var rimraf = require('rimraf'); | ||
|
||
var ManifestPlugin = require('../index.js'); | ||
|
||
function webpackConfig(webpackOpts, opts) { | ||
return _.merge({ | ||
plugins: [ | ||
new ManifestPlugin(opts.manifestOptions) | ||
] | ||
}, webpackOpts); | ||
} | ||
|
||
function webpackCompile(config, compilerOps, cb) { | ||
var compiler = webpack(config); | ||
|
||
_.assign(compiler, compilerOps); | ||
|
||
compiler.run(function(err, stats){ | ||
expect(err).toBeFalsy(); | ||
expect(stats.hasErrors()).toBe(false); | ||
|
||
cb(stats); | ||
}); | ||
}; | ||
|
||
describe('ManifestPlugin using real fs', function() { | ||
beforeEach(function() { | ||
rimraf.sync(path.join(__dirname, 'output/single-file')); | ||
}); | ||
|
||
describe('basic behavior', function() { | ||
it('outputs a manifest of one file', function (done) { | ||
webpackCompile({ | ||
context: __dirname, | ||
output: { | ||
filename: '[name].js', | ||
path: path.join(__dirname, 'output/single-file') | ||
}, | ||
entry: './fixtures/file.js', | ||
plugins: [ | ||
new ManifestPlugin() | ||
] | ||
}, {}, function() { | ||
var manifest = JSON.parse(fs.readFileSync(path.join(__dirname, 'output/single-file/manifest.json'))) | ||
|
||
expect(manifest).toBeDefined(); | ||
expect(manifest).toEqual({ | ||
'main.js': 'main.js' | ||
}); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('ManifestPlugin with memory-fs', function() { | ||
describe('writeToFileEmit', function() { | ||
beforeEach(function() { | ||
rimraf.sync(path.join(__dirname, 'output/emit')); | ||
}); | ||
|
||
it('outputs a manifest of one file', function (done) { | ||
webpackCompile({ | ||
context: __dirname, | ||
output: { | ||
filename: '[name].js', | ||
path: path.join(__dirname, 'output/emit') | ||
}, | ||
entry: './fixtures/file.js', | ||
plugins: [ | ||
new ManifestPlugin({ | ||
writeToFileEmit: true | ||
}) | ||
] | ||
}, { | ||
outputFileSystem: new MemoryFileSystem() | ||
}, function() { | ||
var manifest = JSON.parse(fs.readFileSync(path.join(__dirname, 'output/emit/manifest.json'))) | ||
|
||
expect(manifest).toBeDefined(); | ||
expect(manifest).toEqual({ | ||
'main.js': 'main.js' | ||
}); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |