commit 8b4416c7aac0a07f06e101bd2a464ad8f2049225 Author: Tim Buckley Date: Fri May 27 16:21:33 2016 -0600 Initial import diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +node_modules diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..14fc67d --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,25 @@ +{ + "extends" : "openstack", + + "globals" : { + "module": true + }, + + "env" : { + "node": true + }, + + "rules" : { + "module-setter": 0, + "strict": [2,"global"], + "valid-jsdoc": 0, + "brace-style": [2, "1tbs", { "allowSingleLine": true }], + "no-extra-parens": [2, "functions"], + "complexity": 0, + "no-unused-vars": 0, + "guard-for-in": 0, + "quote-props": 0, + "no-use-before-define": 0 + } + +} diff --git a/.tern-project b/.tern-project new file mode 100644 index 0000000..75fcf14 --- /dev/null +++ b/.tern-project @@ -0,0 +1,9 @@ +{ + "ecmaVersion": 6, + "libs": [], + "plugins": { + "node": {}, + "doc_comment": {}, + "requirejs": {} + } +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..5c5f44e --- /dev/null +++ b/index.js @@ -0,0 +1,76 @@ +'use strict'; + +var fs = require('fs'); +var subunit = require('node-subunit'); + +function SubunitReporter(helper, logger, config) { + config = config || {}; + var outputFile = config.outputFile || 'karma.subunit'; + var tags = config.tags || []; + var slug = config.slug || false; + var separator = config.separator || '.'; + + var startTime, stream, file; + + this.onRunStart = function(browsers) { + startTime = new Date().getTime(); + + stream = new subunit.ObjectToSubunitStream(); + file = fs.createWriteStream(outputFile); + stream.pipe(file); + }; + + this.onSpecComplete = function(browser, result) { + var duration = result.time - startTime; + + var parts = result.suite.slice(); + parts.push(result.description); + + var testId = parts.join(separator); + if (slug) { + testId = testId.replace(/\s+/g, '_'); + } + + var status; + if (result.success) { + status = 'success'; + } else if (result.skipped) { + status = 'skip'; + } else { + status = 'fail'; + } + + var testTags = tags.slice(); + testTags.push('browser-' + browser.id); + testTags.push('spec-' + result.id.substring(4)); + + stream.write({ + testId: testId, + status: 'inprogress', + timestamp: new Date(startTime), + tags: testTags + }); + + stream.write({ + testId: testId, + status: status, + timestamp: new Date(startTime + result.time), + tags: testTags, + _packet: { + flags: { runnable: true } + } + }); + + startTime += result.time; + }; + + this.onRunComplete = function() { + stream.end(); + }; +} + +SubunitReporter.$inject = ['helper', 'logger', 'config.subunitReporter']; + +module.exports = { + 'reporter:subunit': ['type', SubunitReporter] +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..65efc66 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "karma-subunit-reporter", + "version": "0.0.1", + "description": "A Karma plugin to report results in Subunit format", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/timothyb89/karma-subunit-reporter.git" + }, + "keywords": [ + "karma-plugin", + "karma-reporter", + "subunit" + ], + "author": "OpenStack (http://www.openstack.org/)", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/timothyb89/karma-subunit-reporter/issues" + }, + "homepage": "https://github.com/timothyb89/karma-subunit-reporter#readme", + "dependencies": { + "eslint": "^1.5.1", + "eslint-config-openstack": "^1.2.4", + "node-subunit": "0.0.1" + }, + "peerDependencies": { + "karma": ">=0.9" + } +}