Skip to content

Commit

Permalink
Merge pull request #10 from odegroot/filterWebpackWarnings
Browse files Browse the repository at this point in the history
Filter webpack warnings
  • Loading branch information
jauco committed Jul 1, 2014
2 parents bf27283 + c06a3c3 commit c919207
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 20 deletions.
25 changes: 14 additions & 11 deletions HACKING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# How to debug Jester

You attach a graphical debugger ([node-inspector]) to the unittests, or to the compiled jester.js
You attach a graphical debugger ([node-inspector]) to jester.

### Attaching the debugger to the compiled jester.js
- Install [node-inspector] somewhere. Doesn't matter where.

1. Start node-inspector on port 8080:
$ npm install node-inspector

$ cd <jester source dir>
$ .\dist\node_modules\.bin\node-inspector --web-port=8080
info - socket.io started
visit http://0.0.0.0:8080/debug?port=5858 to start debugging
- Start node-inspector.

2. Start jester in debug mode:
$ node_modules/.bin/node-inspector
Node Inspector v0.7.4
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.

$ .\dist\node.exe --debug-brk .\dist\jester.js
*node-inspector* now waits for the process-to-debug on port 5858, and for you on port 8080.

- Start jester in debug mode.

$ node --debug-brk node_modules/jester-tester/src/bin/jester-watch.js
debugger listening on port 5858

3. Open a browser on http://localhost:8080
4. place your breakpoints and press the play button to start running jester.
- Browse to http://127.0.0.1:8080/debug?port=5858.
- Place your breakpoints and press the play button to start running jester.

[node-inspector]: https://npmjs.org/package/node-inspector
2 changes: 1 addition & 1 deletion src/bin/jester-batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var loadConfig = require("../lib/loadConfig"),

var config = loadConfig("./jester.json");

rebuildProject(config.fullEntryGlob, config.artifactPath)
rebuildProject(config.fullEntryGlob, config.artifactPath, config.webpackWarningFilters)
.then(function() {
if(config.srcPath && config.apiDocPath) {
return rebuildDocumentation(config.srcPath, config.apiDocPath, config.jsdocConf, config.readme);
Expand Down
4 changes: 2 additions & 2 deletions src/bin/jester-watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function runTests(path) {
console.log("No tests found for '" + path + "'");
return false;
}
return createTestFile(testFile, config.karmaPath).then(function () {
return createTestFile(testFile, config.karmaPath, config.webpackWarningFilters).then(function () {
return server.run();
});
});
Expand Down Expand Up @@ -74,7 +74,7 @@ function startWatching() {
}

if (filePath.length > 3 && filePath.substr(-3) === ".js") {
var build = rebuildProject(config.fullEntryGlob, config.artifactPath);
var build = rebuildProject(config.fullEntryGlob, config.artifactPath, config.webpackWarningFilters);
if (isReallyFileChangeEvent(changeType, fileCurrentStat, filePreviousStat)) {
when.join(build, runTests(filePath)).done(function(){});
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/createTestFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function createEntryModules(filenames) {
return entryModules;
}

module.exports = function createTestFile(filenames, karmaPath) {
module.exports = function createTestFile(filenames, karmaPath, webpackWarningFilters) {
return webpack({
entry: createEntryModules(filenames),
output: {
Expand All @@ -30,6 +30,6 @@ module.exports = function createTestFile(filenames, karmaPath) {
},
devtool: "#source-map"
}).then(function(stats) {
return handleWebpackResult(stats);
return handleWebpackResult(stats, webpackWarningFilters);
});
};
79 changes: 78 additions & 1 deletion src/lib/handleWebpackResult.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = function handleWebpackResult(stats) {
module.exports = function handleWebpackResult(stats, webpackWarningFilters) {
if (stats) {
if (filterConfigIsValid(webpackWarningFilters)) {
stats.compilation.warnings = filterWebpackWarnings(stats.compilation.warnings, webpackWarningFilters);
}
stats = stats.toJson();
}
var nonFatalErrors = (stats && stats.errors) || [];
Expand Down Expand Up @@ -38,3 +41,77 @@ module.exports = function handleWebpackResult(stats) {
}

};

/**
* Checks the sanity of the webpackWarningFilters-configuration.
*/
function filterConfigIsValid(webpackWarningFilters) {
var filterConfigIsValid = true;
if (webpackWarningFilters) {
if (Array.isArray(webpackWarningFilters)) {
for (var i = 0; i < webpackWarningFilters.length; i++) {
var webpackWarningFilter = webpackWarningFilters[i];
if ("name" in webpackWarningFilter
&& "origin/rawRequest" in webpackWarningFilter
&& "dependencies/0/request" in webpackWarningFilter
&& Object.keys(webpackWarningFilter).length === 3 // That is, webpackWarningFilter contains no keys other than these three.
&& webpackWarningFilter.name === "ModuleNotFoundError"
) {
// This filter config is supported. Proceed.
} else {
// This filter config isn't supported. Abort.
console.warn(
"config.webpackWarningFilters[" + i + "] must be an object similar to {\n" +
" 'name': 'ModuleNotFoundError',\n" +
" 'origin/rawRequest': 'imports?process=>undefined!when',\n" +
" 'dependencies/0/request': 'vertx'\n" +
"}."
);
filterConfigIsValid = false;
}
}
} else {
console.warn("config.webpackWarningFilters must be an array.");
filterConfigIsValid = false;
}
} else {
// No filters are configured. That's okay.
filterConfigIsValid = true;
}
return filterConfigIsValid;
}

function filterWebpackWarnings(unfilteredWarnings, webpackWarningFilters) {
if (!webpackWarningFilters) {
// No filters are configured. Use the complete, unfiltered list of warnings.
return unfilteredWarnings;
}

// There's at least one filter and all filter configs are supported. Do the actual filtering.
var filteredWarnings = unfilteredWarnings.filter(function filterWarning(warning, index, unfilteredWarnings) {
if (warning.name !== "ModuleNotFoundError") {
// filterWebpackWarnings only supports filtering of ModuleNotFoundError-warnings.
// This is some other kind of warning. Leave it in the list, so that it IS shown in Jester's output.
return true;
}

for (var i = 0; i < webpackWarningFilters.length; i++) {
var webpackWarningFilter = webpackWarningFilters[i];
if (
warning.origin.rawRequest === webpackWarningFilter["origin/rawRequest"]
&& warning.dependencies.length > 0
&& warning.dependencies[0].request === webpackWarningFilter["dependencies/0/request"]
) {
// This warning matches one of the filters.
// Remove it from the list, so that it is NOT shown in Jester's output.
return false;
}
}

// This warning matches none of the filters.
// Leave it in the list, so that it IS shown in Jester's output.
return true;
});

return filteredWarnings;
}
4 changes: 2 additions & 2 deletions src/lib/rebuildProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function createEntryModules(featureFiles) {
return entryModules;
}

module.exports = function rebuildProject(entryGlob, artifactPath) {
module.exports = function rebuildProject(entryGlob, artifactPath, webpackWarningFilters) {
return clearDir(artifactPath)
.then(function filesCleared() {
return glob(entryGlob);
Expand All @@ -39,6 +39,6 @@ module.exports = function rebuildProject(entryGlob, artifactPath) {
});
})
.then(function (stats){
return handleWebpackResult(stats);
return handleWebpackResult(stats, webpackWarningFilters);
});
};
2 changes: 1 addition & 1 deletion src/lib/runAllTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function runAllTests(config) {
return glob(config.srcPath + "/**/*.test.js");
})
.then(function (testInputFiles) {
return createTestFile(testInputFiles, config.karmaPath);
return createTestFile(testInputFiles, config.karmaPath, config.webpackWarningFilters);
})
.catch(function(err) {
console.error("failed creating test files ", err);
Expand Down

0 comments on commit c919207

Please sign in to comment.