jest-teamcity
Advanced tools
Comparing version 1.0.0 to 1.1.0
109
lib/index.js
/** | ||
* @author Ivan Tereshchenkov | ||
*/ | ||
const parsec = require('parsec'); | ||
const _ = require('lodash'); | ||
const internal = { | ||
/** | ||
* Escape text message to be compatible with Teamcity | ||
* @param {string} str | ||
* @returns {string} | ||
*/ | ||
escape(str) { | ||
if (!str) { | ||
return ''; | ||
} | ||
'use strict'; | ||
return str | ||
.toString() | ||
.replace(/\x1B.*?m/g, '') | ||
.replace(/\|/g, '||') | ||
.replace(/\n/g, '|n') | ||
.replace(/\r/g, '|r') | ||
.replace(/\[/g, '|[') | ||
.replace(/\]/g, '|]') | ||
.replace(/\u0085/g, '|x') | ||
.replace(/\u2028/g, '|l') | ||
.replace(/\u2029/g, '|p') | ||
.replace(/'/g, '|\'') | ||
}, | ||
const formatter = require('./formatter'); | ||
/** | ||
* Prints test message | ||
* @param {object} test | ||
*/ | ||
printTestLog(tests) { | ||
Object.keys(tests).forEach((suiteName) => { | ||
if (suiteName === '_tests_') { | ||
// print test details | ||
tests[suiteName].forEach((test) => { | ||
this.log(`##teamcity[testStarted name='${this.escape(test.title)}' captureStandardOutput='true']`); | ||
switch (test.status) { | ||
case 'failed': | ||
test.failureMessages.forEach((error) => { | ||
const [message, stack] = error.split('\n '); | ||
this.log(`##teamcity[testFailed name='${this.escape(test.title)}' message='${this.escape(message)}' details='${this.escape(stack)}' captureStandardOutput='true']`); | ||
}); | ||
break; | ||
case 'pending': | ||
this.log(`##teamcity[testIgnored name='${this.escape(test.title)}' message='pending']`); | ||
break; | ||
case 'passed': | ||
break; | ||
} | ||
this.log(`##teamcity[testFinished name='${this.escape(test.title)}' duration='${test.duration}']`); | ||
}); | ||
} else { | ||
// print suite names | ||
this.log(`##teamcity[testSuiteStarted name='${this.escape(suiteName)}']`); | ||
this.printTestLog(tests[suiteName]); | ||
this.log(`##teamcity[testSuiteFinished name='${this.escape(suiteName)}']`); | ||
} | ||
}); | ||
}, | ||
/** | ||
* Outputs teamcity service message | ||
* @param {string} text | ||
*/ | ||
log(text) { | ||
console.log(text); | ||
}, | ||
/** | ||
* Collects test suites | ||
* @param {array} testResults | ||
* @returns {object} | ||
*/ | ||
collectSuites(testResults) { | ||
const suites = {}; | ||
testResults.forEach((testFile) => { | ||
testFile.testResults.forEach((test) => { | ||
const path = test.ancestorTitles.join('.') + '._tests_'; | ||
if (!_.has(suites, path )) { | ||
_.set(suites, path, []); | ||
} | ||
const testsList = _.get(suites, path); | ||
testsList.push(test); | ||
_.set(suites, path, testsList); | ||
}); | ||
}); | ||
return suites; | ||
}, | ||
/** | ||
* Formats and outputs tests results | ||
* @param {array} testResults | ||
*/ | ||
formatReport(testResults) { | ||
const suites = this.collectSuites(testResults); | ||
this.printTestLog(suites); | ||
} | ||
}; | ||
module.exports = (result) => { | ||
if (!parsec().teamcity) { | ||
if (!process.env.TEAMCITY_VERSION) { | ||
return result; | ||
} | ||
return internal.formatReport(result.testResults); | ||
return formatter.formatReport(result.testResults); | ||
}; |
{ | ||
"name": "jest-teamcity", | ||
"version": "1.0.0", | ||
"description": "Jest Teamcity Reporter", | ||
"version": "1.1.0", | ||
"description": "Teamcity Reporter for Jest Testing framework", | ||
"homepage": "https://github.com/itereshchenkov/jest-teamcity", | ||
"main": "lib/index.js", | ||
"dependencies": { | ||
"lodash": "^4.17.3", | ||
"parsec": "^1.5.3" | ||
"lodash": "^4.17.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^3.12.2" | ||
"eslint": "^3.12.2", | ||
"jest": "^19.0.2" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jest" | ||
}, | ||
@@ -22,3 +22,7 @@ "keywords": [ | ||
"tests", | ||
"unit" | ||
"unit", | ||
"unittest", | ||
"integration", | ||
"ci", | ||
"cd" | ||
], | ||
@@ -25,0 +29,0 @@ "author": { |
# jest-teamcity | ||
TeamCity Reporter for Jest testing framework which groups tests using TeamCity Test Suites. | ||
[![Build Status](https://travis-ci.org/itereshchenkov/jest-teamcity.svg?branch=master)](https://travis-ci.org/itereshchenkov/jest-teamcity) | ||
TeamCity Reporter for Jest testing framework which groups tests using TeamCity Test Suites. | ||
## Features | ||
@@ -17,3 +19,3 @@ | ||
Put this into jest configuration file or package.json | ||
``` | ||
```javascript | ||
"jest": { | ||
@@ -24,2 +26,10 @@ "testResultsProcessor": "jest-teamcity" | ||
The reported is enabled only if `TEAMCITY_VERSION` variable is set. It should work in TeamCity be default. | ||
To be able to run the tests with the reporter locally, environment variable should be set: | ||
```bash | ||
export TEAMCITY_VERSION="some_version" | ||
``` | ||
To enable TeamCity reporter, use the following option: | ||
@@ -29,6 +39,5 @@ `jest --teamcity` | ||
Package.json example: | ||
``` | ||
```javascript | ||
"scripts": { | ||
"test": "jest", | ||
"test:teamcity": "jest --teamcity" | ||
"test": "jest" | ||
} | ||
@@ -35,0 +44,0 @@ ``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
15525
1
11
278
0
46
2
3
1
- Removedparsec@^1.5.3
- Removedbabel-runtime@5.8.38(transitive)
- Removedcore-js@1.2.7(transitive)
- Removedparsec@1.5.3(transitive)