Browse Source

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.
Tim Buckley 2 years ago
parent
commit
88d03cd26a
1 changed files with 13 additions and 5 deletions
  1. 13
    5
      index.js

+ 13
- 5
index.js View File

@@ -1,4 +1,3 @@
1
-
2 1
 // Copyright 2016 Hewlett-Packard Development Company, L.P.
3 2
 //
4 3
 // Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -24,6 +23,18 @@ function SubunitReporter(helper, logger, config) {
24 23
   var slug = config.slug || false;
25 24
   var separator = config.separator || '.';
26 25
 
26
+  function normalize(parts) {
27
+    if (slug) {
28
+      return parts.map(function(part) {
29
+        return part.replace(/\s+/g, '_');
30
+      });
31
+    } else {
32
+      return parts;
33
+    }
34
+  }
35
+
36
+  var normalizeFunction = config.normalize || normalize;
37
+
27 38
   var startTime, stream, file;
28 39
 
29 40
   this.onRunStart = function(browsers) {
@@ -40,10 +51,7 @@ function SubunitReporter(helper, logger, config) {
40 51
     var parts = result.suite.slice();
41 52
     parts.push(result.description);
42 53
 
43
-    var testId = parts.join(separator);
44
-    if (slug) {
45
-      testId = testId.replace(/\s+/g, '_');
46
-    }
54
+    var testId = normalizeFunction(parts).join(separator);
47 55
 
48 56
     var status;
49 57
     if (result.success) {

Loading…
Cancel
Save