Browse Source

Initial import

Tim Buckley 2 years ago
commit
8b4416c7aa
5 changed files with 143 additions and 0 deletions
  1. 1
    0
      .eslintignore
  2. 25
    0
      .eslintrc.json
  3. 9
    0
      .tern-project
  4. 76
    0
      index.js
  5. 32
    0
      package.json

+ 1
- 0
.eslintignore View File

@@ -0,0 +1 @@
1
+node_modules

+ 25
- 0
.eslintrc.json View File

@@ -0,0 +1,25 @@
1
+{
2
+  "extends" : "openstack",
3
+
4
+  "globals" : {
5
+    "module": true
6
+  },
7
+
8
+  "env" : {
9
+    "node": true
10
+  },
11
+
12
+  "rules" : {
13
+    "module-setter": 0,
14
+    "strict": [2,"global"],
15
+    "valid-jsdoc": 0,
16
+    "brace-style": [2, "1tbs", { "allowSingleLine": true }],
17
+    "no-extra-parens": [2, "functions"],
18
+    "complexity": 0,
19
+    "no-unused-vars": 0,
20
+    "guard-for-in": 0,
21
+    "quote-props": 0,
22
+    "no-use-before-define": 0
23
+  }
24
+
25
+}

+ 9
- 0
.tern-project View File

@@ -0,0 +1,9 @@
1
+{
2
+  "ecmaVersion": 6,
3
+  "libs": [],
4
+  "plugins": {
5
+    "node": {},
6
+    "doc_comment": {},
7
+    "requirejs": {}
8
+  }
9
+}

+ 76
- 0
index.js View File

@@ -0,0 +1,76 @@
1
+'use strict';
2
+
3
+var fs = require('fs');
4
+var subunit = require('node-subunit');
5
+
6
+function SubunitReporter(helper, logger, config) {
7
+  config = config || {};
8
+  var outputFile = config.outputFile || 'karma.subunit';
9
+  var tags = config.tags || [];
10
+  var slug = config.slug || false;
11
+  var separator = config.separator || '.';
12
+
13
+  var startTime, stream, file;
14
+
15
+  this.onRunStart = function(browsers) {
16
+    startTime = new Date().getTime();
17
+
18
+    stream = new subunit.ObjectToSubunitStream();
19
+    file = fs.createWriteStream(outputFile);
20
+    stream.pipe(file);
21
+  };
22
+
23
+  this.onSpecComplete = function(browser, result) {
24
+    var duration = result.time - startTime;
25
+
26
+    var parts = result.suite.slice();
27
+    parts.push(result.description);
28
+
29
+    var testId = parts.join(separator);
30
+    if (slug) {
31
+      testId = testId.replace(/\s+/g, '_');
32
+    }
33
+
34
+    var status;
35
+    if (result.success) {
36
+      status = 'success';
37
+    } else if (result.skipped) {
38
+      status = 'skip';
39
+    } else {
40
+      status = 'fail';
41
+    }
42
+
43
+    var testTags = tags.slice();
44
+    testTags.push('browser-' + browser.id);
45
+    testTags.push('spec-' + result.id.substring(4));
46
+
47
+    stream.write({
48
+      testId: testId,
49
+      status: 'inprogress',
50
+      timestamp: new Date(startTime),
51
+      tags: testTags
52
+    });
53
+
54
+    stream.write({
55
+      testId: testId,
56
+      status: status,
57
+      timestamp: new Date(startTime + result.time),
58
+      tags: testTags,
59
+      _packet: {
60
+        flags: { runnable: true }
61
+      }
62
+    });
63
+
64
+    startTime += result.time;
65
+  };
66
+
67
+  this.onRunComplete = function() {
68
+    stream.end();
69
+  };
70
+}
71
+
72
+SubunitReporter.$inject = ['helper', 'logger', 'config.subunitReporter'];
73
+
74
+module.exports = {
75
+  'reporter:subunit': ['type', SubunitReporter]
76
+};

+ 32
- 0
package.json View File

@@ -0,0 +1,32 @@
1
+{
2
+  "name": "karma-subunit-reporter",
3
+  "version": "0.0.1",
4
+  "description": "A Karma plugin to report results in Subunit format",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "test": "echo \"Error: no test specified\" && exit 1"
8
+  },
9
+  "repository": {
10
+    "type": "git",
11
+    "url": "git+https://github.com/timothyb89/karma-subunit-reporter.git"
12
+  },
13
+  "keywords": [
14
+    "karma-plugin",
15
+    "karma-reporter",
16
+    "subunit"
17
+  ],
18
+  "author": "OpenStack <openstack-dev@lists.openstack.org> (http://www.openstack.org/)",
19
+  "license": "Apache-2.0",
20
+  "bugs": {
21
+    "url": "https://github.com/timothyb89/karma-subunit-reporter/issues"
22
+  },
23
+  "homepage": "https://github.com/timothyb89/karma-subunit-reporter#readme",
24
+  "dependencies": {
25
+    "eslint": "^1.5.1",
26
+    "eslint-config-openstack": "^1.2.4",
27
+    "node-subunit": "0.0.1"
28
+  },
29
+  "peerDependencies": {
30
+    "karma": ">=0.9"
31
+  }
32
+}

Loading…
Cancel
Save