├── README.md ├── package.json ├── LICENSE └── index.js /README.md: -------------------------------------------------------------------------------- 1 | karma-bamboo-reporter 2 | ===================== 3 | 4 | A quick an dirty karma reporter that integrates with bamboo via https://marketplace.atlassian.com/plugins/com.atlassian.bamboo.plugins.bamboo-nodejs-plugin 5 | 6 | Install 7 | ------------ 8 | `npm install karma-bamboo-reporter` 9 | 10 | Usage 11 | ------------ 12 | ``` 13 | ... 14 | 15 | reporters: ['bamboo'], 16 | 17 | bambooReporter:{ 18 | filename: 'util.mocha.json' //optional, defaults to "mocha.json" 19 | }, 20 | 21 | plugins: ['karma-bamboo-reporter'] 22 | 23 | ... 24 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "karma-bamboo-reporter", 3 | "version": "0.1.2", 4 | "author": "TheSharpieOne", 5 | "license": "MIT", 6 | "homepage": "https://github.com/TheSharpieOne/karma-bamboo-reporter", 7 | "description": "A Karma plugin. Report results in bamboo json format.", 8 | "main": "index.js", 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository":{ 13 | "type": "git", 14 | "url": "git://github.com/TheSharpieOne/karma-bamboo-reporter.git" 15 | }, 16 | "keywords": [ 17 | "karma-plugin", 18 | "karma-reporter", 19 | "bamboo" 20 | ], 21 | "peerDependencies": { 22 | "karma": ">=0.9" 23 | }, 24 | "dependencies": { 25 | "mkdirp": "^0.5.1" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Evan Sharp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var mkdirp = require('mkdirp'); 4 | 5 | var fE; 6 | 7 | var bambooReporter = function (baseReporterDecorator, config, formatError) { 8 | fE = formatError; 9 | baseReporterDecorator(this); 10 | 11 | var filename = config && config.filename || 'mocha.json'; 12 | 13 | var results = { 14 | time: 0, tests: [], failures: [], passes: [], skips: [] 15 | }; 16 | 17 | this.onRunStart = function () { 18 | this._browsers = []; 19 | if (fs.existsSync(filename)) { 20 | fs.unlinkSync(filename); 21 | } 22 | }; 23 | 24 | this.onSpecComplete = function (browser, result) { 25 | results.time += result.time; 26 | result.browser = browser.name; 27 | results.tests.push(result); 28 | if (result.skipped) results.skips.push(result); 29 | else if (result.success) results.passes.push(result); 30 | else results.failures.push(result); 31 | }; 32 | 33 | this.onRunComplete = function (browser, result) { 34 | var obj = { 35 | stats: {tests: (result.success + result.failed), passes: result.success, failures: result.failed, duration: results.time }, failures: results.failures.map(clean), passes: results.passes.map(clean), skipped: results.skips.map(clean) 36 | }; 37 | 38 | // If the directoy we're supposed to write into does not exist, create it 39 | var dir = path.dirname(filename); 40 | if (dir !== '.') { 41 | mkdirp.sync(dir); 42 | } 43 | 44 | fs.writeFileSync(filename, JSON.stringify(obj, null, 2), 'utf-8'); 45 | results = { 46 | time: 0, tests: [], failures: [], passes: [], skips: [] 47 | }; 48 | }; 49 | }; 50 | 51 | function clean(test) { 52 | var o = { 53 | title : test.suite.concat(test.description).join(' '), 54 | fullTitle : test.suite[0], 55 | duration : test.time 56 | }; 57 | if (!test.success) { 58 | o.error = ''; 59 | test.log.forEach(function(log) { 60 | // translate sourcemap 61 | log = fE(log); 62 | o.error += log.split('\n').reduce(function(memo, line, i) { 63 | // keep first line 64 | line = line.split('<-'); 65 | if (line[1]) memo += '\n\tat' + line[1]; 66 | return memo; 67 | }); 68 | }); 69 | } 70 | return o; 71 | } 72 | 73 | bambooReporter.$inject = ['baseReporterDecorator', 'config.bambooReporter', 'formatError']; 74 | 75 | // PUBLISH DI MODULE 76 | module.exports = { 77 | 'reporter:bamboo': ['type', bambooReporter] 78 | }; 79 | --------------------------------------------------------------------------------