UNPKG

3.07 kBJavaScriptView Raw
1var assert = require("assert");
2var fs = require("fs");
3var path = require("path");
4var exec = require('child_process').exec;
5var webpack = require("webpack");
6
7var CaseSensitivePathsPlugin = require("../");
8
9describe("CaseSensitivePathsPlugin", function() {
10
11 it("should compile and warn on wrong filename case", function(done) {
12 webpack({
13 context: path.join(__dirname, "fixtures", "wrong-case"),
14 target: "node",
15 output: {
16 path: path.join(__dirname, "js"),
17 filename: "result.js",
18 },
19 entry: "./entry",
20 plugins: [
21 new CaseSensitivePathsPlugin()
22 ]
23 }, function(err, stats) {
24 if (err) done(err);
25 assert(stats.hasErrors());
26 assert.equal(stats.hasWarnings(), false);
27 var jsonStats = stats.toJson();
28 assert.equal(jsonStats.errors.length, 1);
29
30 var error = jsonStats.errors[0].split("\n");
31 // check that the plugin produces the correct output
32 assert(error[1].indexOf('[CaseSensitivePathsPlugin]') > -1);
33 assert(error[1].indexOf('TestFile.js') > -1); // wrong file require
34 assert(error[1].indexOf('testfile.js') > -1); // actual file name
35
36 done();
37 });
38 });
39
40 it("should handle the deletion of a folder", function(done) {
41 var compiler = webpack({
42 context: path.join(__dirname, "fixtures", "deleting-folder"),
43 target: "node",
44 output: {
45 path: path.join(__dirname, "js"),
46 filename: "result.js",
47 },
48 entry: "./entry",
49 plugins: [
50 new CaseSensitivePathsPlugin()
51 ]
52 });
53
54 // create folder and file to be deleted
55 var testFolder = path.join(__dirname, "fixtures", "deleting-folder", "test-folder");
56 fs.mkdirSync(testFolder);
57 fs.writeFileSync(path.join(testFolder, "testfile.js"), "module.exports = '';");
58
59 var watchCount = 0;
60 var watcher = compiler.watch({ poll: true }, function(err, stats) {
61 if (err) done(err);
62 watchCount++;
63
64 if (watchCount === 1) {
65 assert.equal(stats.hasErrors(), false);
66 assert.equal(stats.hasWarnings(), false);
67
68 // wait for things to settle
69 setTimeout(function() {
70 // after initial compile delete test folder
71 exec("rm -r " + testFolder, function(err) { if (err) done(err); });
72 }, 100);
73 return;
74 }
75
76 if (watchCount === 2) {
77 assert(stats.hasErrors());
78 assert.equal(stats.hasWarnings(), false);
79
80 var jsonStats = stats.toJson();
81 assert.equal(jsonStats.errors.length, 1);
82
83 watcher.close(done);
84 return;
85 }
86
87 throw Error("Shouldn't be here...");
88 });
89 });
90});