Created
January 5, 2016 17:10
-
-
Save jquense/1817fb7cc0d00193249d to your computer and use it in GitHub Desktop.
in mempory webpack testing
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
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