|
| 1 | +/*globals describe it */ |
| 2 | +require("should"); |
| 3 | +var path = require("path"); |
| 4 | +var fs = require("fs"); |
| 5 | + |
| 6 | +var webpack = require("../lib/webpack"); |
| 7 | + |
| 8 | +var base = path.join(__dirname, "fixtures", "stats"); |
| 9 | +var tests = fs.readdirSync(base); |
| 10 | + |
| 11 | +describe("Stats", function() { |
| 12 | + tests.forEach(function(testName) { |
| 13 | + it("should print correct stats for " + testName, function(done) { |
| 14 | + var options = { |
| 15 | + entry: "./index" |
| 16 | + }; |
| 17 | + if(fs.existsSync(path.join(base, testName, "webpack.config.js"))) { |
| 18 | + options = require(path.join(base, testName, "webpack.config.js")); |
| 19 | + } |
| 20 | + options.context = path.join(base, testName); |
| 21 | + var c = webpack(options); |
| 22 | + var files = {}; |
| 23 | + c.outputFileSystem = { |
| 24 | + join: path.join.bind(path), |
| 25 | + mkdirp: function(path, callback) { |
| 26 | + callback(); |
| 27 | + }, |
| 28 | + writeFile: function(name, content, callback) { |
| 29 | + files[name] = content.toString("utf-8"); |
| 30 | + callback(); |
| 31 | + } |
| 32 | + }; |
| 33 | + c.apply(new webpack.optimize.OccurrenceOrderPlugin()); |
| 34 | + c.run(function(err, stats) { |
| 35 | + if(err) return done(err); |
| 36 | + var actual = stats.toString({ |
| 37 | + colors: false |
| 38 | + }); |
| 39 | + (typeof actual).should.be.eql("string"); |
| 40 | + actual = actual.replace(/[0-9]+(\s?ms)/g, "X$1"); |
| 41 | + var expected = fs.readFileSync(path.join(base, testName, "expected.txt"), "utf-8"); |
| 42 | + if(actual !== expected) { |
| 43 | + fs.writeFileSync(path.join(base, testName, "actual.txt"), actual, "utf-8"); |
| 44 | + } else if(fs.existsSync(path.join(base, testName, "actual.txt"))) { |
| 45 | + fs.unlinkSync(path.join(base, testName, "actual.txt")); |
| 46 | + } |
| 47 | + actual.should.be.eql(expected); |
| 48 | + done(); |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments