Socket
Socket
Sign inDemoInstall

jest-teamcity

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-teamcity - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

.prettierrc.json

220

__tests__/formatter.js

@@ -1,123 +0,133 @@

'use strict';
"use strict";
const formatter = require('../lib/formatter');
const testData = require('./data');
const path = require("path");
const formatter = require("../lib/formatter");
const testData = require("./data");
const consoleOutput = [
["##teamcity[testSuiteStarted name=\'foo/__tests__/file.js\']"],
["##teamcity[testSuiteStarted name=\'path\']"],
["##teamcity[testSuiteStarted name=\'to\']"],
["##teamcity[testSuiteStarted name=\'test1\']"],
["##teamcity[testStarted name=\'title1\']"],
["##teamcity[testFailed name=\'title1\']"],
["##teamcity[testFinished name=\'title1\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test1\']"],
["##teamcity[testSuiteStarted name=\'test2\']"],
["##teamcity[testStarted name=\'title2\']"],
["##teamcity[testIgnored name=\'title2\' message=\'pending\']"],
["##teamcity[testFinished name=\'title2\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test2\']"],
["##teamcity[testSuiteFinished name=\'to\']"],
["##teamcity[testSuiteFinished name=\'path\']"],
["##teamcity[testSuiteFinished name=\'foo/__tests__/file.js\']"],
["##teamcity[testSuiteStarted name=\'foo/__tests__/file2.js\']"],
["##teamcity[testSuiteStarted name=\'path2\']"],
["##teamcity[testSuiteStarted name=\'to\']"],
["##teamcity[testSuiteStarted name=\'test3\']"],
["##teamcity[testStarted name=\'title3\']"],
["##teamcity[testFinished name=\'title3\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test3\']"],
["##teamcity[testSuiteStarted name=\'test4\']"],
["##teamcity[testStarted name=\'title4\']"],
["##teamcity[testFailed name=\'title4\']"],
["##teamcity[testFinished name=\'title4\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test4\']"],
["##teamcity[testSuiteFinished name=\'to\']"],
["##teamcity[testSuiteFinished name=\'path2\']"],
["##teamcity[testSuiteFinished name=\'foo/__tests__/file2.js\']"]
["##teamcity[testSuiteStarted name='foo/__tests__/file.js' flowId='12345']"],
["##teamcity[testSuiteStarted name='path' flowId='12345']"],
["##teamcity[testSuiteStarted name='to' flowId='12345']"],
["##teamcity[testSuiteStarted name='test1' flowId='12345']"],
["##teamcity[testStarted name='title1' flowId='12345']"],
["##teamcity[testFailed name='title1' flowId='12345']"],
["##teamcity[testFinished name='title1' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test1' flowId='12345']"],
["##teamcity[testSuiteStarted name='test2' flowId='12345']"],
["##teamcity[testStarted name='title2' flowId='12345']"],
["##teamcity[testIgnored name='title2' message='pending' flowId='12345']"],
["##teamcity[testFinished name='title2' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test2' flowId='12345']"],
["##teamcity[testSuiteFinished name='to' flowId='12345']"],
["##teamcity[testSuiteFinished name='path' flowId='12345']"],
["##teamcity[testSuiteFinished name='foo/__tests__/file.js' flowId='12345']"],
["##teamcity[testSuiteStarted name='foo/__tests__/file2.js' flowId='12345']"],
["##teamcity[testSuiteStarted name='path2' flowId='12345']"],
["##teamcity[testSuiteStarted name='to' flowId='12345']"],
["##teamcity[testSuiteStarted name='test3' flowId='12345']"],
["##teamcity[testStarted name='title3' flowId='12345']"],
["##teamcity[testFinished name='title3' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test3' flowId='12345']"],
["##teamcity[testSuiteStarted name='test4' flowId='12345']"],
["##teamcity[testStarted name='title4' flowId='12345']"],
["##teamcity[testFailed name='title4' flowId='12345']"],
["##teamcity[testFinished name='title4' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test4' flowId='12345']"],
["##teamcity[testSuiteFinished name='to' flowId='12345']"],
["##teamcity[testSuiteFinished name='path2' flowId='12345']"],
["##teamcity[testSuiteFinished name='foo/__tests__/file2.js' flowId='12345']"]
];
describe('jest-teamcity', () => {
describe('formatter', () => {
let consoleFn = console.log;
describe("jest-teamcity", () => {
describe("formatter", () => {
let consoleFn = console.log;
let formatterFn = formatter.log;
beforeAll(() => {
console.log = jest.fn().mockImplementation(s => s);
});
beforeAll(() => {
console.log = jest.fn().mockImplementation(s => s);
const formatterMock = path.sep == "/" ? s => formatterFn(s) : s => formatterFn(s.replace(/\\/g, "/"));
formatter.log = jest.fn().mockImplementation(formatterMock);
});
beforeEach(() => {
console.log.mockReset();
});
beforeEach(() => {
console.log.mockReset();
formatter.log.mockClear();
});
afterAll(() => {
console.log = consoleFn;
});
afterAll(() => {
console.log = consoleFn;
formatter.log = formatterFn;
});
describe('escape()', () => {
test('empty string', () => {
expect(formatter.escape('')).toEqual('');
expect(formatter.escape(null)).toEqual('');
expect(formatter.escape(undefined)).toEqual('');
});
describe("escape()", () => {
test("empty string", () => {
expect(formatter.escape("")).toEqual("");
expect(formatter.escape(null)).toEqual("");
expect(formatter.escape(undefined)).toEqual("");
});
test('escape', () => {
expect(formatter.escape(`|test[test2]|
test3`)).toEqual('||test|[test2|]|||ntest3');
});
});
test("escape", () => {
expect(
formatter.escape(`|test[test2]|
test3`)
).toEqual("||test|[test2|]|||ntest3");
});
});
describe('printTestLog', () => {
test('empty tests', () => {
['', null, undefined, {}, [], 0].forEach((data) => {
formatter.printTestLog(data);
expect(console.log.mock.calls).toHaveLength(0);
});
});
test('with data', () => {
formatter.printTestLog(formatter.collectSuites(testData, '/Users/test'));
expect(console.log.mock.calls).toEqual(consoleOutput);
});
describe("printTestLog", () => {
test("empty tests", () => {
["", null, undefined, {}, [], 0].forEach(data => {
formatter.printTestLog(data);
expect(console.log.mock.calls).toHaveLength(0);
});
});
test('log', () => {
formatter.log('test');
expect(console.log.mock.calls[0][0]).toEqual('test');
});
test("with data", () => {
formatter.printTestLog(formatter.collectSuites(testData, "/Users/test"), "12345");
expect(console.log.mock.calls).toEqual(consoleOutput);
});
});
describe('collectSuites', () => {
test('empty', () => {
expect(formatter.collectSuites()).toEqual({});
expect(formatter.collectSuites(null)).toEqual({});
expect(formatter.collectSuites(undefined)).toEqual({});
expect(formatter.collectSuites('')).toEqual({});
expect(formatter.collectSuites([], '/')).toEqual({});
});
test("log", () => {
formatter.log("test");
expect(console.log.mock.calls[0][0]).toEqual("test");
});
test('with result', () => {
expect(formatter.collectSuites(testData, '/Users/test')).toEqual({
'foo/__tests__/file.js': {
path: expect.objectContaining({
to: expect.objectContaining({
test1: expect.any(Object),
test2: expect.any(Object),
})
}),
},
'foo/__tests__/file2.js': {
path2: expect.objectContaining({
to: expect.objectContaining({
test3: expect.any(Object),
test4: expect.any(Object),
})
})
}
});
});
});
describe("collectSuites", () => {
test("empty", () => {
expect(formatter.collectSuites()).toEqual({});
expect(formatter.collectSuites(null)).toEqual({});
expect(formatter.collectSuites(undefined)).toEqual({});
expect(formatter.collectSuites("")).toEqual({});
expect(formatter.collectSuites([], "/")).toEqual({});
});
test('formatReport', () => {
formatter.formatReport(testData, '/Users/test/');
expect(console.log.mock.calls).toEqual(consoleOutput);
test("with result", () => {
const fileKey = ["foo", "__tests__", "file.js"].join(path.sep);
const file2Key = ["foo", "__tests__", "file2.js"].join(path.sep);
expect(formatter.collectSuites(testData, "/Users/test")).toEqual({
[fileKey]: {
path: expect.objectContaining({
to: expect.objectContaining({
test1: expect.any(Object),
test2: expect.any(Object)
})
})
},
[file2Key]: {
path2: expect.objectContaining({
to: expect.objectContaining({
test3: expect.any(Object),
test4: expect.any(Object)
})
})
}
});
});
});
test("formatReport", () => {
formatter.formatReport(testData, "/Users/test/", "12345");
expect(console.log.mock.calls).toEqual(consoleOutput);
});
});
});

@@ -1,68 +0,70 @@

'use strict';
const consoleOutput = [
["##teamcity[testSuiteStarted name=\'foo/__tests__/file.js\']"],
["##teamcity[testSuiteStarted name=\'path\']"],
["##teamcity[testSuiteStarted name=\'to\']"],
["##teamcity[testSuiteStarted name=\'test1\']"],
["##teamcity[testStarted name=\'title1\']"],
["##teamcity[testFailed name=\'title1\']"],
["##teamcity[testFinished name=\'title1\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test1\']"],
["##teamcity[testSuiteStarted name=\'test2\']"],
["##teamcity[testStarted name=\'title2\']"],
["##teamcity[testIgnored name=\'title2\' message=\'pending\']"],
["##teamcity[testFinished name=\'title2\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test2\']"],
["##teamcity[testSuiteFinished name=\'to\']"],
["##teamcity[testSuiteFinished name=\'path\']"],
["##teamcity[testSuiteFinished name=\'foo/__tests__/file.js\']"],
["##teamcity[testSuiteStarted name=\'foo/__tests__/file2.js\']"],
["##teamcity[testSuiteStarted name=\'path2\']"],
["##teamcity[testSuiteStarted name=\'to\']"],
["##teamcity[testSuiteStarted name=\'test3\']"],
["##teamcity[testStarted name=\'title3\']"],
["##teamcity[testFinished name=\'title3\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test3\']"],
["##teamcity[testSuiteStarted name=\'test4\']"],
["##teamcity[testStarted name=\'title4\']"],
["##teamcity[testFailed name=\'title4\']"],
["##teamcity[testFinished name=\'title4\' duration=\'123\']"],
["##teamcity[testSuiteFinished name=\'test4\']"],
["##teamcity[testSuiteFinished name=\'to\']"],
["##teamcity[testSuiteFinished name=\'path2\']"],
["##teamcity[testSuiteFinished name=\'foo/__tests__/file2.js\']"]
["##teamcity[testSuiteStarted name='foo/__tests__/file.js' flowId='12345']"],
["##teamcity[testSuiteStarted name='path' flowId='12345']"],
["##teamcity[testSuiteStarted name='to' flowId='12345']"],
["##teamcity[testSuiteStarted name='test1' flowId='12345']"],
["##teamcity[testStarted name='title1' flowId='12345']"],
["##teamcity[testFailed name='title1' flowId='12345']"],
["##teamcity[testFinished name='title1' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test1' flowId='12345']"],
["##teamcity[testSuiteStarted name='test2' flowId='12345']"],
["##teamcity[testStarted name='title2' flowId='12345']"],
["##teamcity[testIgnored name='title2' message='pending' flowId='12345']"],
["##teamcity[testFinished name='title2' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test2' flowId='12345']"],
["##teamcity[testSuiteFinished name='to' flowId='12345']"],
["##teamcity[testSuiteFinished name='path' flowId='12345']"],
["##teamcity[testSuiteFinished name='foo/__tests__/file.js' flowId='12345']"],
["##teamcity[testSuiteStarted name='foo/__tests__/file2.js' flowId='12345']"],
["##teamcity[testSuiteStarted name='path2' flowId='12345']"],
["##teamcity[testSuiteStarted name='to' flowId='12345']"],
["##teamcity[testSuiteStarted name='test3' flowId='12345']"],
["##teamcity[testStarted name='title3' flowId='12345']"],
["##teamcity[testFinished name='title3' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test3' flowId='12345']"],
["##teamcity[testSuiteStarted name='test4' flowId='12345']"],
["##teamcity[testStarted name='title4' flowId='12345']"],
["##teamcity[testFailed name='title4' flowId='12345']"],
["##teamcity[testFinished name='title4' duration='123' flowId='12345']"],
["##teamcity[testSuiteFinished name='test4' flowId='12345']"],
["##teamcity[testSuiteFinished name='to' flowId='12345']"],
["##teamcity[testSuiteFinished name='path2' flowId='12345']"],
["##teamcity[testSuiteFinished name='foo/__tests__/file2.js' flowId='12345']"]
];
const testData = require('./data');
const reporter = require('../lib/index');
const testData = require("./data");
const reporter = require("../lib/index");
describe('jest-teamcity', () => {
beforeAll(() => {
console.log = jest.fn().mockImplementation(s => s);
});
describe("jest-teamcity", () => {
beforeAll(() => {
process.env.TEAMCITY_FLOWID = 12345;
console.log = jest.fn().mockImplementation(s => s);
});
beforeEach(() => {
console.log.mockReset();
});
beforeEach(() => {
console.log.mockReset();
});
afterAll(() => {
console.log = consoleFn;
});
afterAll(() => {
console.log = consoleFn;
});
describe('module', () => {
test('enabled (with TEAMCITY_VERSION)', () => {
process.env.TEAMCITY_VERSION = '0.0.0';
const originalCwd = process.cwd();
process.cwd = function () { return '/Users/test'; };
reporter({ testResults: testData });
expect(console.log.mock.calls).toEqual(consoleOutput);
process.cwd = originalCwd;
});
describe("module", () => {
it("enabled (with TEAMCITY_VERSION)", () => {
process.env.TEAMCITY_VERSION = "0.0.0";
test('disabled', () => {
delete process.env.TEAMCITY_VERSION;
const result = reporter({ test: 1 });
expect(result).toEqual({ test: 1 });
});
const originalCwd = process.cwd();
process.cwd = function() {
return "/Users/test";
};
reporter({ testResults: testData });
expect(console.log.mock.calls).toEqual(consoleOutput);
process.cwd = originalCwd;
});
it("disabled", () => {
delete process.env.TEAMCITY_VERSION;
const result = reporter({ test: 1 });
expect(result).toEqual({ test: 1 });
});
});
});
#CHANGELOG
## 1.5.0 - 2019-10-07
### Changed
- Updated dependencies
- Add Prettier
- Add support of TeamCity FlowID
## 1.4.0 - 2019-02-05

@@ -3,0 +9,0 @@ ### Changed

@@ -1,120 +0,130 @@

'use strict';
"use strict";
const _ = require('lodash');
const path = require('path');
const _ = require("lodash");
const path = require("path");
module.exports = {
/**
* Escape text message to be compatible with Teamcity
* @param {string} str
* @returns {string}
*/
escape(str) {
if (!str) {
return '';
}
/**
* Escape text message to be compatible with Teamcity
* @param {string} str
* @returns {string}
*/
escape(str) {
if (!str) {
return "";
}
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, '|\'')
},
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, "|'");
},
/**
* Prints test message
* @param {object} tests
*/
printTestLog(tests) {
if (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)}']`);
switch (test.status) {
case 'failed':
if (test.failureMessages) {
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)}']`);
});
} else {
this.log(`##teamcity[testFailed name='${this.escape(test.title)}']`);
}
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}']`);
});
/**
* Prints test message
* @param {object} tests
*/
printTestLog(tests, flowId) {
if (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)}' flowId='${flowId}']`);
switch (test.status) {
case "failed":
if (test.failureMessages) {
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)}' flowId='${flowId}']`
);
});
} else {
// print suite names
this.log(`##teamcity[testSuiteStarted name='${this.escape(suiteName)}']`);
this.printTestLog(tests[suiteName]);
this.log(`##teamcity[testSuiteFinished name='${this.escape(suiteName)}']`);
this.log(`##teamcity[testFailed name='${this.escape(test.title)}' flowId='${flowId}']`);
}
});
break;
case "pending":
this.log(
`##teamcity[testIgnored name='${this.escape(test.title)}' message='pending' flowId='${flowId}']`
);
break;
case "passed":
break;
}
this.log(
`##teamcity[testFinished name='${this.escape(test.title)}' duration='${
test.duration
}' flowId='${flowId}']`
);
});
} else {
// print suite names
this.log(`##teamcity[testSuiteStarted name='${this.escape(suiteName)}' flowId='${flowId}']`);
this.printTestLog(tests[suiteName], flowId);
this.log(`##teamcity[testSuiteFinished name='${this.escape(suiteName)}' flowId='${flowId}']`);
}
},
});
}
},
/**
* Outputs teamcity service message
* @param {string} text
*/
log(text) {
console.log(text);
},
/**
* Outputs teamcity service message
* @param {string} text
*/
log(text) {
console.log(text);
},
/**
* Collects test suites
* @param {array} testResults
* @returns {object}
*/
collectSuites(testResults, cwd) {
if (!testResults) {
return {};
/**
* Collects test suites
* @param {array} testResults
* @returns {object}
*/
collectSuites(testResults, cwd) {
if (!testResults) {
return {};
}
if (!cwd) {
throw new Error("cwd not specified");
}
const suites = {};
testResults.forEach(testFile => {
const filename = path.relative(cwd, testFile.testFilePath);
testFile.testResults.forEach(test => {
const path = [filename].concat(test.ancestorTitles).concat("_tests_");
if (!_.has(suites, path)) {
_.set(suites, path, []);
}
if (!cwd) {
throw new Error('cwd not specified');
}
const suites = {};
testResults.forEach((testFile) => {
const filename = path.relative(cwd, testFile.testFilePath);
testFile.testResults.forEach((test) => {
const path = [ filename ].concat(test.ancestorTitles).concat('_tests_');
if (!_.has(suites, path )) {
_.set(suites, path, []);
}
const testsList = _.get(suites, path);
testsList.push(test);
const testsList = _.get(suites, path);
testsList.push(test);
_.set(suites, path, testsList);
});
});
_.set(suites, path, testsList);
});
});
return suites;
},
return suites;
},
/**
* Formats and outputs tests results
* @param {array} testResults
*/
formatReport(testResults, cwd) {
const suites = this.collectSuites(testResults, cwd);
this.printTestLog(suites);
}
/**
* Formats and outputs tests results
* @param {array} testResults
*/
formatReport(testResults, cwd, flowId) {
const suites = this.collectSuites(testResults, cwd);
this.printTestLog(suites, flowId);
}
};

@@ -5,12 +5,13 @@ /**

'use strict';
const formatter = require("./formatter");
const formatter = require('./formatter');
module.exports = result => {
const flowId = process.env.TEAMCITY_FLOWID || process.pid.toString();
const teamCityVersion = process.env.TEAMCITY_VERSION;
module.exports = (result) => {
if (process.env.TEAMCITY_VERSION) {
formatter.formatReport(result.testResults, process.cwd());
}
if (teamCityVersion) {
formatter.formatReport(result.testResults, process.cwd(), flowId);
}
return result;
return result;
};
{
"name": "jest-teamcity",
"version": "1.4.0",
"version": "1.5.0",
"description": "Teamcity Reporter for Jest Testing framework",

@@ -8,7 +8,7 @@ "homepage": "https://github.com/itereshchenkov/jest-teamcity",

"dependencies": {
"lodash": "^4.17.11"
"lodash": "^4.17.15"
},
"devDependencies": {
"eslint": "^5.13.0",
"jest": "^24.1.0"
"jest": "^24.9.0",
"prettier": "^1.18.2"
},

@@ -15,0 +15,0 @@ "scripts": {

@@ -25,3 +25,3 @@ # jest-teamcity

The reported is enabled only if `TEAMCITY_VERSION` variable is set. It should work in TeamCity be default.
The reporter is enabled only if `TEAMCITY_VERSION` variable is set. It should work in TeamCity by default.

@@ -28,0 +28,0 @@ To be able to run the tests with the reporter locally, environment variable should be set:

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc