2013-10-11 16:42:25 +08:00
|
|
|
var should = require("should");
|
|
|
|
var path = require("path");
|
|
|
|
|
|
|
|
var webpack = require("../lib/webpack");
|
|
|
|
|
|
|
|
var base = path.join(__dirname, "fixtures", "errors");
|
|
|
|
|
|
|
|
describe("Errors", function() {
|
|
|
|
function getErrors(options, callback) {
|
|
|
|
options.context = base;
|
|
|
|
var c = webpack(options);
|
|
|
|
var files = {};
|
|
|
|
c.outputFileSystem = {
|
|
|
|
join: path.join.bind(path),
|
|
|
|
mkdirp: function(path, callback) {
|
|
|
|
callback();
|
|
|
|
},
|
|
|
|
writeFile: function(name, content, callback) {
|
|
|
|
files[name] = content.toString("utf-8");
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
c.run(function(err, stats) {
|
|
|
|
if(err) throw err;
|
2013-10-16 14:57:37 +08:00
|
|
|
should.strictEqual(typeof stats, "object");
|
2014-01-21 23:24:17 +08:00
|
|
|
stats = stats.toJson({ errorDetails: false });
|
2013-10-16 14:57:37 +08:00
|
|
|
should.strictEqual(typeof stats, "object");
|
2013-10-11 16:42:25 +08:00
|
|
|
stats.should.have.property("errors");
|
|
|
|
stats.should.have.property("warnings");
|
|
|
|
Array.isArray(stats.errors).should.be.ok;
|
|
|
|
Array.isArray(stats.warnings).should.be.ok;
|
|
|
|
callback(stats.errors, stats.warnings);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
it("should throw an error if file doesn't exist", function(done) {
|
|
|
|
getErrors({
|
|
|
|
entry: "./missingFile"
|
|
|
|
}, function(errors, warnings) {
|
|
|
|
errors.length.should.be.eql(2);
|
|
|
|
warnings.length.should.be.eql(0);
|
2014-05-26 17:36:59 +08:00
|
|
|
errors.sort();
|
2013-10-11 16:42:25 +08:00
|
|
|
var lines = errors[0].split("\n");
|
|
|
|
lines[0].should.match(/missingFile.js/);
|
|
|
|
lines[1].should.match(/^Module not found/);
|
2014-05-26 17:36:59 +08:00
|
|
|
lines[1].should.match(/\.\/dir\/missing2/);
|
|
|
|
lines[2].should.match(/missingFile.js 12:9/);
|
2013-10-11 16:42:25 +08:00
|
|
|
var lines = errors[1].split("\n");
|
|
|
|
lines[0].should.match(/missingFile.js/);
|
|
|
|
lines[1].should.match(/^Module not found/);
|
2014-05-26 17:36:59 +08:00
|
|
|
lines[1].should.match(/\.\/missing/);
|
|
|
|
lines[2].should.match(/missingFile.js 4:0/);
|
2013-10-11 16:42:25 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it("should report require.extensions as unsupported", function(done) {
|
|
|
|
getErrors({
|
|
|
|
entry: "./require.extensions"
|
|
|
|
}, function(errors, warnings) {
|
|
|
|
errors.length.should.be.eql(0);
|
|
|
|
warnings.length.should.be.eql(1);
|
|
|
|
var lines = warnings[0].split("\n");
|
2014-02-04 01:12:19 +08:00
|
|
|
lines[0].should.match(/require.extensions\.js/);
|
2013-10-11 16:42:25 +08:00
|
|
|
lines[1].should.match(/require.extensions is not supported by webpack/);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-04 01:12:19 +08:00
|
|
|
it("should throw an error if you try to require an entry point", function(done) {
|
|
|
|
getErrors({
|
|
|
|
entry: {
|
|
|
|
a: "./require-entry-point",
|
|
|
|
b: "./entry-point",
|
|
|
|
c: ["./entry-point2"]
|
|
|
|
}
|
|
|
|
}, function(errors, warnings) {
|
|
|
|
errors.length.should.be.eql(2);
|
|
|
|
warnings.length.should.be.eql(0);
|
|
|
|
var lines = errors[0].split("\n");
|
|
|
|
lines[0].should.match(/require-entry-point\.js/);
|
|
|
|
lines[1].should.match(/a dependency to an entry point is not allowed/);
|
|
|
|
lines = errors[1].split("\n");
|
|
|
|
lines[0].should.match(/require-entry-point\.js/);
|
|
|
|
lines[1].should.match(/a dependency to an entry point is not allowed/);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2014-03-31 17:33:17 +08:00
|
|
|
it("should warn about case-sensitive module names", function(done) {
|
|
|
|
getErrors({
|
|
|
|
entry: "./case-sensitive"
|
|
|
|
}, function(errors, warnings) {
|
2014-03-31 17:39:01 +08:00
|
|
|
if(errors.length === 0) {
|
|
|
|
warnings.length.should.be.eql(2);
|
2014-06-12 12:34:27 +08:00
|
|
|
warnings.sort().reverse();
|
2014-03-31 17:39:01 +08:00
|
|
|
var lines = warnings[0].split("\n");
|
|
|
|
lines[0].should.match(/file\.js/);
|
|
|
|
lines = warnings[1].split("\n");
|
|
|
|
lines[0].should.match(/FILE\.js/);
|
|
|
|
} else {
|
|
|
|
errors.length.should.be.eql(1);
|
|
|
|
warnings.length.should.be.eql(0);
|
|
|
|
}
|
2014-03-31 17:33:17 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-10-11 16:42:25 +08:00
|
|
|
});
|