forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrors.test.js
More file actions
85 lines (82 loc) · 2.65 KB
/
Errors.test.js
File metadata and controls
85 lines (82 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;
should.strictEqual(typeof stats, "object");
stats = stats.toJson({ errorDetails: false });
should.strictEqual(typeof stats, "object");
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);
var lines = errors[0].split("\n");
lines[0].should.match(/missingFile.js/);
lines[1].should.match(/^Module not found/);
lines[1].should.match(/\.\/missing/);
lines[2].should.match(/missingFile.js 4:0/);
var lines = errors[1].split("\n");
lines[0].should.match(/missingFile.js/);
lines[1].should.match(/^Module not found/);
lines[1].should.match(/\.\/dir\/missing2/);
lines[2].should.match(/missingFile.js 12:9/);
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");
lines[0].should.match(/require.extensions\.js/);
lines[1].should.match(/require.extensions is not supported by webpack/);
done();
});
});
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();
});
});
});