From 88d03cd26a146f1baa22f4580392c1361e181b66 Mon Sep 17 00:00:00 2001 From: Tim Buckley Date: Thu, 9 Jun 2016 12:01:34 -0600 Subject: [PATCH] Support custom testId normalization functions This adds support for user-specified normalization functions as a configuration paramter 'normalize'. These functions can override the default default normalization functionality (as configured with the 'slug' parameter) to adjust or remove project-specific formatting. --- index.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b875e87..7923861 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,3 @@ - // Copyright 2016 Hewlett-Packard Development Company, L.P. // // Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -24,6 +23,18 @@ function SubunitReporter(helper, logger, config) { var slug = config.slug || false; var separator = config.separator || '.'; + function normalize(parts) { + if (slug) { + return parts.map(function(part) { + return part.replace(/\s+/g, '_'); + }); + } else { + return parts; + } + } + + var normalizeFunction = config.normalize || normalize; + var startTime, stream, file; this.onRunStart = function(browsers) { @@ -40,10 +51,7 @@ function SubunitReporter(helper, logger, config) { var parts = result.suite.slice(); parts.push(result.description); - var testId = parts.join(separator); - if (slug) { - testId = testId.replace(/\s+/g, '_'); - } + var testId = normalizeFunction(parts).join(separator); var status; if (result.success) {