|
| 1 | +var should = require("should"); |
| 2 | +var sinon = require("sinon"); |
| 3 | +var PluginEnvironment = require("./helpers/PluginEnvironment"); |
| 4 | +var applyPluginWithOptions = require("./helpers/applyPluginWithOptions"); |
| 5 | +var WarnCaseSensitiveModulesPlugin = require("../lib/WarnCaseSensitiveModulesPlugin"); |
| 6 | + |
| 7 | +describe("WarnCaseSensitiveModulesPlugin", function() { |
| 8 | + var env; |
| 9 | + |
| 10 | + beforeEach(function() { |
| 11 | + env = {}; |
| 12 | + }); |
| 13 | + |
| 14 | + it("has apply function", function() { |
| 15 | + (new WarnCaseSensitiveModulesPlugin()).apply.should.be.a.Function(); |
| 16 | + }); |
| 17 | + |
| 18 | + describe("when applied", function() { |
| 19 | + beforeEach(function() { |
| 20 | + env.eventBindings = applyPluginWithOptions(WarnCaseSensitiveModulesPlugin); |
| 21 | + }); |
| 22 | + |
| 23 | + it("binds one event handler", function() { |
| 24 | + env.eventBindings.length.should.be.exactly(1); |
| 25 | + }); |
| 26 | + |
| 27 | + describe("compilation handler", function() { |
| 28 | + beforeEach(function() { |
| 29 | + env.pluginEnvironment = new PluginEnvironment(); |
| 30 | + env.eventBinding = env.eventBindings[0]; |
| 31 | + env.eventBinding.handler(env.pluginEnvironment.getEnvironmentStub()); |
| 32 | + env.compilationEventBindings = env.pluginEnvironment.getEventBindings(); |
| 33 | + }); |
| 34 | + |
| 35 | + it("binds to compilation event", function() { |
| 36 | + env.eventBinding.name.should.be.exactly("compilation"); |
| 37 | + }); |
| 38 | + |
| 39 | + it("binds one compilation event handler", function() { |
| 40 | + env.compilationEventBindings.length.should.be.exactly(1); |
| 41 | + }); |
| 42 | + |
| 43 | + describe("seal handler", function() { |
| 44 | + beforeEach(function() { |
| 45 | + env.compilationEventContext = { |
| 46 | + modules: [{ |
| 47 | + identifier: () => "Foo", |
| 48 | + reasons: [] |
| 49 | + }, |
| 50 | + { |
| 51 | + identifier: () => "Bar", |
| 52 | + reasons: [] |
| 53 | + }, |
| 54 | + { |
| 55 | + identifier: () => "fOO", |
| 56 | + reasons: [] |
| 57 | + } |
| 58 | + ], |
| 59 | + warnings: [] |
| 60 | + }; |
| 61 | + env.compilationEventBinding = env.compilationEventBindings[0]; |
| 62 | + env.compilationEventBinding.handler.call(env.compilationEventContext); |
| 63 | + }); |
| 64 | + |
| 65 | + it("binds to seal event", function() { |
| 66 | + env.compilationEventBinding.name.should.be.exactly("seal"); |
| 67 | + }); |
| 68 | + |
| 69 | + it("adds warning for each plugin with case insensitive name", function() { |
| 70 | + env.compilationEventContext.warnings.length.should.be.exactly(1); |
| 71 | + env.compilationEventContext.warnings[0].message.should.be.exactly(` |
| 72 | +There are multiple modules with names that only differ in casing. |
| 73 | +This can lead to unexpected behavior when compiling on a filesystem with other case-semantic. |
| 74 | +Use equal casing. Compare these module identifiers: |
| 75 | +* Foo |
| 76 | +* fOO |
| 77 | +`.trim()); |
| 78 | + }); |
| 79 | + }); |
| 80 | + }); |
| 81 | + }); |
| 82 | +}); |
0 commit comments