Skip to content

Commit

Permalink
Added a basic test
Browse files Browse the repository at this point in the history
  • Loading branch information
jkimbo committed Aug 7, 2016
1 parent 8818e92 commit 293d43a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Enforces module path case sensitivity in Webpack",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha test/"
},
"repository": {
"type": "git",
Expand All @@ -22,5 +22,9 @@
"bugs": {
"url": "https://github.com/Urthen/case-sensitive-paths-webpack-plugin/issues"
},
"homepage": "https://github.com/Urthen/case-sensitive-paths-webpack-plugin#readme"
"homepage": "https://github.com/Urthen/case-sensitive-paths-webpack-plugin#readme",
"devDependencies": {
"mocha": "^3.0.1",
"webpack": "^1.13.1"
}
}
1 change: 1 addition & 0 deletions test/fixtures/wrong-case/entry.js
@@ -0,0 +1 @@
var testModule = require('./TestFile');
1 change: 1 addition & 0 deletions test/fixtures/wrong-case/testfile.js
@@ -0,0 +1 @@
module.exports = '';
37 changes: 37 additions & 0 deletions test/index.js
@@ -0,0 +1,37 @@
var assert = require("assert");
var path = require("path");
var webpack = require("webpack");

var CaseSensitivePathsPlugin = require("../");

describe("CaseSensitivePathsPlugin", function() {

it("should compile and warn on wrong filename case", function(done) {
webpack({
context: path.join(__dirname, "fixtures", "wrong-case"),
target: "node",
output: {
path: path.join(__dirname, "js"),
filename: "result.js",
},
entry: "./entry",
plugins: [
new CaseSensitivePathsPlugin()
]
}, function(err, stats) {
if (err) done(err);
assert(stats.hasErrors());
assert.equal(stats.hasWarnings(), false);
var jsonStats = stats.toJson();
assert.equal(jsonStats.errors.length, 1);

var error = jsonStats.errors[0].split("\n");
// check that the plugin produces the correct output
assert(error[1].indexOf('[CaseSensitivePathsPlugin]') > -1);
assert(error[1].indexOf('TestFile.js') > -1); // wrong file require
assert(error[1].indexOf('testfile.js') > -1); // actual file name

done();
});
});
});

0 comments on commit 293d43a

Please sign in to comment.