Socket
Socket
Sign inDemoInstall

karma-tfs-reporter

Package Overview
Dependencies
4
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

0

index.js

@@ -0,0 +0,0 @@ var path = require('path');

6

package.json
{
"name": "karma-tfs-reporter",
"version": "1.0.0",
"version": "1.0.1",
"description": "A Karma plugin for reporting test results to TFS",

@@ -23,5 +23,7 @@ "main": "index.js",

"dependencies": {
"dateformat": "^2.0.0",
"mkpath": "^1.0.0",
"node-uuid": "^1.4.7"
"node-uuid": "^1.4.7",
"xmlbuilder": "^9.0.0"
}
}

@@ -25,3 +25,3 @@ # karma-tfs-reporter

require('karma-webpack'),
require('karma-chrome-launcher'),
require('karma-phantomjs-launcher'),
require('karma-tfs-reporter')

@@ -38,3 +38,3 @@ ],

},
browsers: ['Chrome'],
browsers: ['PhantomJS'],
reporters: ['progress', 'tfs'],

@@ -41,0 +41,0 @@ // Default settings (optional)

var uuid = require('node-uuid');
var os = require('os');
var xmlbuilder = require('xmlbuilder');
var dateFormat = require('dateformat');

@@ -10,18 +12,8 @@ function pad(n, width, z) {

var toISOString = function(time) {
var date = new Date(time),
tzo = -date.getTimezoneOffset(),
dif = tzo >= 0 ? '+' : '-';
return date.getFullYear()
+ '-' + pad(date.getMonth() + 1, 2)
+ '-' + pad(date.getDate(), 2)
+ 'T' + pad(date.getHours(), 2)
+ ':' + pad(date.getMinutes(), 2)
+ ':' + pad(date.getSeconds(), 2)
+ '.' + pad(date.getMilliseconds(), 3) + '0000'
+ dif + pad(tzo / 60, 2)
+ ':' + pad(tzo % 60, 2);
function toISOString (time) {
var date = new Date(time);
return dateFormat(date, "isoDateTime");
};
var duration = function (start, finish) {
function duration (start, finish) {
var diff = finish.getTime() - start.getTime();

@@ -66,45 +58,96 @@ return pad((diff / 1000 / 60 / 60) % 100, 2)

// Am I going to hell for this?
return `<?xml version="1.0" encoding="UTF-8"?>
<TestRun id="${uuid()}" name="${testResults.name}" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Times creation="${toISOString(start)}" start="${toISOString(start)}" finish="${toISOString(finish)}" />
<Results>
${specs.map(spec =>
`<UnitTestResult executionId="${spec.executionId}" testId="${spec.testId}" testName="${spec.name}" computerName="${os.hostname()}" duration="${duration(spec.result.start, spec.result.finish)}" startTime="${toISOString(spec.result.start)}" endTime="${toISOString(spec.result.finish)}" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="${spec.result.outcome}" testListId="${suites[spec.result.suite]}">
${spec.result.outcome == 'Failed' ? `<Output>
<ErrorInfo>
<Message>${escape(spec.result.message)}</Message>
<StackTrace>${escape(spec.result.stackTrace)}</StackTrace>
</ErrorInfo>
</Output>` : ``}
</UnitTestResult>
`).join('')}
</Results>
<TestDefinitions>
${specs.map(spec =>
`<UnitTest name="${spec.name}" id="${spec.testId}">
<Execution id="${spec.executionId}" />
<TestMethod codeBase="${testResults.name}" className="${spec.result.suite}" name="${spec.name}" />
</UnitTest>
`).join('')}
</TestDefinitions>
<TestEntries>
${specs.map(spec =>
`<TestEntry testId="${spec.testId}" executionId="${spec.executionId}" testListId="${suites[spec.result.suite]}" />
`).join('')}
</TestEntries>
<TestLists>
${Object.keys(suites).map(suite =>
`<TestList name="${suite}" id="${suites[suite]}" />
`).join('')}
</TestLists>
<ResultSummary outcome="${fullOutcome}">
<Counters total="${testResults.specs.length}" executed="${executed.length}" passed="${passed.length}" failed="${failed.length}" />
<Output>
${notExecuted.map(spec =>
`<StdOut>Test '${spec.name}' was skipped in the test run.</StdOut>
`).join('')}
</Output>
</ResultSummary>
</TestRun>`;
var unitTestResultsArray = specs.map(spec => {
var testResult = {
'@executionId': spec.executionId,
'@testId': spec.testId,
'@testName': spec.name,
'@computerName': os.hostname(),
'@duration': duration(spec.result.start, spec.result.finish),
'@startTime': toISOString(spec.result.start),
'@endTime': toISOString(spec.result.finish),
'@testType': '13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b',
'@outcome': spec.result.outcome,
'@testListId': suites[spec.result.suite]
};
if(spec.result.outcome === 'Failed'){
testResult.ErrorInfo = {
Message:escape(spec.result.message),
StackTrace:escape(spec.result.stackTrace)
}
}
return testResult;
});
var testDefinitionsArray = specs.map(spec => {
return {
'@name': spec.name,
'@id': spec.testId,
'Execution':{
'@id':spec.executionId
},
'TestMethod': {
'@codeBase': testResults.name,
'@className': spec.result.suite,
'@name': spec.name
}
};
});
var testEntryArray = specs.map(spec => {
return {
'@testId': spec.testId,
'@executionId': spec.executionId,
'@testListId': suites[spec.result.suite]
};
});
var testListArray = Object.keys(suites).map(suite => {;
return {
'@name': suite,
'@id': suites[suite]
};
});
var skippedArray = notExecuted.map(spec => {
return {'#text': `Test '${spec.name}' was skipped in the test run.`};
});
return xmlbuilder.create({
TestRun: {
'@id': uuid(),
'@name': testResults.name,
'@xmlns': 'http://microsoft.com/schemas/VisualStudio/TeamTest/2010',
Times: {
'@creation': toISOString(start),
'@start': toISOString(start),
'@finish': toISOString(finish)
},
TestLists: {
TestList: testListArray
},
TestDefinitions: {
UnitTest: testDefinitionsArray
},
TestEntries: {
TestEntry: testEntryArray
},
Results: {
UnitTestResult: unitTestResultsArray
},
ResultSummary:{
'@outcome':fullOutcome,
Counters:{
'@total': testResults.specs.length,
'@executed': executed.length,
'@passed': passed.length,
'@failed': failed.length
},
Output: {
StdOut: skippedArray
}
}
}
})
.dec('1.0', 'UTF-8')
.end({pretty:true});
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc