Skip to content

Instantly share code, notes, and snippets.

@jquense
Created January 5, 2016 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jquense/1817fb7cc0d00193249d to your computer and use it in GitHub Desktop.
Save jquense/1817fb7cc0d00193249d to your computer and use it in GitHub Desktop.
in mempory webpack testing
export function run(config, assert) {
return new Promise((resolve, reject) => {
let compiler = webpack(config)
let fs = compiler.outputFileSystem = new MemoryFileSystem();
compiler.run(function (err, stats) {
if (err) return reject(err)
let errors = stats.compilation.errors || [];
if (assert) expect(errors.length).to.equal(0, errors.join('\n'))
resolve({
fs,
output: getOutputFiles(fs, config.output.path),
stats,
errors,
warnings: stats.compilation.warnings || []
})
})
})
}
function getOutputFiles(fs, dir) {
let files = []
dir = path.normalize(dir)
getFiles(dir)
return files.map(f => path.normalize(f).replace(dir + path.sep, ''))
function getFiles(dir) {
fs.readdirSync(dir).forEach(filename => {
let file = path.join(dir, filename)
if (fs.statSync(file).isDirectory())
getFiles(file)
else
files.push(file)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment